Author Topic: Advent of Code  (Read 112644 times)

Re: Advent of Code
« Reply #800 on: 11 December, 2019, 09:46:46 pm »
What haven't we had yet?

* Reverse engineering? (Almost certainly we'll be presented with an Intcode computer that even with the most optimal implementation will still take far too long to run in normal time, so we'll have to work out what it is doing and then optimise that)

* SAT solver

* An A* type solver (heavy on the backtracking)

* Something geometric (especially if it's 3D)

What else?
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #801 on: 12 December, 2019, 08:27:17 am »
Well Day 12 part 2 seems fun. Haven't worked out what the trick is yet.

[EDIT] Worked out what the trick is!

Rejigged it a bit:-

Code: [Select]
$ cat inp | time ./12d.pl
A: *elided*
B: *elided to avoid spoilers*
0.78user 0.00system 0:00.78elapsed 100%CPU (0avgtext+0avgdata 9472maxresident)k
0inputs+0outputs (0major+631minor)pagefaults 0swaps

Might rewrite it in C to see how fast I can make it go...

Code: [Select]
$ cat inp | time ./12d
A: *elided*
B: *elided to avoid spoilers*
0.00user 0.00system 0:00.00elapsed 100%CPU (0avgtext+0avgdata 2176maxresident)k
0inputs+0outputs (0major+170minor)pagefaults 0swaps

Ping!

Finer grained timings:-

Code: [Select]
$ cat inp | ./12d 1000
*output elided to avoid spoilers*
init = 126 usec total
a = 218 usec total
calc = 8628 usec total
b = 8644 usec total

So initialisation (parsing the file) is taking 126 usec.
Calculating part a and outputting the answer is taking 92 usec.
Part b takes 8426 usec with the bulk of that in an initial computation and 16 usec in a secondary computation.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #802 on: 13 December, 2019, 10:18:45 am »
Day 13 is awesome.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #803 on: 14 December, 2019, 05:07:02 am »
GN: I'm up as the puzzle opens.

BN: I'm absolutely shitfaced.

GN: I'll have a look at the puzzle anyway, you never know...

BN: There are lots of words and symbols and things that I really can't comprehend right now

GN/BN: Dqvnk

P.S. Day 13 was awesome
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #804 on: 14 December, 2019, 02:32:21 pm »
Glad it was a gentle one today (day 14). Not sure my hungover brain would have coped with anything trickier.
"Yes please" said Squirrel "biscuits are our favourite things."

Ben T

Re: Advent of Code
« Reply #805 on: 15 December, 2019, 08:56:56 pm »
Just catching up, yes like day 13...was almost lamenting use of a console app but then found there is a SetCursorPosition function which prevents having to redraw and can animate it in a non-flickery way :)

Re: Advent of Code
« Reply #806 on: 16 December, 2019, 01:06:06 am »
Late to it today as I'd been out all day at a family party. Chased a few silly bugs in a dreadful implementation but got it done.

The way I'd implemented meant it was only a very small change required to do part 2.

Loving the use of IntCode computers to provide inputs (i.e. the maze) that can't be analysed directly.

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

Re: Advent of Code
« Reply #807 on: 16 December, 2019, 04:18:04 pm »
Day 16.

Easy!

