Nice.. I went from 10ms to 3ms using (and working around) a transient set in the hot loop
I wonder if there’s a nice O(n) solution to part2
I suspect there is. I think I need to sleep before I finish part 2 😕
yeah there's a better way to do this I think.. it's taking a loooong time otherwise
ooh, came up with a relatively quick answer using not-any?
and some
I bet there's a way you can just generate the answer using LCD's
I was thinking the same thing, except I'm not sure that gets you the right answer still
It could certainly help you find one point in time at which all the scanners would be at zero at the time your packet arrives, but I'm not sure that would be useful information, nor would it be guaranteed to be the minimum possible result
https://github.com/minikomi/advent-of-code/blob/master/src/advent/2017/day13.clj#L39-L48 here's mine anyway!
OK, this is the first time in AoC 2017 that my fans are spin-spin-spinning and I get no response from second part.
Time to do the simplest optimizations.
I’m sure there’s an algebraic way to solve this with no code whatsoever…
Using cycle
was probably not a good idea 🙂
“Elapsed time: 536598.496201 msecs”
Execution time mean : 1.755792 sec
I dropped it to 8500msec and I need to get to real work 🙂
You can see all my progress in the same file: https://github.com/orestis/adventofcode/blob/master/clojure/aoc/src/aoc/2017_day13.clj
…but I do have to look at @minikomi’s code first 🙂
@minikomi I think we arrived at the same logic but your version is a bit more “unrolled” than mine.
yeah, not-any?
was the key thing i did to speed it up
As soon as there's a zero-case. you can go onto the next one.
What’s your answer? Mine is close to 4 million…
I think that some
should be equivalent in terms of performance with not-any?
though.
It Should be: https://github.com/clojure/clojure/blob/clojure-1.9.0-alpha14/src/clj/clojure/core.clj#L2682
Nice 🙂
3875838
Day 13: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_13.cljc
I wonder if there is an efficient solution to part 2 using some variation of the Chinese remainder theorem.
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day13.clj
6673ms for part 2
@mfikes very nice solution for day13!
Thanks! It luckily seems to perform well (around 800 ms for my data)
@mfikes yeah you really don't have any intermediate data structures
except for the last call to some
Interesting. I didn't even think about that aspect. I just wrote it for readability / concision.
our solutions are similar, you moved the logic a step deeper which eliminated the need to pass data around
oh and I'm wasting cycles iterating through the count of the structure
\mutters read the instructions. read the instructions. read the instructions
Don’t get caught ignoring the instructions.
Well played, sir. Well played.
Well, down from 21 seconds to 900ms for part 2. Now to see what solutions you guys came up with.
@mfikes is there a way you're preventing the github banner thing from displaying when you paste a link? That's really nice and tidy.
Wow, that's a nice, concise solution.
Where does some-fn
come from?
Oh dear, it’s a core function…
I got thrown by the home-fn
naming 🙂
ok, finally done…
https://github.com/borkdude/aoc2017/blob/master/src/day13.clj
2s for part 2
@grzm After pasting a link, you’ll see a little delete button next to the GitHub banner.
@mfikes cheers.
@borkdude did your util/find-first
function miss the commit?
(I didn’t see it in there either FWIW.)
I like reading what others find useful to abstract away.
@mfikes Sorry, fixed. See comment at the bottom why I used it.
No idea why some
was slower for me than that custom function
(defn find-first
[pred vals]
(reduce
(fn [_ v]
(when (pred v)
(reduced v)))
nil
vals))
(time (some identity (repeat 10000000 nil))) ;; 250 ms
(time (find-first identity (repeat 10000000 nil))) ;; 40 ms
wow
(time (some #(when (> ^long % 10000000) %) (range))) ;; 558 ms
(time (find-first #(> ^long % 10000000) (range))) ;; 95 ms
calls seq on every iteration
calls (when (seq coll))
on every iteration to detect the end of the sequence
I guess one more reason reduce is faster because many collections know how to reduce themselves
but would there be a reason not to rewrite some using reduce so it’s faster?
Hello! Im using Advent of Code as a way of learning Clojure and have just created a repo of what I have so far. Thought id post it incase anyone was interested 😃 https://github.com/sandemchad/clj-advent-of-code-2017
@chad Feel free to add yours to this one too: https://github.com/adventofcode-clojurians/adventofcode-clojurians
@mfikes holy crap, I just saw yours and it’s so concise
@borkdude I changed my some
implementation to reduce and nothing changed
@chad Nice solutions, especially given you are learning
@bhauman what if you execute above snippet? same timing?
@borkdude Honestly, I think I just got lucky. I wrote what seemed straightforward, and by luck of the dice, it was short and fast. Doesn’t happen all the time. 🙂
@borkdude I get similar results and it makes sense now that I look at your example
more closely
Awesome will do 🙂
Thank you 🙂 I am really enjoying using Clojure solving these problems have been a really good way of learning.
https://github.com/krisajenkins/AdventOfCode/blob/master/src/Year2017/Day13.purs#L43