Author Topic: Advent of Code  (Read 35259 times)

vorsprung

  • Opposites Attract
    • Audaxing
Re: Advent of Code
« Reply #750 on: December 03, 2019, 08:56:50 pm »
This year I'm doing them in C# instead of Perl. ... 174 lines of code + tests, would probably have been about ten in Perl.

That's progress!
Audaxing Blog follow @vorsprungbike on

Re: Advent of Code
« Reply #751 on: December 03, 2019, 11:48:29 pm »
$ wc -l 3?.pl
  52 3a.pl
  58 3b.pl

I tend to copy the file when I start part b as I hack what I've done rather than trying to come up with a single program that does both. The difference between this particular day's a and b parts were 6 new lines in b (keeping track of steps to each point) and 4 lines changed (which dealt with keeping track of the minimum step values for a crossing instead of the minimum manhattan distance).

0 lines of tests. ;)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #752 on: December 04, 2019, 08:52:48 am »
This year I'm doing them in C# instead of Perl. The gains from a nice test framework and intellisense are more than cancelled out by the sheer wordiness of it all.

Delay today caused by trying to dump all the points into Lists and do a Linq intersect to pop out all the crossings. Great for the tests, way too slow for the full puzzle - didn't expect to get hit by that on day 3. So had to go back and do it again properly. 174 lines of code + tests, would probably have been about ten in Perl.

I tried a linq intersect, found it slow, but then I applied an optimization: remove all points from wire A outside the bounding box of wire B. Remove all points from wire B outside the bounding box of wire A. Do it iteratively till you remove no more.
Ran in 28 seconds.
It is matching ~70,000 x 70,000 instead of ~150,000 x ~150,000.

It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #753 on: December 04, 2019, 09:30:21 am »
28 seconds?

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #754 on: December 04, 2019, 12:53:43 pm »
28 seconds?


Yeah... I probably could have optimized it like you have but I didn't need to and it would have took me longer than 28 seconds to do it :)

Day 5 looks good, probably a recursive algorithm but haven't tried it yet
It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #755 on: December 04, 2019, 01:25:38 pm »
Day 5 looks good, probably a recursive algorithm but haven't tried it yet

You see the future!

