Yikes, half way through day 3 and I'm sure I'll find a simpler intuitive solution in the other ones.
https://github.com/deepee0086-clj/adventofcode-clojurians/blob/master/src/day_03.clj
Hmm. My soln. for today's part two matches the example inputs, but not my own.
Ooooh. Bad hex formatting, I think.
:picard-facepalm:
I'm glad my solution worked, because I don't know how I would have debugged that.
It's... definitely a 'walk through by hand' deal. Best I could do was run through their small example step-by-step.
That pretty much describes my code. Amazingly enough, I had the algorithms right the first time. Spent a good deal of time wondering what was wrong before I realized I was using the wrong hash length.
Now trying to port it to cljs
Pushed. Now to sleep!
Moar yak shaving for the 'twist' logic, I feel a lot better about it now. Found the right abstraction for the job.
Today was fun! I managed to reuse my functions from part 1 without having to rewrite them at all. https://github.com/orestis/adventofcode/blob/master/clojure/aoc/src/aoc/2017_day10.clj
@fellshard Nice solution! I like your twist
logic; I went with a transient vector instead.
https://github.com/borkdude/aoc2017/blob/master/src/day10.clj
1.3 ms for part 1, 224ms for part 2
here’s mine
3.9ms / 224,8ms
@orestis nice mix of code, tests, and description
Thanks @grzm — I picked it up somewhere. These days I don’t even read the puzzle on the browser any more, I just copy paste directly in the editor. I love how cider enables me to write tiny functions one by one.
I’m sure there is a way of doing this better, literate programming? Perhaps some kind of jupyter notebook?
I'm much more pragmatic about it: you've got a solution that works really well.
I would like to look into devcards to make the whole thing interactive and shareable.
Looks like there's a smaller set of inputs for Day 10. @borkdude and I have the same one.
AFAIK, there’s only 10-20 inputs per puzzle, as the have to all be validated beforehand.
makes sense
AFAIK, there’s only 10-20 inputs per puzzle, as they have to all be validated beforehand.
@orestis devcards isn’t that more for showing UI components? you could also try klipse, so anyone could play with it in the browser
@borkdude: how does yours work with using "%x" for formatting? I needed to use "%02x"
I've run yours locally and confirmed it works.
Ah, yes, I haven’t used either so got them mixed up.
@grzm don’t know, haven’t thought about it deeply
Okay: the test examples they give require "%02x"
as some of the xor'd values are less than 16. That's not the case for the actual input.
thanks, I’ll enhance
60ms on part 2 🙂
but it wasn't easy
found some weird things: like apply
is faster than arg destructuring
in my first version, part 2 never finished as I got tired of waiting after 5 minutes
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day10.clj
@orestis our answers are so similar 🙂
@orestis I found a big optimization if you mod the drop pos here: https://github.com/orestis/adventofcode/blob/master/clojure/aoc/src/aoc/2017_day10.clj#L44
Is (let [[head & tail] s])
the idiomatic way to do (let [head (first s) tail (rest s)])
when you know you deal with vectors?
I wouldn't say so
@bhauman You mean by skipping the cycle
?
you keep the cycle
but pos could be larger than your vector so you can mod it by the length to get the same value
so less iterating through the array
(= (drop (mod pos (count x)) (cycle x)) (drop pos (cycle x)))
Hm - I think I mod the pos anyway at every step so it should be equivalent?
oh ok missed that 🙂
well that makes much more sense
i should have done that
@orestis btw I'm pretty sure [head & tail]
compiles into first
rest
so they should be equivalent and its pretty idiomatic to use [head & tail]
when iterating
over any collection
Good to know; coming from Elixir where there is some nice syntactic sugar to work with linked lists, I’ve missed that a bit.
I first had a solution with cycle, drop and take, but then decided I could do better with one pass
I could probably make it faster with transients, but I haven’t used any today
@borkdude your solution gets a 👍 for clarity and simplicity
and its way fast enough to get the job done
thanks 🙂
@nooga your hurting my brain 🙂 trying to follow it ... trying ...
sorry 😄
link?
definately not a production code 😄
(c-splice a p (reverse (c-slice a p l)))
for the win
it looks like C written in Clojure 🙂
I see a p l
and I see APL
I get into this mode sometimes 😄
p0, ah, of course, a pointer
and then some bit shifting going on
I wrote this while reading the puzzle, not after
there’s not much conscious thought into this 😄
My day 10: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_10.cljc
What's up with that strange length sequence 3, 4, 1, 5, 17, 31, 73, 47, 23
and skip size 4
in the running example? That tripped me up for a long time.
oh you can mod the skip size!!
well damn
@mfikes nice concise solution
Good thinking on just mapping the indices instead of mapping the values in-place, @borkdude
Less list-shifting shenanigans that way
@orestis - Maybe you'd enjoy poking http://gdeer81.github.io/marginalia/
Ohh that seems nice! I’ll give it a proper look.
@mfikes I think it’s bascially what I did but mine is less clear
Just solved Day 10. I think it's interesting how my solutions per day all look so similar. Maybe it's just me
I'm still curious. Was this just me missing something fundamental, or did others find this a problem. If you know why it is correct, please share. https://clojurians.slack.com/archives/C0GLTDB2T/p1512927092000137
This is my understanding, thinking out loud: the 3, 4, 1, 5
are from the initial lengths in Part 1. The 17, 31, 73, 47, 23
is the "coda" as .@orestis (edited from @fellshard) named it, which is added in Part 2. A the end of the first part, skip was 4 and position is 4. They're picking up where that left off. Am I following you so far?
@grzm Thank-you. That helps! (WTF!)
That makes complete sense. Wow, them hopping back to part 1, after having started a new example involving 49,44,50,44,51,17,31,73,47,23
really threw me off. Attempting to understand that sequence was an order of magnitude harder than just solving the problem. (Or infinitely harder for me, since it escaped my ability to comprehend it.)
Yeah, I'm not sure why they didn't just continue with the ascii-values they already had in part 2.
I was trying desperately to derive 3, 4, 1, 5
from something in part 2.
Actually, they didn't want to redo the whole thing: they wanted to show an example of maintaining state across rounds.
Well, part of the real world is interpreting requirements, right? 😉
Cool. Thanks. "Mike, look at part 1," was all I needed 🙂
Indeed, that is part of problem solving. Requirements interpretation.
Well, the rest of it was me making sure I understood the question
'coda' was someone else's name, but I like it better than 'suffix', which the problem statement used. The problem writing was a bit disorganized and verbose today; perhaps intentionally, perhaps not. Easy to miss the piece about the suffix, as it's not highlighted or mentioned elsewhere.
Right, it was .@orestis
Yeah, generally the problems are very high quality, and day 10 was also a high quality problem. Perhaps the description wasn't as clearly written as some of the previous ones. That's cool—it adds to the challenge.
It's why l like AoC - it mimics real world problems a bit better, both with the explanation sometimes being unclear, yet testable with examples; and with two-part solutions, that force you to refactor or remodeling your solution in many cases. A much more interesting learning experience.