adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
pesterhazy 2019-12-01T10:19:11.025300Z

First puzzle: https://github.com/pesterhazy/advent2019

mpcjanssen 2019-12-01T11:04:52.026500Z

My entry: https://github.com/mpcjanssen/aoc2019

πŸ‘ 2
mpcjanssen 2019-12-01T11:12:42.028400Z

Although (iterate) seems perfect for this puzzle.

uneman 2019-12-01T11:16:51.029100Z

I've tried to induce recursion formula to get the sum of the sequence, but it was slower than I expected because it requires factorizations. πŸ˜“ https://github.com/namenu/advent-of-code/blob/master/src/year2019/day01.clj

πŸ‘ 1
πŸ™‚ 1
snorremd 2019-12-01T14:10:05.031Z

Started with a transducer + recursive function solution for the second task. But after seeing the iterator based one I switched out the recursive function. https://github.com/snorremd/adventofcode2019/blob/master/src/day1.clj

Chase 2019-12-01T14:57:14.032500Z

oh man, I was able to complete both parts in about 20 minutes today! Might not sound like much but this time last year, that would have been a tough ask. Thank you Clojure slack for all the help! That was so satisfying inputting correct answers on the first try. This is fun!

Chase 2019-12-01T15:11:41.032900Z

now we shall see how quickly the difficulty ramps up

meow 2019-12-01T18:43:22.034400Z

(def FILE "../data/1.txt")
(def data (~>> FILE file->lines (map string->number)))

;; ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
;; Solve

(fn (step n) (~> n (quotient _ 3) (- 2)))
(fn (score n) (apply + (unfold negative? identity step (step n))))
(def A (~>> data (map step) (apply +)))
(def B (~>> data (map score) (apply +)))

dpsutton 2019-12-01T18:49:32.035300Z

@slack1899 what language is that?

kenj 2019-12-01T18:51:57.036700Z

TIL you can’t just shove #(/ % 3) into a -> threading macro, even though you can normally shove functions that take a single arg. No idea why…

kenj 2019-12-01T18:54:26.038300Z

at this point I realize #(/ % 3) was unnecessary for a ->, but still 🀷

dpsutton 2019-12-01T18:54:43.038800Z

Because that’s expanded at read time to (fn [temp] ...) so it gets threaded as (fn thread-value [temp] ...)

kenj 2019-12-01T18:56:10.039400Z

ahhh, that makes a lot of sense

kenj 2019-12-01T18:56:16.039600Z

thank you!

dpsutton 2019-12-01T18:56:30.040Z

Probably catches everyone at some point

meow 2019-12-01T19:04:24.040600Z

@dpsutton this is Racket but I couldn't help but snoop around the other Lisp channels I'm a part of

meow 2019-12-01T19:04:39.041Z

I only use Racket for practicing algorithms and puzzles and toys

πŸ‘ 1
erwinrooijakkers 2019-12-01T19:08:28.042600Z

Mine πŸ™‚ https://github.com/transducer/adventofcode/blob/master/src/adventofcode/2019/day1.clj

πŸ˜† 2
erwinrooijakkers 2019-12-01T19:10:15.043100Z

Ah iterate

kenj 2019-12-01T19:14:08.044700Z

what’s annoying is that since the mass->fuel calc is lossy, you get different results if you calculate on the fuel requirements for the sum of all mass, as opposed to calculating the fuel requirements for each module of mass and summing the fuel results

kenj 2019-12-01T19:36:52.045100Z

kenj 2019-12-01T19:37:14.045700Z

I always realize how much I stink at Clojure after reading other people’s code πŸ™‚

kenj 2019-12-01T19:37:38.046200Z

is there any real advantage to using transduce over reduce?

2019-12-01T20:38:46.046700Z

I didn’t know you could use Clojure in a Jupyter notebook. Nice

2019-12-01T23:28:55.047600Z

speed & memory

2019-12-01T23:29:23.047800Z

fewer allocations for intermediate structures

2019-12-01T23:30:03.048Z

but unless you’re wanting to learn to use transducers, it doesn’t matter for this problem

gbouvier 2019-12-01T23:42:53.048400Z

My transducer version took 3 times as long to run as my reduce version. Maybe with more data or fns in the transducer compose it would swing the other way?