(Won't post any spoilers until most people have had a go.)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #756 on: December 04, 2019, 04:54:11 pm »
Day 5 looks good, probably a recursive algorithm but haven't tried it yet

You see the future!

(Won't post any spoilers until most people have had a go.)

(click to show/hide)
It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #757 on: December 04, 2019, 04:59:47 pm »
For me day 5 is in 12 hours time.  Passwords with doubles was day 4.

Re: Advent of Code
« Reply #758 on: December 04, 2019, 05:03:10 pm »
That was my joke about being able to see the future!

(He can't, he's just got the day wrong.)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #759 on: December 04, 2019, 05:57:35 pm »
That was my joke about being able to see the future!

(He can't, he's just got the day wrong.)

I mean to be pedantic it should really be day 3, with 1st Dec being day 0  :D

(The " largest piece of ui", the timer, is on day 5 when you're actually on day 4)
It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #760 on: December 04, 2019, 11:07:42 pm »
Only because someone suggested it could be done with grep:-

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #761 on: December 05, 2019, 11:38:25 am »
2019 Day 5:

As usual the biggest problems are not reading it clearly enough and trying to jump in to get it done. That and silly copypasta errors.

The snippets of test case code was nice, they certainly helped me track down my mistake.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #762 on: December 05, 2019, 12:03:01 pm »
Main mistake with day 5, was thinking that python might be a good language. Whoever heard of having to re-declare a variable's globalness in every function it is used in, FFS.   :facepalm:
It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #763 on: December 05, 2019, 03:27:02 pm »
I might observe that Day 5 instructions include some artful misdirection


(click to show/hide)

Re: Advent of Code
« Reply #764 on: December 05, 2019, 03:47:45 pm »
I might observe that Day 5 instructions include some artful misdirection


(click to show/hide)

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #765 on: December 05, 2019, 03:52:08 pm »
No.  5 & 6

Re: Advent of Code
« Reply #766 on: December 05, 2019, 04:36:14 pm »
BTW, I'm expecting INPUT and OUTPUT to go the same way that https://adventofcode.com/2017/day/18 did and you'll end up needing two copies of the 'computer' running at the same time swapping inputs/outputs and vice versa.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #767 on: December 05, 2019, 05:21:50 pm »
I might observe that Day 5 instructions include some artful misdirection


(click to show/hide)

(click to show/hide)
It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #768 on: December 05, 2019, 06:18:37 pm »
(Replying to spoiler above)

Well, it only works with one interpretation.

An eyeball analysis of the test program should show that interpreting the other way quickly leads to unknown opcodes.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #769 on: December 05, 2019, 06:44:16 pm »
I don't know if it was sneaky but misintepreting 5 and 6 led to code than ran all 4 test programs and gave the correct answers, but crapped out on two of the conditions of the longer 5th test program.  Most confusing.

Re: Advent of Code
« Reply #770 on: December 05, 2019, 06:59:49 pm »
I don't know if it was sneaky but misintepreting 5 and 6 led to code than ran all 4 test programs and gave the correct answers, but crapped out on two of the conditions of the longer 5th test program.  Most confusing.

Based on previous years I think he specifically designs things like that into the puzzles.

I remember one puzzle (can't remember exactly which one or which year) that my hastily thrown together perl program would pass all of the example/test inputs but failed on my personal puzzle input. Turned out that the main puzzle input was specifically crafted to trick languages like perl that have lazy typing as it interpreted some of the integer values as octal, so incrementing something like "007" would get you "010" not "008" leading to very hard to find bugs.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #771 on: December 05, 2019, 07:42:15 pm »
Yeah. The instructions also said it prints "a series of diagnostic error codes which should all be zero" and then prints the answer.
Mine printed a number 3 first, then a load of zeros, then the answer. But the 3 didn't seem to indicate I had a bug, as the answer was still right.
Could the errant 3 be a hint to a future puzzle that complains of "one of the spaceships' systems not working properly", I wonder...

There seems to be several different ways he can make the puzzles non-trivial - the main ones I've seen so far are (1) making the spec fairly complicated so you have to read it thoroughly, (2) is by making the data such that the 'obvious' / brute-force solution would never complete quickly enough, and an optimization or dynamic programming is required, (3) is by introducing a reverse-engineering requirement, like when the 'machine code' is in fact doing a loop with all its jumps and you have to figure out what the loop's trying to do.
There is the other one you mention of trying to trick specific languages, integer overflows are an obvious one. I quite enjoy the challenge imposed by that to be honest.

I personally enjoy (2) most. I don't enjoy (1) quite so much, and I find (3) difficult.

I sometimes do wonder whether he will introduce another one of making puzzles refer to past ones, possibly even implicitly.
It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #772 on: December 05, 2019, 07:52:50 pm »
Yeah. The instructions also said it prints "a series of diagnostic error codes which should all be zero" and then prints the answer.
Mine printed a number 3 first, then a load of zeros, then the answer. But the 3 didn't seem to indicate I had a bug, as the answer was still right.
Could the errant 3 be a hint to a future puzzle that complains of "one of the spaceships' systems not working properly", I wonder...

If you give me your input I can run it through mine and see what I get. Here's my input:-

Code: [Select]
3,225,1,225,6,6,1100,1,238,225,104,0,1002,92,42,224,1001,224,-3444,224,4,224,102,8,223,223,101,4,224,224,1,224,223,223,1102,24,81,225,1101,89,36,224,101,-125,224,224,4,224,102,8,223,223,101,5,224,224,1,224,223,223,2,118,191,224,101,-880,224,224,4,224,1002,223,8,223,1001,224,7,224,1,224,223,223,1102,68,94,225,1101,85,91,225,1102,91,82,225,1102,85,77,224,101,-6545,224,224,4,224,1002,223,8,223,101,7,224,224,1,223,224,223,1101,84,20,225,102,41,36,224,101,-3321,224,224,4,224,1002,223,8,223,101,7,224,224,1,223,224,223,1,188,88,224,101,-183,224,224,4,224,1002,223,8,223,1001,224,7,224,1,224,223,223,1001,84,43,224,1001,224,-137,224,4,224,102,8,223,223,101,4,224,224,1,224,223,223,1102,71,92,225,1101,44,50,225,1102,29,47,225,101,7,195,224,101,-36,224,224,4,224,102,8,223,223,101,6,224,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,107,677,677,224,1002,223,2,223,1006,224,329,1001,223,1,223,1108,226,677,224,102,2,223,223,1006,224,344,101,1,223,223,1107,226,226,224,1002,223,2,223,1006,224,359,101,1,223,223,8,677,226,224,1002,223,2,223,1006,224,374,1001,223,1,223,1107,677,226,224,102,2,223,223,1005,224,389,1001,223,1,223,1008,677,677,224,1002,223,2,223,1006,224,404,1001,223,1,223,108,677,677,224,102,2,223,223,1005,224,419,1001,223,1,223,1107,226,677,224,102,2,223,223,1006,224,434,101,1,223,223,1008,226,226,224,1002,223,2,223,1006,224,449,1001,223,1,223,107,226,226,224,102,2,223,223,1006,224,464,1001,223,1,223,1007,677,226,224,1002,223,2,223,1006,224,479,1001,223,1,223,1108,226,226,224,102,2,223,223,1006,224,494,1001,223,1,223,8,226,226,224,1002,223,2,223,1005,224,509,1001,223,1,223,7,226,677,224,102,2,223,223,1005,224,524,101,1,223,223,1008,677,226,224,102,2,223,223,1005,224,539,101,1,223,223,107,226,677,224,1002,223,2,223,1006,224,554,1001,223,1,223,1108,677,226,224,102,2,223,223,1005,224,569,101,1,223,223,108,226,226,224,1002,223,2,223,1005,224,584,1001,223,1,223,7,677,226,224,1002,223,2,223,1005,224,599,1001,223,1,223,108,226,677,224,1002,223,2,223,1006,224,614,101,1,223,223,1007,677,677,224,1002,223,2,223,1006,224,629,101,1,223,223,7,677,677,224,102,2,223,223,1005,224,644,101,1,223,223,1007,226,226,224,1002,223,2,223,1006,224,659,1001,223,1,223,8,226,677,224,102,2,223,223,1005,224,674,1001,223,1,223,4,223,99,226

This (with an input of 1) gives 9 zeroes and then my answer of 9961446. With an input of 5 it gives 742621.

There seems to be several different ways he can make the puzzles non-trivial - the main ones I've seen so far are (1) making the spec fairly complicated so you have to read it thoroughly, (2) is by making the data such that the 'obvious' / brute-force solution would never complete quickly enough, and an optimization or dynamic programming is required, (3) is by introducing a reverse-engineering requirement, like when the 'machine code' is in fact doing a loop with all its jumps and you have to figure out what the loop's trying to do.
There is the other one you mention of trying to trick specific languages, integer overflows are an obvious one. I quite enjoy the challenge imposed by that to be honest.

I personally enjoy (2) most. I don't enjoy (1) quite so much, and I find (3) difficult.

Roughly similar here. Finding the most appropriate algorithm is always nice. #3 always reminds me of days of old where I did more reverse engineering, it was never really that much "fun".
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #773 on: December 05, 2019, 08:09:24 pm »
Yeah. The instructions also said it prints "a series of diagnostic error codes which should all be zero" and then prints the answer.
Mine printed a number 3 first, then a load of zeros, then the answer. But the 3 didn't seem to indicate I had a bug, as the answer was still right.
Could the errant 3 be a hint to a future puzzle that complains of "one of the spaceships' systems not working properly", I wonder...

If you give me your input I can run it through mine and see what I get. Here's my input:-

Code: [Select]
3,225,1,225,6,6,1100,1,238,225,104,0,1002,92,42,224,1001,224,-3444,224,4,224,102,8,223,223,101,4,224,224,1,224,223,223,1102,24,81,225,1101,89,36,224,101,-125,224,224,4,224,102,8,223,223,101,5,224,224,1,224,223,223,2,118,191,224,101,-880,224,224,4,224,1002,223,8,223,1001,224,7,224,1,224,223,223,1102,68,94,225,1101,85,91,225,1102,91,82,225,1102,85,77,224,101,-6545,224,224,4,224,1002,223,8,223,101,7,224,224,1,223,224,223,1101,84,20,225,102,41,36,224,101,-3321,224,224,4,224,1002,223,8,223,101,7,224,224,1,223,224,223,1,188,88,224,101,-183,224,224,4,224,1002,223,8,223,1001,224,7,224,1,224,223,223,1001,84,43,224,1001,224,-137,224,4,224,102,8,223,223,101,4,224,224,1,224,223,223,1102,71,92,225,1101,44,50,225,1102,29,47,225,101,7,195,224,101,-36,224,224,4,224,102,8,223,223,101,6,224,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,107,677,677,224,1002,223,2,223,1006,224,329,1001,223,1,223,1108,226,677,224,102,2,223,223,1006,224,344,101,1,223,223,1107,226,226,224,1002,223,2,223,1006,224,359,101,1,223,223,8,677,226,224,1002,223,2,223,1006,224,374,1001,223,1,223,1107,677,226,224,102,2,223,223,1005,224,389,1001,223,1,223,1008,677,677,224,1002,223,2,223,1006,224,404,1001,223,1,223,108,677,677,224,102,2,223,223,1005,224,419,1001,223,1,223,1107,226,677,224,102,2,223,223,1006,224,434,101,1,223,223,1008,226,226,224,1002,223,2,223,1006,224,449,1001,223,1,223,107,226,226,224,102,2,223,223,1006,224,464,1001,223,1,223,1007,677,226,224,1002,223,2,223,1006,224,479,1001,223,1,223,1108,226,226,224,102,2,223,223,1006,224,494,1001,223,1,223,8,226,226,224,1002,223,2,223,1005,224,509,1001,223,1,223,7,226,677,224,102,2,223,223,1005,224,524,101,1,223,223,1008,677,226,224,102,2,223,223,1005,224,539,101,1,223,223,107,226,677,224,1002,223,2,223,1006,224,554,1001,223,1,223,1108,677,226,224,102,2,223,223,1005,224,569,101,1,223,223,108,226,226,224,1002,223,2,223,1005,224,584,1001,223,1,223,7,677,226,224,1002,223,2,223,1005,224,599,1001,223,1,223,108,226,677,224,1002,223,2,223,1006,224,614,101,1,223,223,1007,677,677,224,1002,223,2,223,1006,224,629,101,1,223,223,7,677,677,224,102,2,223,223,1005,224,644,101,1,223,223,1007,226,226,224,1002,223,2,223,1006,224,659,1001,223,1,223,8,226,677,224,102,2,223,223,1005,224,674,1001,223,1,223,4,223,99,226

This (with an input of 1) gives 9 zeroes and then my answer of 9961446. With an input of 5 it gives 742621.
Hmm, cheers - ok just tried it again and it's not printing the phantom '3' now. Must have just been a debugging line I left in...cheers anyway
It is what it is. It's not what it's not, so it must be what it is.

Re: Advent of Code
« Reply #774 on: December 06, 2019, 09:30:17 am »
Yet more "READ IT PROPERLY" fun today.

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."