This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-20
Channels
- # adventofcode (47)
- # announcements (3)
- # aws (29)
- # bangalore-clj (3)
- # beginners (63)
- # boot (2)
- # braveandtrue (40)
- # calva (34)
- # cider (37)
- # cljs-dev (8)
- # clojars (3)
- # clojure (45)
- # clojure-europe (2)
- # clojure-france (4)
- # clojure-india (2)
- # clojure-italy (44)
- # clojure-japan (4)
- # clojure-nl (39)
- # clojure-serbia (1)
- # clojure-spec (21)
- # clojure-uk (75)
- # clojurescript (28)
- # cursive (24)
- # data-science (3)
- # datomic (31)
- # emacs (13)
- # fulcro (35)
- # hoplon (21)
- # jobs-discuss (66)
- # nrepl (18)
- # off-topic (72)
- # pathom (35)
- # re-frame (20)
- # reagent (54)
- # shadow-cljs (35)
- # spacemacs (9)
- # specter (8)
- # sql (13)
- # testing (9)
- # tools-deps (21)
- # vim (3)
Very similar to day 23 of 2017
Quite enjoyed this one. Had to backtrack a bit once I realized I was parsing into a difficult-to-wrangle format.
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.
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 🙂
memoize + store set of visited rooms in each path:
"Elapsed time: 1402.048955 msecs"
"Elapsed time: 1255.330936 msecs"
Interesting, I didn't even check to see if any of the paths ever looped back on themselves
every branch in examples is either terminates ))))$
, or loops to the previous point (NEWS|)...
after doing a circle
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
Argh! All examples of part one work with my solution but of course the big one doesn’t 🙈
Ah. I think I know what I did
every branch in examples is either terminates ))))$
, or loops to the previous point (NEWS|)...
after doing a circle
(time (part-1))
"Elapsed time: 39457.156774 msecs"
3314
memoize it, @lucaspolymeris
Don't know what memoize could workhttps://paste.ofcode.org/iKWt9afh7cWZg5UtPWhXRq
If you analyze the code, the only function that takes real time is nodes-depth
I always forget remove
, but will just change readability, not performance I think. But thanks anyways
move
?
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
I tracked seen
per branch, so could not make it transient, but my move
repetitive usage is noticable
(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.I might try to update neighbors
, since I will never use one key more than once
not sure what you mean. nodes-length
returns the minimum distance between the root and every other node
into
doesn't change much btw
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
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))]
still working on actually processing that for the solution though
oops, left the regexes even though I no longer need them
@lucaspolymeris I don’t think yours works. Try “^N(E|)N(E|)N$”
Im only with my phone now, I'll try it later. But there might be some off by ones errors in small inputs
No - it’s actually not your code, it’s that the stack based approach doesn’t work except for on the sample input
Is not stack based
I think is just a coincidence of names
It worked with my input (not sample)