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
borkdude 2017-12-16T09:00:24.000129Z

Hmz. My program for part 1 works for the examples but somehow not for my real input. I get an answer, but it’s wrong.

theeternalpulse 2017-12-16T09:05:37.000006Z

what is the answer?

erwin 2017-12-16T09:06:30.000009Z

do you somehow have a regex only parsing single digits?

borkdude 2017-12-16T09:37:56.000041Z

[0 1 2 3 4 5 6 7 8 9101112131415]
[a b c d e f g h i j k l m n o p]
[a b c k e f g h i j d l m n o p] :EXCHANGE (3 10) CORRECT
[a b c k e f l h i j d g m n o p] :PARTNER (l g)   CORRECT
[h i j d g m n o p a b c k e f l] :SPIN (9)        CORRECT
[h i j d g m l o p a b c k e f n] :EXCHANGE (6 15) CORRECT
[l o p a b c k e f n h i j d g m] :SPIN (10)       CORRECT  

borkdude 2017-12-16T09:38:28.000044Z

My answer is "bfcjlogemipdnakh"

borkdude 2017-12-16T09:44:12.000034Z

My input: https://github.com/borkdude/aoc2017/blob/master/resources/day16.txt

borkdude 2017-12-16T09:53:36.000050Z

My parser seems to be correct: when I coerce the parsed tree back to a string and compare to the input, it’s equal

erwin 2017-12-16T10:03:23.000028Z

@borkdude with your input, I get a different answer

borkdude 2017-12-16T10:03:51.000056Z

thanks

ihabunek 2017-12-16T10:15:11.000019Z

oh dear, first part takes 80ms, which is nowhere fast enough for part 2 😄

ihabunek 2017-12-16T10:17:54.000011Z

it's time to optimize

orestis 2017-12-16T10:37:24.000069Z

Yarg. Yes 🙂

orestis 2017-12-16T10:37:50.000065Z

34msecs here…

orestis 2017-12-16T10:39:59.000074Z

if you narrow it down to 1ms, it’s still 45 days 🙂

orestis 2017-12-16T10:40:05.000070Z

Sorry, 11 days.

orestis 2017-12-16T10:40:16.000014Z

So we have to be a bit more clever…

ihabunek 2017-12-16T10:40:31.000069Z

i have some ideas...

ihabunek 2017-12-16T10:40:43.000059Z

but need to go out now, will try later

ihabunek 2017-12-16T10:42:27.000038Z

i wish i understood macros better 😄

2017-12-16T10:45:05.000120Z

Unfortunately, this finds the wrong answer and I’m too lazy to figure out why

orestis 2017-12-16T10:45:13.000029Z

For part 1 or 2?

2017-12-16T10:45:17.000008Z

1

val_waeselynck 2017-12-16T10:46:27.000039Z

My solutions to day 16, including an exploration / explanation of the algebraic properties that make part 2 viable https://github.com/vvvvalvalval/advent-of-code-2017/tree/master/src

👍 1
2017-12-16T10:47:25.000042Z

@borkdude same here hehe

borkdude 2017-12-16T10:47:38.000072Z

I found the bug btw

2017-12-16T10:48:28.000026Z

I’m still looking for mine, I tested the S, X, P fns and my “parser” seems correct

orestis 2017-12-16T10:48:37.000004Z

@nooga Looking at your code, I find something peculiar; do you want to know or want to battle it?

2017-12-16T10:48:38.000033Z

but the answer is wrong :f

2017-12-16T10:49:01.000021Z

don’t tell me, I’m going to figure it out

orestis 2017-12-16T10:49:11.000011Z

I don’t have time to battle part 2 at the moment…

2017-12-16T10:49:12.000023Z

and it’s probably something stupid

orestis 2017-12-16T10:49:45.000054Z

From past experience, this is probably going to be one of those puzzles where a lot of people will drop off; I find no shame in stealing the answer from someone and moving on though 🙂

2017-12-16T10:51:23.000010Z

I still haven’t done day 14, my knot-hash fn is slow and somehow I get wrong answers, too complex to debug for now

2017-12-16T10:59:19.000060Z

ah, my S function is totally wrong 😄

😉 1
erwin 2017-12-16T11:05:39.000013Z

@val_waeselynck removed spoiler

val_waeselynck 2017-12-16T11:08:05.000032Z

@erwin sure, so did I, I just thought some people might also be interested in the math aspects that make this 'reasonable repetition' possible 🙂

val_waeselynck 2017-12-16T11:08:44.000036Z

oh, and we might have spoiled the others a bit :s

erwin 2017-12-16T11:08:54.000060Z

> since the maximum idempotence exponent for a 16-elements permutation is 5 4 140 I do not understand this part, how do you calculate this?

erwin 2017-12-16T11:09:34.000005Z

original message: your explanation for part-2 is difficult to understand ... 😅 I did "dumb" reasoning: the naive implementation is way to slow (8 hours of calculation), lets assume there is reasonable repetition (even though a 16 items permutation is larger then 1.000.000.000), because otherwise this puzzle is no fun 😉

orestis 2017-12-16T11:11:53.000008Z

I did a far more naive thing, tried to see if there were repetitions in the states which is somewhat expectable as I calculated at least 10 days of calculations…

orestis 2017-12-16T11:12:16.000033Z

And indeed I arrived at the 24 + 16…

orestis 2017-12-16T11:15:27.000002Z

@val_waeselynck Can you point me to the math concepts/names that you explain in part 2?

orestis 2017-12-16T11:16:18.000064Z

I had some initial idea that some instructions might cancel each other out (e.g. the pairings) but I lacked the formal math to prove it.

orestis 2017-12-16T11:17:01.000004Z

