This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-01
Channels
- # adventofcode (30)
- # announcements (51)
- # aws (27)
- # babashka (1)
- # beginners (16)
- # calva (6)
- # cider (10)
- # clj-kondo (2)
- # clojure (94)
- # clojure-dev (27)
- # clojure-italy (1)
- # clojure-taiwan (1)
- # clojure-uk (5)
- # clojurescript (18)
- # clojutre (2)
- # cursive (14)
- # data-science (8)
- # emacs (2)
- # joker (5)
- # off-topic (3)
- # shadow-cljs (31)
- # sql (2)
- # vim (2)
- # yada (11)
I didnβt know you could use Clojure in a Jupyter notebook. Nice
Although (iterate)
seems perfect for this puzzle.
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
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
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!
(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 +)))
@slack1899 what language is that?
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β¦
Because thatβs expanded at read time to (fn [temp] ...) so it gets threaded as (fn thread-value [temp] ...)
@dpsutton this is Racket but I couldn't help but snoop around the other Lisp channels I'm a part of
Mine π https://github.com/transducer/adventofcode/blob/master/src/adventofcode/2019/day1.clj
Ah iterate
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
but unless youβre wanting to learn to use transducers, it doesnβt matter for this problem