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
theeternalpulse 2017-12-10T06:03:54.000043Z

Yikes, half way through day 3 and I'm sure I'll find a simpler intuitive solution in the other ones.

fellshard 2017-12-10T06:20:50.000063Z

Hmm. My soln. for today's part two matches the example inputs, but not my own.

fellshard 2017-12-10T06:23:48.000033Z

Ooooh. Bad hex formatting, I think.

fellshard 2017-12-10T06:24:28.000004Z

:picard-facepalm:

grzm 2017-12-10T06:34:37.000047Z

I'm glad my solution worked, because I don't know how I would have debugged that.

fellshard 2017-12-10T06:37:04.000052Z

It's... definitely a 'walk through by hand' deal. Best I could do was run through their small example step-by-step.

grzm 2017-12-10T06:37:49.000014Z

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.

😌 1
grzm 2017-12-10T06:39:14.000042Z

Now trying to port it to cljs

grzm 2017-12-10T06:59:31.000007Z

Pushed. Now to sleep!

🙋 1
fellshard 2017-12-10T07:46:00.000035Z

Moar yak shaving for the 'twist' logic, I feel a lot better about it now. Found the right abstraction for the job.

orestis 2017-12-10T10:35:16.000055Z

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

orestis 2017-12-10T10:38:50.000070Z

@fellshard Nice solution! I like your twist logic; I went with a transient vector instead.

borkdude 2017-12-10T12:20:24.000070Z

1.3 ms for part 1, 224ms for part 2

2017-12-10T13:29:47.000049Z

here’s mine

2017-12-10T13:33:39.000077Z

3.9ms / 224,8ms

grzm 2017-12-10T15:15:51.000102Z

@orestis nice mix of code, tests, and description

orestis 2017-12-10T15:26:36.000006Z

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.

orestis 2017-12-10T15:27:31.000025Z

I’m sure there is a way of doing this better, literate programming? Perhaps some kind of jupyter notebook?

grzm 2017-12-10T15:27:58.000004Z

I'm much more pragmatic about it: you've got a solution that works really well.

orestis 2017-12-10T15:29:06.000015Z

I would like to look into devcards to make the whole thing interactive and shareable.

grzm 2017-12-10T15:29:32.000002Z

Looks like there's a smaller set of inputs for Day 10. @borkdude and I have the same one.

orestis 2017-12-10T15:30:34.000024Z

AFAIK, there’s only 10-20 inputs per puzzle, as the have to all be validated beforehand.

grzm 2017-12-10T15:30:46.000077Z

makes sense

orestis 2017-12-10T15:30:53.000008Z

AFAIK, there’s only 10-20 inputs per puzzle, as they have to all be validated beforehand.

borkdude 2017-12-10T15:31:25.000077Z

@orestis devcards isn’t that more for showing UI components? you could also try klipse, so anyone could play with it in the browser

grzm 2017-12-10T15:33:24.000081Z

@borkdude: how does yours work with using "%x" for formatting? I needed to use "%02x"

grzm 2017-12-10T15:34:04.000020Z

I've run yours locally and confirmed it works.

orestis 2017-12-10T15:34:14.000039Z

Ah, yes, I haven’t used either so got them mixed up.

borkdude 2017-12-10T15:34:55.000079Z

@grzm don’t know, haven’t thought about it deeply

grzm 2017-12-10T15:38:33.000007Z

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.

borkdude 2017-12-10T15:40:47.000085Z

thanks, I’ll enhance

bhauman 2017-12-10T16:11:27.000075Z

60ms on part 2 🙂

bhauman 2017-12-10T16:11:43.000082Z

but it wasn't easy

bhauman 2017-12-10T16:13:03.000034Z

found some weird things: like apply is faster than arg destructuring

bhauman 2017-12-10T16:13:57.000042Z

in my first version, part 2 never finished as I got tired of waiting after 5 minutes

bhauman 2017-12-10T16:17:14.000031Z

@orestis our answers are so similar 🙂

bhauman 2017-12-10T16:18:55.000009Z

@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

orestis 2017-12-10T16:19:41.000003Z

Is (let [[head & tail] s]) the idiomatic way to do (let [head (first s) tail (rest s)]) when you know you deal with vectors?

bhauman 2017-12-10T16:20:15.000074Z

I wouldn't say so

orestis 2017-12-10T16:20:26.000073Z

@bhauman You mean by skipping the cycle?

bhauman 2017-12-10T16:21:01.000066Z

you keep the cycle

bhauman 2017-12-10T16:21:35.000030Z

but pos could be larger than your vector so you can mod it by the length to get the same value

bhauman 2017-12-10T16:21:50.000025Z

so less iterating through the array

bhauman 2017-12-10T16:23:23.000046Z

(= (drop (mod pos (count x)) (cycle x)) (drop pos (cycle x)))