i.e. my first hunch was to do what you did for “fun” but had no idea how to reason about it. Would love to learn more 🙂

2017-12-16T11:19:38.000012Z

my idea is to find a cycle and basically start from the last one

val_waeselynck 2017-12-16T11:23:29.000001Z

Some keywords: Permutations (one-to-one functions of a finite set onto itself), the fact that transpositions and rotations of elements are permutations, the fact that a permutation composed to another permutation is still a permutation, and finally the fact that every permutation can be decomposed into rotations of disjoint support, which is what helps you compute that idempotence exponent (the lowest common multiple of the cycles' lengths).

val_waeselynck 2017-12-16T11:23:47.000057Z

Not useful to solve the problem per se, but useful to be confident in the fact that the period will be small

val_waeselynck 2017-12-16T11:28:28.000096Z

@orestis @erwin ^

erwin 2017-12-16T11:50:00.000080Z

thanks

orestis 2017-12-16T11:55:04.000062Z

Thanks, I will have to dig deeper some time. And I'll also have to see how you did the AOT analysis of the input, as that is a generally useful technique.

val_waeselynck 2017-12-16T12:01:41.000043Z

@orestis what I called AOT here was just compacting the steps into 2 permutations, not sure it will be much reusable as it leveraged the same algebraic properties I mentionned above 🙂

2017-12-16T12:08:12.000056Z

ha, done

👍 1
2017-12-16T12:19:09.000032Z

it crashes this funny repl but works on my machine

2017-12-16T12:21:51.000101Z

I tried to compile the input into something like (fn [initial-state] (-> initial-state (S 1) (X 1 3) ...)) and then evaling it for fun but it just caused a stack overflow in clojure compiler

2017-12-16T12:21:56.000020Z

😂

2017-12-16T12:23:33.000069Z

I could probably get away with series of swap!s on an atom though

bhauman 2017-12-16T14:11:43.000039Z

@nooga your are probably having a cons explosion?

2017-12-16T14:12:02.000068Z

@bhauman where?

bhauman 2017-12-16T14:12:42.000020Z

does your stack overflow say "lazySeq.Cons" or someting like that?

bhauman 2017-12-16T14:13:06.000003Z

what happens is that you can build up too much lazy state

bhauman 2017-12-16T14:13:20.000112Z

and when it finally comes due it explodes

2017-12-16T14:13:25.000011Z

no idea, I scrapped this “compiler” function

2017-12-16T14:13:57.000058Z

but I’d suppose that was rather caused by putting too many expressions in ->

bhauman 2017-12-16T14:15:26.000103Z

no its normally from nested lazy seqs that grow to large by the time you start to consume them

bhauman 2017-12-16T14:16:01.000063Z

so basically the code I'm looking at is different from the code you were using earlier

bhauman 2017-12-16T14:17:11.000002Z

anyway asking for a billion was a dead give away, it would have been brutal if they asked for something just outside of plausible

grzm 2017-12-16T14:34:26.000023Z

okay. I thought I'd just let that run overnight. Still hasn't finished.

borkdude 2017-12-16T14:39:52.000078Z

Great puzzle today. I have yet to clean up my code.

mfikes 2017-12-16T14:49:38.000067Z

Yeah, while part 1 can be tedious, it is straightforward. Part 2 had nice characteristics.

borkdude 2017-12-16T16:25:38.000066Z

My InstaParser is a bit slow (~850ms). Wonder how long your folks’ parsing takes?

borkdude 2017-12-16T16:30:13.000025Z

Could probably optimize it by handwriting it.

2017-12-16T16:38:32.000049Z

@bhauman the code I was talking about looked more or less like this https://repl.it/repls/KookyBestTurkey

borkdude 2017-12-16T17:42:20.000080Z

Hand-written parser: ~8ms https://github.com/borkdude/aoc2017/blob/master/src/day16.clj#L119

grzm 2017-12-16T20:01:13.000084Z

Interesting. I've got a solution which works for part-1, gives me the correct period for part-2, but not the correct answer for part-2. It's two transpositions off. And it doesn't look like an off-by-one error, as neither solution on either side is correct either.

2017-12-16T21:06:03.000028Z

@grzm I was in the same situation and then I noticed 10e9 instead of 1e9

2017-12-16T21:06:36.000053Z

so it was off by 0 this time 😉

grzm 2017-12-16T21:08:26.000025Z

@nooga thanks for an idea to confirm. but that's one off-by-zero that I don't have 😞

grzm 2017-12-16T21:08:58.000052Z

I do wish Clojure accepted number syntax like 1_000_000_000 for cases like this.

2017-12-16T21:21:44.000087Z

it does accept scientific notation like, well, 1e9 for cases like this

grzm 2017-12-16T21:22:26.000040Z

true. doesn't help with 1234765890, though

bhauman 2017-12-16T21:23:52.000009Z

I always make the mistake of thinking this syntax exists b/c we have such an awesome reader, but alas I'm always wrong

grzm 2017-12-16T21:32:05.000029Z

How can it be wrong when it feels so right?

borkdude 2017-12-16T21:54:59.000007Z

Added a Kern parser implementation for day 16: https://github.com/borkdude/aoc2017/blob/master/src/day16.clj#L115

val_waeselynck 2017-12-16T23:46:04.000021Z

Nothing like a 26-hours plane trip to catch up on AoC 🙂 I know I'm late to the party, but I wonder what you guys thought of day 11 (Haxagonal Grid)? Did you find it difficult? It took me a lot of head scratching to achieve a clean solution, and even then if feels like it could be simpler (here if you're curious: https://github.com/vvvvalvalval/advent-of-code-2017/blob/master/src/aoc2017/day11.clj)