Fork me on GitHub
#adventofcode
<
2019-12-02
>
tbrooke02:12:31

@potetm Are you doing your videos this year?

potetm02:12:08

If I do, it’ll have to be after the advent season 😕

potetm02:12:15

too busy at the moment

pepas03:12:26

hey folks, I’m very new to clojure. decided to go through the advent of code stuff to get some practice! here’s day 1: https://gist.github.com/cellularmitosis/269d593919a7337219f8df7c5a5df648

mpcjanssen04:12:53

@jasonpepas you might want to use quot instead of Math/floor. I had the same, but quot is easier.

👍 4
😎 4
Jett Durham06:12:54

I suppose I ought to share my repo, given my current slot in the leaderboard 😅 https://github.com/thejettdurham/advent-of-code-2019-clj I’m a Senior Frontend Engineer working in React(+Native) by day, and wannabe Clojurist by night. I don’t have formal CS training, so Advent of Code gives me the opportunity to help fill in those gaps in the fundamentals. 😁

fingertoe07:12:05

@mpcjanssen @jasonpepas I used int instead of quot or Math/floor without any problem.. Seemed to coerce a ratio to it’s next lowest integer.

mpcjanssen07:12:54

What I like about the iterate based solutions is that they clearly separate the step function between states and the terminating condition. This is great for debugging.

👌 4
fellshard08:12:40

Trying to focus a bit differently this year. I'm solving for speed first, then focusing on visualizing the problem/solution. This has a side-effect of encouraging me to find CLJC solutions for rapid porting to the Quil sketch host. http://www.quil.info/sketches/show/0622589e4acd61f73d86eff09064deff308553905d58dfc10448cf244ce9fa24 http://www.quil.info/sketches/show/d804ff390bc3f0bf59ba151699b5930e82158efc95765b5c81f188eec0e648a3

👍 12
pesterhazy09:12:44

I have a feeling that Intcode will stay with us for a while

karlis10:12:52

my solutions for the day: https://github.com/skazhy/advent/blob/master/src/advent/2019/day2.clj second one took two coffees to figure out without bruteforcing 😄

❤️ 4
dmarjenburgh11:12:54

Can you explain? Why is the output linear in the noun variable?

karlis12:12:56

after some testing I noticed that if I change is constant if I bump the "noun" variable

fingertoe10:12:57

My solution: https://github.com/jreighley/aoc2019/blob/master/src/aoc/aoc2.clj I suspect my handling of the 99 op code passed my tests but needs some further thought Not used to the mutation risk..

dpsutton13:12:12

is there a mistake in day2 examples? 1,1,1,4,99,5,6,0,99 becomes 30,1,1,4,2,5,6,0,99 it highlights the 30 and the 2 as new values. but there can only be one single instruction run because position 5--the second opcode-- is a 99 and the machine halts?

fingertoe22:12:40

It’s sorta Greek to us Clojurists, but mutability causes that 99 to be replaced by a 2.

fingertoe23:12:03

I am pretty sure by code didn’t think that through either.

rutledgepaulv14:12:50

the first step is to replace 99 with 2. add registers 1 and register 2 and put into register 4 (5th position)

dpsutton14:12:38

thanks. i did a partition-by 4 rather than allowing for dynamic instructions. part 1 still worked 🙂

misha14:12:31

I assoced to (state res-idx) rather than to res-idx and part 1 worked too. I wonder if that was a deliberate trap or unintentional.

misha16:12:59

(def enum-pairs
  (letfn [(pairs [i] (map (fn [j] [j (- i j)]) (range (inc i))))]
    (mapcat pairs (range))))
wtf opieop

genmeblog20:12:27

Looks like (quite not optimal) list comprehension. I would use for here. Especially when we know that > Each of the two input values will be between 0 and 99, inclusive.

misha06:12:39

it is lazy infinite positive quarter of a xy plane. Sweet, but yeah, ranges are known, so for is more readable and sufficient here

Average-user06:12:03

I wasn't sure if those values where necessarily bounded. But yeah.

Alex Jackson21:12:03

Hi all, I'm using aoc to learn me some clojure this year. here's my solution for day 2: https://github.com/jacksonal/advent-of-code-2019/blob/master/src/advent_of_code_2019/day2.clj any comments or criticisms welcome. I've never written a line of clojure outside of messing around in the REPL a little bit. I especially struggled with figuring out how to best use (for) although it sounds like there is a non-brute force solution.

genmeblog21:12:55

Hi Alex. Some use of language comments. 1. def should go outside your defn. Use let inside your functions. 2. for can be combined into one. This way you can avoid flatten 3. (nth seq 0) equals first 4. I think in this task subvec is not necessary. 5. Instead of vector use just [] 6. (into (vector) map ...) can be substituted with mapv

👍 4
genmeblog21:12:56

7. (not (nil? x)) can be substituted with (seq x)

Alex Jackson21:12:42

ah cool these language comments are great. thank you

fingertoe21:12:10

Nice looking code. The only serious “Beginner” hallmark that I see is the user of the def inside of the int-compute function. It’s pretty rare to see a def within a defn — usually we use let bindings in that spot. I think most folks would use the def on it’s own to slurp the input data, then pass that as an arg to the int-compute.

tschady21:12:35

:let and :when in the for loop can help clear it up

👍 8
tschady21:12:20

(defn part-2 [input]
  (let [magic-output 19690720]
    (first (for [noun  (range 100)
                 verb  (range 100)
                 :let  [tape (run-tape input noun verb)]
                 :when (= magic-output (first tape))]
             (+ verb (* 100 noun))))))

genmeblog21:12:44

Also, since a lot of code is already around, take a look at it.

genmeblog21:12:13

8. One more advice (nth vector k) can be replaced by (vector k) eg. ([0 1 2 3 4] 3)

👍 4
val_waeselynck21:12:34

Also consider using destructuring on op-seq, and case rather than (if (== ...)). = should usually be favoured over ==.

val_waeselynck21:12:47

https://clojurians.slack.com/archives/C0GLTDB2T/p1575321553081900?thread_ts=1575320523.080100&amp;cid=C0GLTDB2T Some consider this bad practice though. It's clever, but may be overly general, obscuring the type of vector and increasing the risk of breakage.

genmeblog21:12:16

Yes, yes, in general you're right. But in this case, when code is short and vector type is used consciously it can be helpful.

💯 4
genmeblog22:12:46

Anyway. In contests like this plenty of performance tricks will be used to make algorithms efficient enough. Some of such ticks can be considered bad style.

misha06:12:21

(get [] 1)
=> nil
(nth [] 1)
Execution error (IndexOutOfBoundsException) 
([] 1)
Execution error (IndexOutOfBoundsException)