Fork me on GitHub
#adventofcode
<
2019-12-01
>
dmarjenburgh20:12:46

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

mpcjanssen11:12:42

Although (iterate) seems perfect for this puzzle.

nam.hyunwoo11:12:51

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
snorremd14:12:05

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

Chase14:12:14

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!

Chase15:12:41

now we shall see how quickly the difficulty ramps up

meow18:12:22

(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 +)))

dpsutton18:12:32

@slack1899 what language is that?

kenj18:12:57

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…

kenj18:12:26

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

dpsutton18:12:43

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

kenj18:12:10

ahhh, that makes a lot of sense

kenj18:12:16

thank you!

dpsutton18:12:30

Probably catches everyone at some point

meow19:12:24

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

meow19:12:39

I only use Racket for practicing algorithms and puzzles and toys

πŸ‘ 1
kenj19:12:08

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

kenj19:12:14

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

kenj19:12:38

is there any real advantage to using transduce over reduce?

potetm23:12:55

speed & memory

potetm23:12:23

fewer allocations for intermediate structures

potetm23:12:03

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

gbouvier23:12:53

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?

potetm00:12:44

way too little info to comment

potetm00:12:01

post a gist w/ the 2 versions + the method used to time?