my code for today: https://github.com/borkdude/aoc2017/blob/master/src/day24.clj
wonder if I could use tree-seq
i wonder if i could use a zipper 🙂
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day24.clj
you could use a tree-seq
if you include the current state with each child-node
https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_24.cljc
hah, TIL: http://clojuredocs.org/clojure.set/index
i could have used that knowledge earlier today
Yeah, that's a rare gem. I happened to use it in day 7 https://github.com/mfikes/advent-of-code/blob/202768383a22d6cb0d37ef7b73dab32b21cb8085/src/advent_2017/day_07.cljc#L27
@mfikes nice concise solution
It seems that some amount of golfing makes code easier to comprehend, but if you push it too far, you lose the balance.
@bhauman, yeah, that way I would only have to build the tree on not visit each node afterwards but only apply tree-seq on it
@mfikes interesting looking and concise solution. is it fast?
Part 2 is around 12 seconds
Didn’t think about concision, although I might try the tree-seq approach.
(time (part-1)) ;; 1859, ~5.8s
(time (part-2)) ;; 1799, ~6.4s
Part 2 is almost identical to part 1 in my code
Little speedup by not even building a tree anymore: https://github.com/borkdude/aoc2017/blob/master/src/day24.clj#L90
(time (part-1)) ;; 1859, ~5.8s
(time (part-1')) ;; 1859 ~4.8ms
(time (part-2)) ;; 1799, ~6.4s
(time (part-2')) ;; 1799, ~5.0s
This may be how @bhauman does it too? https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day24.clj#L37 Might try his index too.
With index, 1.7s for part 2 now https://github.com/borkdude/aoc2017/blob/master/src/day24.clj#L152
Very clean solution in SQL: https://github.com/xocolatl/advent-of-code/blob/master/Day24/script.sql
Added a tree-seq
example at the end. I prefer it as a solution.
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day24.clj
I just cleaned it up a bit more
it’s a very cool way of using tree-seq again, unexpected because the root you’re passing doesn’t look like a tree, but as long children and branch? return something useful it just keeps going 🙂
yeah its really a tree of states
Not building a tree, but only return the answers is still faster though + the index really speeds it up significantly
yeah no intermediate structures
Not that that is important, but it’s nice to play around with these trade offs
hmmmm I does tree-seq return a reducable?
no its a lazy-seq for sure
that would be a nice project to make tree-seq implement the reduce protocols
off to bed… tomorrow the last day of AOC…
have a good one!