Fork me on GitHub
#adventofcode
<
2017-12-24
>
borkdude12:12:55

wonder if I could use tree-seq

ihabunek14:12:52

i wonder if i could use a zipper 🙂

bhauman15:12:12

you could use a tree-seq if you include the current state with each child-node

ihabunek15:12:07

i could have used that knowledge earlier today

ihabunek15:12:09

@mfikes nice concise solution

mfikes15:12:41

It seems that some amount of golfing makes code easier to comprehend, but if you push it too far, you lose the balance.

borkdude15:12:43

@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

borkdude16:12:23

@mfikes interesting looking and concise solution. is it fast?

mfikes16:12:42

Part 2 is around 12 seconds

borkdude16:12:20

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

borkdude16:12:57

Part 2 is almost identical to part 1 in my code

borkdude16:12:27

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

bhauman22:12:58

Added a tree-seq example at the end. I prefer it as a solution.

bhauman22:12:45

I just cleaned it up a bit more

borkdude22:12:11

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 🙂

bhauman22:12:59

yeah its really a tree of states

borkdude22:12:12

Not building a tree, but only return the answers is still faster though + the index really speeds it up significantly

bhauman22:12:34

yeah no intermediate structures

borkdude22:12:35

Not that that is important, but it’s nice to play around with these trade offs

bhauman22:12:00

hmmmm I does tree-seq return a reducable?

bhauman22:12:08

no its a lazy-seq for sure

bhauman22:12:23

that would be a nice project to make tree-seq implement the reduce protocols

borkdude22:12:34

off to bed… tomorrow the last day of AOC…

bhauman22:12:44

have a good one!