What? Eh? What?! Ah.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #808 on: 16 December, 2019, 06:47:22 pm »
(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #809 on: 16 December, 2019, 07:32:25 pm »
Finally completed day 10 part 2.  I got stuck for a long time because I was getting the correct answer for the test case but the list of test cases only matched my output in a few places.  Importantly the 200th answer in the test case was correct and when I chanced my actual input it actually delivered the correct response.
Clever enough to know I'm not clever enough.

Re: Advent of Code
« Reply #810 on: 17 December, 2019, 11:16:22 am »
Finally completed day 10 part 2.  I got stuck for a long time because I was getting the correct answer for the test case but the list of test cases only matched my output in a few places.  Importantly the 200th answer in the test case was correct and when I chanced my actual input it actually delivered the correct response.

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

Re: Advent of Code
« Reply #811 on: 17 December, 2019, 11:24:32 am »
...Catching up from yesterday (did it yesterday but didn't have time to post about it)...

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

Re: Advent of Code
« Reply #812 on: 17 December, 2019, 11:24:40 am »
Day 17. Another example of READ THE TEXT, then READ IT AGAIN.

I spent 15 minutes banging my head against random things before realising I was doing something stupid.

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

Re: Advent of Code
« Reply #813 on: 17 December, 2019, 08:53:45 pm »
I have test cases for asteroids lying on the X and Y axes so that I don't run into that problem.
Clever enough to know I'm not clever enough.

Re: Advent of Code
« Reply #814 on: 18 December, 2019, 02:18:28 pm »
(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #815 on: 19 December, 2019, 09:45:30 am »
(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #816 on: 19 December, 2019, 11:57:36 am »
What haven't we had yet?

* Reverse engineering? (Almost certainly we'll be presented with an Intcode computer that even with the most optimal implementation will still take far too long to run in normal time, so we'll have to work out what it is doing and then optimise that)

This is still looming.

I was also thinking, on my commute in, about various IntCode related trickiness that could be thrown in:-
* Storing things at huge memory increments, i.e. storing at address 10,000,000, then 20,000,000 and so on up to some large number. Anyone who uses an array (or auto-expanding array) for memory will be slowly stuffed.
* Storing things at really huge memory locations, i.e. 9,000,000,000,000,000,000 (i.e. just below 2^63) - again, anyone using a basic array for memory is toast
* Playing on the edge of 32-bit or 64-bit numbers, e.g. something that creates numbers greater than 2^31 but less than 2^32 so that anything that uses signed 32-bit integers blows up. Likewise for signed 64-bit integers. Some intermediate result is 2^63 < x < 2^64 which will cause almost impossible to spot bugs as the result may still look plausible

My mitigations so far are:-
* I use a hash for my memory so it doesn't matter how big the numbers get, although it's slightly slower than using an array
* I use perl so I get automatic use of signed 64-bit integers although you need to be careful how you print out really large numbers as the defaults flick to E notation at ~19 digits

Future mitigations are:-
* Rewrite in C to be faster although that makes storing sparse memory locations in a hash a bit more work
* Still relatively slow due to the interprocess-communication so I should really have a perl version that can instantiate and run multiple IntCode computers in the same process
* Store low memory (0-1,000,000) in an array for speed and anything else in a hash
* Attempt to spot over/under-flow in calculations and exit if spotted
* Option to use 32-bit signed ints (for speed), 64-bit signed ints (where necessary), and libgmp for arbitrary length integers (assuming this becomes a problem later on)

(I don't like the idea of using libgmp or another library, I've done all of the problems so far without using any extra libraries/modules bar IPC::Open2 to be able to talk to my IntCode computer run as a separate process.)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #817 on: 20 December, 2019, 01:26:57 pm »
(click to show/hide)

Expecting a horror show tomorrow or Sunday though.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #818 on: 21 December, 2019, 03:15:29 pm »
Enjoyed today (2019 day 21). Got my 9yo daughter to help me out with the logic for the first bit, especially good as you could see the results of trying different bits of logic.

She lost interest for part 2 though and, quite rightly, said "It's just more of the same, just a bit harder" and went back to programming with Scratch on her Raspberry Pi.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #819 on: 22 December, 2019, 12:43:47 pm »
Expecting a horror show tomorrow or Sunday though.

Always fun to see the leaderboards and see that part 2 has taken a long time for the 100th person (>2h in this case). Not sure if I'll have time to do it this afternoon before I have to go out.

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

Re: Advent of Code
« Reply #820 on: 22 December, 2019, 02:25:54 pm »
(click to show/hide)

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

Ben T

Re: Advent of Code
« Reply #821 on: 24 December, 2019, 11:23:35 pm »
day 16 been grriiiiiiinnnnding away since, well, day 16. Think I might have to stop it.  :-[

Ben T

Re: Advent of Code
« Reply #822 on: 27 December, 2019, 02:45:07 pm »
day 16 been grriiiiiiinnnnding away since, well, day 16. Think I might have to stop it.  :-[

Day 16 part 2 a nice trick, very quickly realised the dynamic programming way of calculating the second half of the message but was stuck for ages on how to extend that to calculate the first half of the message...only just realised the method which is that
(click to show/hide)

Davef

Re: Advent of Code
« Reply #823 on: 30 December, 2019, 12:58:32 pm »
Thanks for drawing my attention to this. I have really enjoyed doing it. I wasted hours with a fault reading my puzzle inputs. a spurious line break overwrote the character at offset 2000.  It had no effect until day 21 and 25 when my intcode computers worked nearly perfectly ... but not quite.

Re: Advent of Code
« Reply #824 on: 30 December, 2019, 05:35:27 pm »
I plan on going back and uploading various versions of the code.
a) The hacked version I used just to complete the challenge (usually in perl but sometimes in C)
b) A cleaned up version of the above
c) A very clean version written in another language (C or maybe go)

I'll see if I can do this for 2015-2018 too although I may pick a different new language for each year (go and Rust are on my list)

(I have all 250 stars, be interesting to see the stats on how many people have done that. There were 362 people with 200 stars by April 2019: https://twitter.com/ericwastl/status/1116561274379259904 )
"Yes please" said Squirrel "biscuits are our favourite things."