orestis 2017-12-10T16:24:56.000055Z

Hm - I think I mod the pos anyway at every step so it should be equivalent?

bhauman 2017-12-10T16:25:11.000081Z

oh ok missed that 🙂

bhauman 2017-12-10T16:25:49.000059Z

well that makes much more sense

bhauman 2017-12-10T16:27:13.000002Z

i should have done that

bhauman 2017-12-10T16:29:28.000009Z

@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

bhauman 2017-12-10T16:29:41.000014Z

over any collection

orestis 2017-12-10T16:32:33.000142Z

Good to know; coming from Elixir where there is some nice syntactic sugar to work with linked lists, I’ve missed that a bit.

borkdude 2017-12-10T16:33:10.000055Z

I first had a solution with cycle, drop and take, but then decided I could do better with one pass

borkdude 2017-12-10T16:33:36.000084Z

I could probably make it faster with transients, but I haven’t used any today

bhauman 2017-12-10T16:35:12.000136Z

@borkdude your solution gets a 👍 for clarity and simplicity

bhauman 2017-12-10T16:36:14.000025Z

and its way fast enough to get the job done

borkdude 2017-12-10T16:37:16.000048Z

thanks 🙂

bhauman 2017-12-10T16:38:14.000039Z

@nooga your hurting my brain 🙂 trying to follow it ... trying ...

2017-12-10T16:38:25.000049Z

sorry 😄

borkdude 2017-12-10T16:38:42.000047Z

link?

2017-12-10T16:39:32.000056Z

definately not a production code 😄

bhauman 2017-12-10T16:40:13.000078Z

(c-splice a p (reverse (c-slice a p l))) for the win

borkdude 2017-12-10T16:40:14.000091Z

it looks like C written in Clojure 🙂

bhauman 2017-12-10T16:41:01.000079Z

I see a p l and I see APL

2017-12-10T16:41:04.000033Z

I get into this mode sometimes 😄

👍 1
borkdude 2017-12-10T16:41:28.000049Z

p0, ah, of course, a pointer

borkdude 2017-12-10T16:41:38.000095Z

and then some bit shifting going on

2017-12-10T16:42:49.000019Z

I wrote this while reading the puzzle, not after

2017-12-10T16:43:49.000078Z

there’s not much conscious thought into this 😄

mfikes 2017-12-10T17:31:32.000137Z

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.

bhauman 2017-12-10T17:31:48.000017Z

oh you can mod the skip size!!

bhauman 2017-12-10T17:31:55.000002Z

well damn

borkdude 2017-12-10T17:42:19.000111Z

@mfikes nice concise solution

fellshard 2017-12-10T18:42:54.000033Z

Good thinking on just mapping the indices instead of mapping the values in-place, @borkdude

fellshard 2017-12-10T18:43:13.000053Z

Less list-shifting shenanigans that way

fellshard 2017-12-10T18:44:40.000035Z

@orestis - Maybe you'd enjoy poking http://gdeer81.github.io/marginalia/

orestis 2017-12-10T19:17:59.000118Z

Ohh that seems nice! I’ll give it a proper look.

2017-12-10T19:24:43.000070Z

@mfikes I think it’s bascially what I did but mine is less clear

jmb 2017-12-10T22:15:42.000041Z

Just solved Day 10. I think it's interesting how my solutions per day all look so similar. Maybe it's just me

mfikes 2017-12-10T23:05:07.000103Z

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

grzm 2017-12-10T23:17:22.000112Z

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?

mfikes 2017-12-10T23:19:56.000044Z

@grzm Thank-you. That helps! (WTF!)

mfikes 2017-12-10T23:25:16.000095Z

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.)

grzm 2017-12-10T23:26:07.000063Z

Yeah, I'm not sure why they didn't just continue with the ascii-values they already had in part 2.

mfikes 2017-12-10T23:26:41.000058Z

I was trying desperately to derive 3, 4, 1, 5 from something in part 2.

grzm 2017-12-10T23:26:51.000062Z

Actually, they didn't want to redo the whole thing: they wanted to show an example of maintaining state across rounds.

grzm 2017-12-10T23:27:27.000036Z

Well, part of the real world is interpreting requirements, right? 😉

mfikes 2017-12-10T23:27:35.000005Z

Cool. Thanks. "Mike, look at part 1," was all I needed 🙂

mfikes 2017-12-10T23:27:54.000055Z

Indeed, that is part of problem solving. Requirements interpretation.

grzm 2017-12-10T23:29:27.000037Z

Well, the rest of it was me making sure I understood the question

fellshard 2017-12-10T23:31:34.000027Z

'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.

grzm 2017-12-10T23:32:29.000075Z

Right, it was .@orestis

mfikes 2017-12-10T23:34:22.000093Z

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.

fellshard 2017-12-10T23:37:26.000018Z

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.