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
fellshard 2018-12-20T00:00:10.806300Z

Trying to brute-force the second part?

Average-user 2018-12-20T04:05:17.807300Z

Very similar to day 23 of 2017

2018-12-20T05:04:15.807700Z

Day 20… Where to begin…

gklijs 2018-12-20T05:59:57.807800Z

At room 0,0 with 4 optional doors?

😄 1
gklijs 2018-12-20T06:02:13.808Z

If you print each step you can see a certain pattern. It could take very long for part 2 to complete if you don't change the program.

☝️ 1
fellshard 2018-12-20T07:10:03.808700Z

Quite enjoyed this one. Had to backtrack a bit once I realized I was parsing into a difficult-to-wrangle format.

2018-12-20T07:23:03.808900Z

That’s it!

2018-12-20T07:28:24.810500Z

Again, my solution is really slow… It seems to be making progress, but…

2018-12-20T08:17:26.812100Z

I couldn’t sleep until I figured this out, despite being too tired to actually think. Whenever I alternate, push [pos, pattern] for each alternation onto the search stack, which can cause a lot of duplicate work to be done. Adding in the cache check reversed the duplication, which really shouldn’t have been there. That probably makes no sense to anyone but me, but I at least I can let myself sleep 🙂

🙂 1
misha 2018-12-20T08:57:03.813900Z

memoize + store set of visited rooms in each path:

"Elapsed time: 1402.048955 msecs"
"Elapsed time: 1255.330936 msecs"

misha 2018-12-20T08:58:26.814100Z

good thing, it is a "tree", not a graph

fellshard 2018-12-20T10:07:28.815600Z

Interesting, I didn't even check to see if any of the paths ever looped back on themselves

2018-12-20T15:23:42.817500Z

I don’t think tracking the visited rooms is sufficient - you have to know you haven’t been to the same room with the same remaining pattern to search

fellshard 2018-12-20T19:43:14.820100Z

I'd recommend breaking the solution up into multiple stages.

2018-12-20T07:57:28.810600Z

Hmm. I had to cache/memoize a bit. That sped it up a lott, but It doesn’t feel like I should have needed to do that. Maybe it’ll be more obvious in the morning.

2018-12-20T09:03:50.814900Z

Argh! All examples of part one work with my solution but of course the big one doesn’t 🙈

misha 2018-12-20T09:07:39.815500Z

had a different issue, massively misunderstood p2, and wasted like extra hour on it

2018-12-20T13:06:27.816700Z

Ah. I think I know what I did

Average-user 2018-12-20T18:39:37.818600Z

(time (part-1))
"Elapsed time: 39457.156774 msecs"
3314

misha 2018-12-20T19:08:00.819Z

memoize it, @lucaspolymeris

Average-user 2018-12-20T19:24:28.819700Z

Don't know what memoize could workhttps://paste.ofcode.org/iKWt9afh7cWZg5UtPWhXRq

Average-user 2018-12-20T19:28:18.819900Z

If you analyze the code, the only function that takes real time is nodes-depth

misha 2018-12-20T19:44:50.820300Z

(filter (complement seen) (remove seen)

misha 2018-12-20T19:45:46.820500Z

move might be used many times with same args

Average-user 2018-12-20T19:46:39.820800Z

I always forget remove, but will just change readability, not performance I think. But thanks anyways

Average-user 2018-12-20T19:47:10.821Z

move?

misha 2018-12-20T19:47:22.821200Z

(defn move [dir [x y]]

misha 2018-12-20T19:48:03.821500Z

if you have shared seen - make it transient

Average-user 2018-12-20T19:48:12.821700Z

ahh right. But the only function that uses move is build-graph. Which takes:

(time (count (build-graph (clean-input))))
"Elapsed time: 77.78829 msecs"
10000

misha 2018-12-20T19:49:12.821900Z

I tracked seen per branch, so could not make it transient, but my move repetitive usage is noticable

misha 2018-12-20T19:56:04.822100Z

(reduce conj seen front)
                 (reduce conj ds (map (constantly depth) front))
into might speed these 2 up, since it does transient under the hood, if possible.

Average-user 2018-12-20T19:58:17.822300Z

I might try to update neighbors, since I will never use one key more than once

misha 2018-12-20T20:01:00.822500Z

so you are doing exhaustive search, and then - select?

Average-user 2018-12-20T20:06:20.822700Z

not sure what you mean. nodes-length returns the minimum distance between the root and every other node

Average-user 2018-12-20T20:07:07.822900Z

into doesn't change much btw

misha 2018-12-20T20:08:59.823100Z

but you assign those distances to every known room first

Average-user 2018-12-20T20:46:32.823800Z

well here is my day 20, is not that efficient but it is concise, I think https://github.com/Average-user/adventofcode-clj-2018/blob/master/src/adventofcode_clj_2018/day20.clj

baritonehands 2018-12-20T21:06:34.824500Z

I like how it came using some string manipulation and the reader:

(defn parse-input [input]
  (-> input
      (str/replace #"[\^]" "[")
      (str/replace #"[\$]" "]")
      (str/replace "|" " | ")
      (read-string)))
[ENWWW (NEEE | SSE (EE | N))]

baritonehands 2018-12-20T21:06:45.824800Z

still working on actually processing that for the solution though

baritonehands 2018-12-20T21:08:52.825200Z

oops, left the regexes even though I no longer need them

2018-12-20T23:49:22.825600Z

@lucaspolymeris I don’t think yours works. Try “^N(E|)N(E|)N$”

2018-12-20T23:50:34.825800Z

or even “^N(E|)N”