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
borkdude 2017-12-24T09:41:11.000024Z

my code for today: https://github.com/borkdude/aoc2017/blob/master/src/day24.clj

ihabunek 2017-12-24T11:55:37.000039Z

@fellshard i think everyone had the off-by-one problem in this one, i had two 😄

borkdude 2017-12-24T12:25:55.000056Z

wonder if I could use tree-seq

ihabunek 2017-12-24T14:50:52.000047Z

i wonder if i could use a zipper 🙂

bhauman 2017-12-24T15:30:12.000014Z

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

ihabunek 2017-12-24T15:44:27.000021Z

hah, TIL: http://clojuredocs.org/clojure.set/index

ihabunek 2017-12-24T15:45:07.000015Z

i could have used that knowledge earlier today

mfikes 2017-12-24T15:45:23.000038Z

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

ihabunek 2017-12-24T15:47:09.000016Z

@mfikes nice concise solution

mfikes 2017-12-24T15:48:41.000072Z

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

borkdude 2017-12-24T15:58:43.000045Z

@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

borkdude 2017-12-24T16:01:23.000071Z

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

mfikes 2017-12-24T16:01:42.000007Z

Part 2 is around 12 seconds

borkdude 2017-12-24T16:02:20.000051Z

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

borkdude 2017-12-24T16:02:57.000001Z

Part 2 is almost identical to part 1 in my code

borkdude 2017-12-24T16:55:27.000044Z

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

borkdude 2017-12-24T16:59:27.000011Z

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.

borkdude 2017-12-24T18:49:37.000048Z

With index, 1.7s for part 2 now https://github.com/borkdude/aoc2017/blob/master/src/day24.clj#L152

borkdude 2017-12-24T20:06:16.000036Z

Very clean solution in SQL: https://github.com/xocolatl/advent-of-code/blob/master/Day24/script.sql

bhauman 2017-12-24T22:23:58.000006Z

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

bhauman 2017-12-24T22:36:45.000003Z

I just cleaned it up a bit more

borkdude 2017-12-24T22:37:11.000005Z

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 🙂

bhauman 2017-12-24T22:37:59.000020Z

yeah its really a tree of states

borkdude 2017-12-24T22:38:12.000058Z

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

bhauman 2017-12-24T22:38:34.000033Z

yeah no intermediate structures

borkdude 2017-12-24T22:38:35.000027Z

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

bhauman 2017-12-24T22:39:00.000031Z

hmmmm I does tree-seq return a reducable?

bhauman 2017-12-24T22:39:08.000071Z

no its a lazy-seq for sure

bhauman 2017-12-24T22:40:23.000044Z

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

borkdude 2017-12-24T22:40:34.000041Z

off to bed… tomorrow the last day of AOC…

bhauman 2017-12-24T22:40:44.000031Z

have a good one!