Yet Another Cycling Forum

General Category => The Knowledge => Ctrl-Alt-Del => Topic started by: Afasoas on 10 December, 2015, 08:09:29 pm

Title: Advent of Code
Post by: Afasoas on 10 December, 2015, 08:09:29 pm
10 days late discovering this, but what a little gem it is.
A Christmas themed two-part puzzle to be solved in code for each day of advent.

http://adventofcode.com/

I've had a crack at day 1 and 2 in PowerShell.
https://github.com/biscuitNinja/AdventOfCode

You can do it in any language of your choice.
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2015, 09:57:02 pm

made a bit of a meal of that  ;)
https://github.com/bjtaylor1/AdventOfCode/blob/master/Day1.ps1
Title: Re: Advent of Code
Post by: David Martin on 10 December, 2015, 10:25:14 pm
Done days 1-3 so far. Straightforward if you read the instructions. I misread day 3 as 'more than 1 present'.

Title: Re: Advent of Code
Post by: David Martin on 10 December, 2015, 10:53:26 pm
4b is nasty. It is taking a while to bruteforce.
Title: Re: Advent of Code
Post by: Afasoas on 10 December, 2015, 10:58:04 pm
Ben T, if we were Golfing (https://en.wikipedia.org/wiki/Code_golf) you'd have beaten me on day 1 :)
I've just seen a version of Day 3 done as a one liner in PERL.

Day 4 looks interesting ... "AdventCoins"
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 12:10:36 am
What was the one liner? I'm fairly sure I can see how to do it but it is probably somewhat obfuscated.

4b is still running. Maybe I was unlucky.
Title: Re: Advent of Code
Post by: Afasoas on 11 December, 2015, 07:27:36 am
What was the one liner? I'm fairly sure I can see how to do it but it is probably somewhat obfuscated.

https://www.reddit.com/r/adventofcode/comments/3v8roh/day_3_solutions/cxmc1h2

4b is still running. Maybe I was unlucky.

Still crunching away with this too. It's only using 15% CPU .. I'm wondering if a parallel foreach might have been better...
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 08:50:30 am
What was the one liner? I'm fairly sure I can see how to do it but it is probably somewhat obfuscated.

https://www.reddit.com/r/adventofcode/comments/3v8roh/day_3_solutions/cxmc1h2

That's not really a one-liner. It's about as much as I wrote in Python.

Ready to have a crack at 7, the rest have been straightforward.
Title: Re: Advent of Code
Post by: Ben T on 11 December, 2015, 09:06:14 am
4b is nasty. It is taking a while to bruteforce.
Do you know for a fact that bruteforce is the only way?
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 10:18:21 am
It takes a very long time if you have a silly bug in your code :embarassed: Done.
Title: Re: Advent of Code
Post by: Pingu on 11 December, 2015, 10:56:52 am
Did 1a & 1b with javascript  :P
Title: Re: Advent of Code
Post by: Ben T on 11 December, 2015, 11:38:09 am
It appears day 3 can be solved  by munging a 2D space into a 1D one using prime numbers :)
https://github.com/bjtaylor1/AdventOfCode/blob/master/Day3.ps1
Title: Re: Advent of Code
Post by: red marley on 11 December, 2015, 11:55:24 am
For those of us who have come to this late (and thanks Afasoas for point to it), can specific approaches to the solutions be put in spoiler tags please?
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 12:15:58 pm
It appears day 3 can be solved  by munging a 2D space into a 1D one using prime numbers :)
https://github.com/bjtaylor1/AdventOfCode/blob/master/Day3.ps1

(click to show/hide)
Title: Re: Advent of Code
Post by: Mr Larrington on 11 December, 2015, 12:28:48 pm
I no longer have access to a VMS Fortran compiler so that's me stuffed ;D
Title: Re: Advent of Code
Post by: Pancho on 11 December, 2015, 12:31:40 pm
Quick - recommend me a programming language (and tools) that an old duffer can use!

A few years back (on another computer) I think I installed python (IIRC - could have been something else) and actually managed to get it to interact with Openstreetmap to draw a map with a particular bus route. IIRC, it was surprisingly easy.

Firstly, a really stupid question - how can I tell if I've already got python installed (Ubuntu is the operating sys and I've found "Terminal" gives me a Ye Olde terminal)?

VMT
Title: Re: Advent of Code
Post by: Ben T on 11 December, 2015, 12:42:08 pm
It appears day 3 can be solved  by munging a 2D space into a 1D one using prime numbers :)
https://github.com/bjtaylor1/AdventOfCode/blob/master/Day3.ps1

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Afasoas on 11 December, 2015, 12:44:26 pm
If you're using Windows, PowerShell is readily available. You could use Python, perl, ruby - the problem is choosing a language.
If you want an IDE you could try Microsoft's Code and then relevant plugin's for your language of choice.

The second link in the OP are my feeble attempts thus far.

Title: Re: Advent of Code
Post by: Pancho on 11 December, 2015, 12:56:54 pm
Quick - recommend me a programming language (and tools) that an old duffer can use!

A few years back (on another computer) I think I installed python (IIRC - could have been something else) and actually managed to get it to interact with Openstreetmap to draw a map with a particular bus route. IIRC, it was surprisingly easy.

Firstly, a really stupid question - how can I tell if I've already got python installed (Ubuntu is the operating sys and I've found "Terminal" gives me a Ye Olde terminal)?

VMT

Maybe it wasn't python. Maybe it was perl - I've found I've managed to get a perl manual up on this machine so I prob have it installed already!

Think I'll have a coffee and then set about learning how compiling and running works these days. Then I'll try and learn perl. Then I'll try and do December 1st.
Title: Re: Advent of Code
Post by: Afasoas on 11 December, 2015, 01:04:01 pm
Just running "python -V" will give you the version number.

Code: [Select]
user@cinelli ~ $ python -V
Python 2.7.6
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 01:35:12 pm

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 01:37:42 pm
Dec 1st is extremely simple and should be achievable after lesson 1 of a python course (if they start with string manipulation)
1b could be optimised if you think about how far away you are from where you want to be.
Title: Re: Advent of Code
Post by: red marley on 11 December, 2015, 02:56:45 pm
I like the fact that the second part of each day is not revealed until submitting an answer to the first. That way we are encouraged to think about solutions that might be a little more generalisable.

However for Day 3...
(click to show/hide)
Title: Re: Advent of Code
Post by: Pancho on 11 December, 2015, 03:25:03 pm
Well, I haven't even figured out how to bring a file in a character at a time yet!
Title: Re: Advent of Code
Post by: Ben T on 11 December, 2015, 03:27:09 pm
I like the fact that the second part of each day is not revealed until submitting an answer to the first. That way we are encouraged to think about solutions that might be a little more generalisable.

However for Day 3...
(click to show/hide)
Rule of agile: do as little work as possible. ;)

I didn't even know an extra  bit appeared.... but hardly any modification required however: https://github.com/bjtaylor1/AdventOfCode/blob/master/Day3b.ps1

Title: Re: Advent of Code
Post by: Ben T on 11 December, 2015, 03:34:28 pm

(click to show/hide)
(click to show/hide)

I agree ;) , but, is there not a condition you could place on the primes  to guarantee it?
My initial 'hunch' was that that condition would be
p1>n AND p2 > n
I have absolutely no idea how to prove that however.
Thinking about it however
would
p1 > p2  x n AND p2 > n
not guarantee it?
Again, no idea how to prove, just a hunch

Can you disprove it?
so if, say,  n = 10, I would choose primes 11 and 113...
i.e. 11 > 10 and 113 > 10* 11.
what moves (values of m1 and m2) would cause a hash collision i.e. such that
m1 * p1 = m2 * p2
where
m1 <= 10
m2 <= 10
p1 = 11
p2 = 113
?
How to prove there are no such values of m1 and m2?
If  I place  that condition do they even need to be prime?
Title: Re: Advent of Code
Post by: Afasoas on 11 December, 2015, 03:42:41 pm
Well, I haven't even figured out how to bring a file in a character at a time yet!
http://code.activestate.com/recipes/65118-processing-a-string-one-character-at-a-time/
Title: Re: Advent of Code
Post by: Pancho on 11 December, 2015, 04:48:09 pm
YES!!! YES!!! YES!!!

I've done Day 1! Learned about command line again. Learned about Linux commands. Found "perl", got it running. Tried, tried, and tried again.

And got this (the most shockingly skanky code ever written - but it works!):

(click to show/hide)
Title: Re: Advent of Code
Post by: Pancho on 11 December, 2015, 04:50:08 pm
Whoops.

It seems I've only done Part 1 of Day 1. Back to the grindstone.
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 05:09:14 pm
Invigilating a 3 hour exam allowed the time to get through days 7, 8 and 9.

7 was the hardest, 8 was tricky, 9 easy to bruteforce.

To solve 7:
(click to show/hide)

I may steal some of these for interview questions.
Title: Re: Advent of Code
Post by: Pingu on 11 December, 2015, 06:48:03 pm
Day 2 done in a spreadsheet  :demon:
Title: Re: Advent of Code
Post by: JonBuoy on 11 December, 2015, 07:11:18 pm
Part 1 of Day 1 done in a word processor   :demon:
Title: Re: Advent of Code
Post by: Pingu on 11 December, 2015, 07:22:24 pm
Day 3 done (javascript).
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 07:37:48 pm
Waiting for 10b to finish running.
Title: Re: Advent of Code
Post by: Pancho on 11 December, 2015, 08:33:06 pm
Still trying to work out how to do arrays.
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 10:34:50 pm
10b finished. I was pondering on how best to write the code for 11 but ended up solving both parts by inspection (and only one failed attempt out of 3)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 10:37:14 pm
Still trying to work out how to do arrays.
In perl? Clues to a solution included.
(click to show/hide)


Title: Re: Advent of Code
Post by: red marley on 11 December, 2015, 11:23:40 pm
4b is still running. Maybe I was unlucky.

Still crunching away with this too. It's only using 15% CPU .. I'm wondering if a parallel foreach might have been better...

Day 4 (MD5)
(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 11 December, 2015, 11:34:09 pm
Day 4 done. It helps when you search for the correct string. "000000" has six characters  :facepalm:
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 11:35:58 pm
4b is still running. Maybe I was unlucky.

Still crunching away with this too. It's only using 15% CPU .. I'm wondering if a parallel foreach might have been better...

Day 4 (MD5)
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2015, 11:36:45 pm
Day 4 done. It helps when you search for the correct string. "000000" has six characters  :facepalm:
You and me both..
Title: Re: Advent of Code
Post by: Oaky on 12 December, 2015, 12:35:33 am
Just started this today.  I did 1 and 2 (chose Python, mainly because I learnt it fairly recently, but it fell into disuse and I wanted to blow some cobwebs away).

Was particularly chuffed with (2) because the approach I took fro part a turned out to be trivially extensible for part b.  The meat of which is this:-

(click to show/hide)

the full code (including a few test cases) is here:-

(click to show/hide)
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 09:43:24 am
OK, I really didn't want to ask for help - but I'm really stumped. Still on Day 2 Part 1!

In my defence, I am learning everything on the job - from command line linux, use of editors, through to the actual language itself. Solving the problems, as you can see, are a long way down the line.

Anyway, I've done this (please excuse all the comments (I'd get lost without them) and the "print" diagnostics (don't have a debugger)):

(click to show/hide)

Everything seems to work except my calculation of the "slack" paper needed. The sort function works (well, now it does - apparently it doesn't sort numbers without that bit of extra code - took me a long time to work that out) and I take the two lowest and multiply them together - and get guff!

Maybe it's confusing text and numbers? But why does it work for the other instances of multiplication?

Baffled and stuck - help required!

VMT.
Title: Re: Advent of Code
Post by: red marley on 12 December, 2015, 09:56:13 am
Pancho, I don't know much about Perl so can't help you there, but here's a hint on the algorithm...

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2015, 10:07:00 am
The code seems to run for me (once the filename is changed) and seems to give a credible answer. It is going round the houses a long way, looping through the data twice.

Title: Re: Advent of Code
Post by: David Martin on 12 December, 2015, 10:14:42 am
Day 12 first part is trivial for a unix hacker. The second part means the quick solution to part A is not extensible but you have to have a proper parser.
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 10:21:01 am
Quote
The code seems to run for me (once the filename is changed) and seems to give a credible answer. It is going round the houses a long way, looping through the data twice.

The reason for going round the houses is simply because I have to test everything step by step as I've no idea how things (even loops) actually work. It took me a long time to work out how to load in data so I got that working first. Then I had to work out how to manipulate arrays - but didn't want to muck up the bit I'd got working!

Also, it feels tidier to do things in chunks. Set up some arrays. Load them from a file. Do stuff with them. If you mung all that together, it gets terribly confusing terribly rapidly (well, to an old codger like me).

I spent a long time down a dead-end route. Tried to set up a multi-dimensional array to hold everything but multi-dimensional arrays seemed to be unnecessarily complex so gave up. But I'd still rather have all the data for Parcel x held in ParcelData (ParcelID, Length, Width, Height, Area, Slack).

Anyway, if it broadly works for you, WTF does it tell me:

 (Parcel : 0   L: 3 W: 11 H: 24 A: 738 S: 33738) ?
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 10:37:31 am
And yet, when I sum up all the Slacks, it gives a believable answer?

Which turns out to be the correct answer.

Must be something to do with my diagnostic print statements. But I'm stuffed if I know what.

Anyway, on to Day 2, Part 2.
Title: Re: Advent of Code
Post by: Afasoas on 12 December, 2015, 11:48:15 am
Day 4 done. It helps when you search for the correct string. "000000" has six characters  :facepalm:
You and me both..

+1 .. :/
Title: Re: Advent of Code
Post by: Pingu on 12 December, 2015, 12:15:37 pm
Day 4 done. It helps when you search for the correct string. "000000" has six characters  :facepalm:
You and me both..

+1 .. :/

Is that some sort of regex?
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 12:28:51 pm
Day 3 has got me puzzling. There must be a quicker way of doing it than just moving around a virtual x and y grid. Something to do with summing up all the moves or something.

But it's beyond my brain to figure it out.

So, I'm sticking with trekking a counter around a virtual board. Which will take me long enough to actually programme - it's taken me this long to work out how to get hold of one character at a time.
Title: Re: Advent of Code
Post by: red marley on 12 December, 2015, 12:37:57 pm
Day 3 hint

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2015, 12:38:29 pm
Day 3. I think you have to remember where you have been.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 12 December, 2015, 01:31:24 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 01:50:03 pm
Cracked Day 3 Part 1:

(click to show/hide)

It works but I get shedloads of warnings about unitialised values. I've tried to stop that but failed.
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 01:51:48 pm
I'd deliberately not looked at the hints until now as I wasn't fully stuck.

I think I've sort of done what you describe - but differently.
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 02:11:14 pm
3b's in the bag - and I've done my first subroutines (santamove, and robomove!).
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 02:39:33 pm
I don't even understand the question for Day 4. Well, I do a bit - I vaguely remember some of the jargon.

I'll spend some time on google - that usually cures all ignorance.

But, at first glance, it's either stupidly difficult (write code to do MD5 hashing (whatever that is)) or just boring (keep chucking numbers into existing MD5 functions until you get one back with the appropriate number of zeroes. It's possible I've misunderstood!
Title: Re: Advent of Code
Post by: red marley on 12 December, 2015, 03:04:33 pm
MD5 hashing isn't that different in principle to what you did for Day 3. Hashing is just a transformation of some collection of data (e.g. the row and column representing Santa's location) into a single number known as a hash. The key to making the hashing transformation useful is that you want to be pretty sure that the same original data always gives the same hash, and that data collections that are different give different hashes.

The MD5 and other cryptographic hash transformations have the additional property that given the hash, you cannot easily retrieve the original data. It is now known how to break the MD5 hashing such that you can retrieve the original data, but for the purposes of this advent exercise, that's not necessary.

(click to show/hide)
Title: Re: Advent of Code
Post by: Afasoas on 12 December, 2015, 03:26:07 pm
Just catching up. Day 5 with some regular expressions.
A bit of regex solves anything :)

(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 12 December, 2015, 03:54:22 pm
Just catching up. Day 5 with some regular expressions.
A bit of regex solves anything :)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 12 December, 2015, 03:55:35 pm
Day 5 done.
Title: Re: Advent of Code
Post by: red marley on 12 December, 2015, 04:13:25 pm
I've set up a 'private leaderboard' for YACF if anyone wishes to join it. The access code is 48462-ea506236
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 04:26:22 pm
I've set up a 'private leaderboard' for YACF if anyone wishes to join it. The access code is 48462-ea506236

I think I must have hit the anon login option as I have the memorable moniker of "anonymous user #49001".
Title: Re: Advent of Code
Post by: red marley on 12 December, 2015, 04:43:20 pm
Should you wish, you can change this to whatever name you use for authenticating access to the Advent site through the 'settings' option.
Title: Re: Advent of Code
Post by: red marley on 12 December, 2015, 04:45:14 pm
Not necessary for completing the task, but as I like drawing pictures this is the pattern of lights for my version of Day 6 part b:

(http://staff.city.ac.uk/~jwo/acf/adventLights.jpg)
Title: Re: Advent of Code
Post by: Pancho on 12 December, 2015, 05:42:59 pm
I've got to out now so can't do any more this eve :(

Also tomorrow's out as I'm picking up my daughter from the airport after 4 months away from home :)
Title: Re: Advent of Code
Post by: Diver300 on 12 December, 2015, 06:46:30 pm
Days 1 - 3 solved using spreadsheets.

It's not efficient and the computer struggles to run the spreadsheets.
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2015, 10:48:12 pm
Days 1 - 3 solved using spreadsheets.

It's not efficient and the computer struggles to run the spreadsheets.
Tht sounds like masochism. Just becasue you can, doesn't mean you should. You may find Day 4 a bit hard to do on a spreadsheet.
Title: Re: Advent of Code
Post by: Kim on 12 December, 2015, 10:59:59 pm
I ended up simulating neural networks using speadsheets for my final year research project (because reasons).  I wouldn't recommend it, unless you specifically want to make Clippy cry, but it's amazing what you can abuse them for if you're sufficiently determined/desperate/masochistic.
Title: Re: Advent of Code
Post by: Diver300 on 13 December, 2015, 10:02:05 am
My reusability of code fell down flat.
Part 5a solved on a spreadsheet
Part 5b used javascipt

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 13 December, 2015, 10:15:33 am
Not necessary for completing the task, but as I like drawing pictures this is the pattern of lights for my version of Day 6 part b:

(http://staff.city.ac.uk/~jwo/acf/adventLights.jpg)

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 13 December, 2015, 10:19:25 am
(click to show/hide)

You could have, but I believe each dataset is unique to your ID, so it wouldn't have got you very far.
Title: Re: Advent of Code
Post by: Pingu on 13 December, 2015, 12:06:39 pm
I must be missing something obvious in 6a. It doesn't look that difficult, but I'm not getting the right answer. My code seems to work for small data sets, but fails for the full problem set.
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2015, 01:23:10 pm
I must be missing something obvious in 6a. It doesn't look that difficult, but I'm not getting the right answer. My code seems to work for small data sets, but fails for the full problem set.
Off by one error somewhere?

I reverted to building a 2D matrix in numpy

I couldn't readily work out an elegant way of solving 11, and by the time I had thought about how to solve it I already had by inspection.

..d
Title: Re: Advent of Code
Post by: Pingu on 13 December, 2015, 01:40:25 pm
I must be missing something obvious in 6a. It doesn't look that difficult, but I'm not getting the right answer. My code seems to work for small data sets, but fails for the full problem set.
Off by one error somewhere?

Maybe, but I can't see where.

Would someone who's done 6a like to try it with my data set and let me know what you get? Here's the set:

turn off 660,55 through 986,197
turn off 341,304 through 638,850
turn off 199,133 through 461,193
toggle 322,558 through 977,958
toggle 537,781 through 687,941
turn on 226,196 through 599,390
turn on 240,129 through 703,297
turn on 317,329 through 451,798
turn on 957,736 through 977,890
turn on 263,530 through 559,664
turn on 158,270 through 243,802
toggle 223,39 through 454,511
toggle 544,218 through 979,872
turn on 313,306 through 363,621
toggle 173,401 through 496,407
toggle 333,60 through 748,159
turn off 87,577 through 484,608
turn on 809,648 through 826,999
toggle 352,432 through 628,550
turn off 197,408 through 579,569
turn off 1,629 through 802,633
turn off 61,44 through 567,111
toggle 880,25 through 903,973
turn on 347,123 through 864,746
toggle 728,877 through 996,975
turn on 121,895 through 349,906
turn on 888,547 through 931,628
toggle 398,782 through 834,882
turn on 966,850 through 989,953
turn off 891,543 through 914,991
toggle 908,77 through 916,117
turn on 576,900 through 943,934
turn off 580,170 through 963,206
turn on 184,638 through 192,944
toggle 940,147 through 978,730
turn off 854,56 through 965,591
toggle 717,172 through 947,995
toggle 426,987 through 705,998
turn on 987,157 through 992,278
toggle 995,774 through 997,784
turn off 796,96 through 845,182
turn off 451,87 through 711,655
turn off 380,93 through 968,676
turn on 263,468 through 343,534
turn on 917,936 through 928,959
toggle 478,7 through 573,148
turn off 428,339 through 603,624
turn off 400,880 through 914,953
toggle 679,428 through 752,779
turn off 697,981 through 709,986
toggle 482,566 through 505,725
turn off 956,368 through 993,516
toggle 735,823 through 783,883
turn off 48,487 through 892,496
turn off 116,680 through 564,819
turn on 633,865 through 729,930
turn off 314,618 through 571,922
toggle 138,166 through 936,266
turn on 444,732 through 664,960
turn off 109,337 through 972,497
turn off 51,432 through 77,996
turn off 259,297 through 366,744
toggle 801,130 through 917,544
toggle 767,982 through 847,996
turn on 216,507 through 863,885
turn off 61,441 through 465,731
turn on 849,970 through 944,987
toggle 845,76 through 852,951
toggle 732,615 through 851,936
toggle 251,128 through 454,778
turn on 324,429 through 352,539
toggle 52,450 through 932,863
turn off 449,379 through 789,490
turn on 317,319 through 936,449
toggle 887,670 through 957,838
toggle 671,613 through 856,664
turn off 186,648 through 985,991
turn off 471,689 through 731,717
toggle 91,331 through 750,758
toggle 201,73 through 956,524
toggle 82,614 through 520,686
toggle 84,287 through 467,734
turn off 132,367 through 208,838
toggle 558,684 through 663,920
turn on 237,952 through 265,997
turn on 694,713 through 714,754
turn on 632,523 through 862,827
turn on 918,780 through 948,916
turn on 349,586 through 663,976
toggle 231,29 through 257,589
toggle 886,428 through 902,993
turn on 106,353 through 236,374
turn on 734,577 through 759,684
turn off 347,843 through 696,912
turn on 286,699 through 964,883
turn on 605,875 through 960,987
turn off 328,286 through 869,461
turn off 472,569 through 980,848
toggle 673,573 through 702,884
turn off 398,284 through 738,332
turn on 158,50 through 284,411
turn off 390,284 through 585,663
turn on 156,579 through 646,581
turn on 875,493 through 989,980
toggle 486,391 through 924,539
turn on 236,722 through 272,964
toggle 228,282 through 470,581
toggle 584,389 through 750,761
turn off 899,516 through 900,925
turn on 105,229 through 822,846
turn off 253,77 through 371,877
turn on 826,987 through 906,992
turn off 13,152 through 615,931
turn on 835,320 through 942,399
turn on 463,504 through 536,720
toggle 746,942 through 786,998
turn off 867,333 through 965,403
turn on 591,477 through 743,692
turn off 403,437 through 508,908
turn on 26,723 through 368,814
turn on 409,485 through 799,809
turn on 115,630 through 704,705
turn off 228,183 through 317,220
toggle 300,649 through 382,842
turn off 495,365 through 745,562
turn on 698,346 through 744,873
turn on 822,932 through 951,934
toggle 805,30 through 925,421
toggle 441,152 through 653,274
toggle 160,81 through 257,587
turn off 350,781 through 532,917
toggle 40,583 through 348,636
turn on 280,306 through 483,395
toggle 392,936 through 880,955
toggle 496,591 through 851,934
turn off 780,887 through 946,994
turn off 205,735 through 281,863
toggle 100,876 through 937,915
turn on 392,393 through 702,878
turn on 956,374 through 976,636
toggle 478,262 through 894,775
turn off 279,65 through 451,677
turn on 397,541 through 809,847
turn on 444,291 through 451,586
toggle 721,408 through 861,598
turn on 275,365 through 609,382
turn on 736,24 through 839,72
turn off 86,492 through 582,712
turn on 676,676 through 709,703
turn off 105,710 through 374,817
toggle 328,748 through 845,757
toggle 335,79 through 394,326
toggle 193,157 through 633,885
turn on 227,48 through 769,743
toggle 148,333 through 614,568
toggle 22,30 through 436,263
toggle 547,447 through 688,969
toggle 576,621 through 987,740
turn on 711,334 through 799,515
turn on 541,448 through 654,951
toggle 792,199 through 798,990
turn on 89,956 through 609,960
toggle 724,433 through 929,630
toggle 144,895 through 201,916
toggle 226,730 through 632,871
turn off 760,819 through 828,974
toggle 887,180 through 940,310
toggle 222,327 through 805,590
turn off 630,824 through 885,963
turn on 940,740 through 954,946
turn on 193,373 through 779,515
toggle 304,955 through 469,975
turn off 405,480 through 546,960
turn on 662,123 through 690,669
turn off 615,238 through 750,714
turn on 423,220 through 930,353
turn on 329,769 through 358,970
toggle 590,151 through 704,722
turn off 884,539 through 894,671
toggle 449,241 through 984,549
toggle 449,260 through 496,464
turn off 306,448 through 602,924
turn on 286,805 through 555,901
toggle 722,177 through 922,298
toggle 491,554 through 723,753
turn on 80,849 through 174,996
turn off 296,561 through 530,856
toggle 653,10 through 972,284
toggle 529,236 through 672,614
toggle 791,598 through 989,695
turn on 19,45 through 575,757
toggle 111,55 through 880,871
turn off 197,897 through 943,982
turn on 912,336 through 977,605
toggle 101,221 through 537,450
turn on 101,104 through 969,447
toggle 71,527 through 587,717
toggle 336,445 through 593,889
toggle 214,179 through 575,699
turn on 86,313 through 96,674
toggle 566,427 through 906,888
turn off 641,597 through 850,845
turn on 606,524 through 883,704
turn on 835,775 through 867,887
toggle 547,301 through 897,515
toggle 289,930 through 413,979
turn on 361,122 through 457,226
turn on 162,187 through 374,746
turn on 348,461 through 454,675
turn off 966,532 through 985,537
turn on 172,354 through 630,606
turn off 501,880 through 680,993
turn off 8,70 through 566,592
toggle 433,73 through 690,651
toggle 840,798 through 902,971
toggle 822,204 through 893,760
turn off 453,496 through 649,795
turn off 969,549 through 990,942
turn off 789,28 through 930,267
toggle 880,98 through 932,434
toggle 568,674 through 669,753
turn on 686,228 through 903,271
turn on 263,995 through 478,999
toggle 534,675 through 687,955
turn off 342,434 through 592,986
toggle 404,768 through 677,867
toggle 126,723 through 978,987
toggle 749,675 through 978,959
turn off 445,330 through 446,885
turn off 463,205 through 924,815
turn off 417,430 through 915,472
turn on 544,990 through 912,999
turn off 201,255 through 834,789
turn off 261,142 through 537,862
turn off 562,934 through 832,984
turn off 459,978 through 691,980
turn off 73,911 through 971,972
turn on 560,448 through 723,810
turn on 204,630 through 217,854
turn off 91,259 through 611,607
turn on 877,32 through 978,815
turn off 950,438 through 974,746
toggle 426,30 through 609,917
toggle 696,37 through 859,201
toggle 242,417 through 682,572
turn off 388,401 through 979,528
turn off 79,345 through 848,685
turn off 98,91 through 800,434
toggle 650,700 through 972,843
turn off 530,450 through 538,926
turn on 428,559 through 962,909
turn on 78,138 through 92,940
toggle 194,117 through 867,157
toggle 785,355 through 860,617
turn off 379,441 through 935,708
turn off 605,133 through 644,911
toggle 10,963 through 484,975
turn off 359,988 through 525,991
turn off 509,138 through 787,411
toggle 556,467 through 562,773
turn on 119,486 through 246,900
turn on 445,561 through 794,673
turn off 598,681 through 978,921
turn off 974,230 through 995,641
turn off 760,75 through 800,275
toggle 441,215 through 528,680
turn off 701,636 through 928,877
turn on 165,753 through 202,780
toggle 501,412 through 998,516
toggle 161,105 through 657,395
turn on 113,340 through 472,972
toggle 384,994 through 663,999
turn on 969,994 through 983,997
turn on 519,600 through 750,615
turn off 363,899 through 948,935
turn on 271,845 through 454,882
turn off 376,528 through 779,640
toggle 767,98 through 854,853
toggle 107,322 through 378,688
turn off 235,899 through 818,932
turn on 445,611 through 532,705
toggle 629,387 through 814,577
toggle 112,414 through 387,421
toggle 319,184 through 382,203
turn on 627,796 through 973,940
toggle 602,45 through 763,151
turn off 441,375 through 974,545
toggle 871,952 through 989,998
turn on 717,272 through 850,817
toggle 475,711 through 921,882
toggle 66,191 through 757,481
turn off 50,197 through 733,656
toggle 83,575 through 915,728
turn on 777,812 through 837,912
turn on 20,984 through 571,994
turn off 446,432 through 458,648
turn on 715,871 through 722,890
toggle 424,675 through 740,862
toggle 580,592 through 671,900
toggle 296,687 through 906,775
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2015, 01:44:06 pm
Sorry, I had a power failure and lost my scratch file with the code in.
Title: Re: Advent of Code
Post by: red marley on 13 December, 2015, 02:06:39 pm
Pingu, with your light instructions, I get 400410 left on.

Which looks like this:

(http://staff.city.ac.uk/~jwo/acf/adventLightsPingu.png)

and for part b, like this:

(http://staff.city.ac.uk/~jwo/acf/adventLights2Pingu.jpg)

(which clearly shows an image of Jesus imprinted on it, so you must have a very special set of instructions)
Title: Re: Advent of Code
Post by: red marley on 13 December, 2015, 04:50:12 pm
Waiting for 10b to finish running.

(click to show/hide)
Title: Re: Advent of Code
Post by: Pancho on 13 December, 2015, 04:59:44 pm
Waiting for 4b to spit out an answer. (4a turned out to be the trivially boring case).
Title: Re: Advent of Code
Post by: Pingu on 13 December, 2015, 05:39:35 pm
Pingu, with your light instructions, I get 400410 left on.

Thanks jo  :thumbsup:
Title: Re: Advent of Code
Post by: red marley on 13 December, 2015, 05:46:57 pm
Does that mean you spotted the reason why you were not getting the correct result? One of the difficult aspects of that particular challenge is that is a hard one to debug.
Title: Re: Advent of Code
Post by: Pingu on 13 December, 2015, 05:57:27 pm
It was thanks for trying my data with your solution  :)

I have found the reason why my code didn't work. It was because it extracted strings rather than numbers for the coordinates from the instructions  :facepalm: One day I will learn  ::-)

6a completed.
Title: Re: Advent of Code
Post by: Pingu on 13 December, 2015, 05:59:19 pm
(http://staff.city.ac.uk/~jwo/acf/adventLights2Pingu.jpg)

(which clearly shows an image of Jesus imprinted on it, so you must have a very special set of instructions)

I thought yours looked a bit like Bender.
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2015, 06:32:24 pm
Waiting for 10b to finish running.

(click to show/hide)
Python on an aging mac. It took a little while, probably my fault for writing stupidly inefficient code. (Couple of minutes? - didn't matter as I was half way through a rather tedious exam invigilation).
Title: Re: Advent of Code
Post by: Pingu on 13 December, 2015, 06:57:49 pm
It was thanks for trying my data with your solution  :)

I have found the reason why my code didn't work. It was because it extracted strings rather than numbers for the coordinates from the instructions  :facepalm: One day I will learn  ::-)

6a completed.

And so 6b took about 5 minutes.
Title: Re: Advent of Code
Post by: red marley on 13 December, 2015, 09:08:07 pm
I'm finding Day 12 (JSON parsing) rather frustrating.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2015, 09:35:05 pm
You could do it with a stream parser, though I tried it and my code didn't work so reverted to a json parser and a recursive tree walker function to do the addition.
Did you write code for 11? I started to think about how I would code it but had solved it by inspection before I worked out how I would code it.
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2015, 09:37:18 pm
Day 13
(click to show/hide)
Title: Re: Advent of Code
Post by: Afasoas on 13 December, 2015, 11:50:11 pm
Really excited by the number of people taking part. Unfortunately I've not had much weekend time to catch up.. 7 days behind  :-\
Title: Re: Advent of Code
Post by: tonycollinet on 14 December, 2015, 06:04:13 am
I've just done days one and two in a spreadsheet. Not gonna work for day 3.


So can anyone suggest a mac based easy to setup and use programming environment. I used to do C a long time ago. Not worried about (re)learning to code, but could do without the pain of learning a clunky environment.

Something with instant feedback would be good. Along the lines of

Print "Hello World"
Run
Hello World

Would be great :-)

Title: Re: Advent of Code
Post by: red marley on 14 December, 2015, 07:08:26 am
http://processing.org

It's based on Java, so shares a C like syntax, but with a lower barrier to entry. I've used it to answer the first 12 days' advent questions so far.

println("hello world!");

works straight out of the box.

Loading text files is easy (loadStrings()), as is conversion to character arrays (.toCharArray()) and regular expressions, all of which are helpful for the challenge.
Title: Re: Advent of Code
Post by: Pancho on 14 December, 2015, 09:02:19 am
@tonycollinet: from a background of non-coder scared of incomprehensible IDEs, I'm using perl that I found was already on my computer. I just use an ascii text editor to write code, save it, then use perl to compile and run. I think Macs have perl onboard by default. Type perl -v to find version.
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2015, 11:26:02 am
I completed day 7 last night.  It took me a lot longer than I'd anticipated.

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 14 December, 2015, 12:08:23 pm
Day 7

(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 14 December, 2015, 06:02:05 pm
I've skipped day 7* and done day 8.




*Javascript does the bitwise operations on 32-bit.
Title: Re: Advent of Code
Post by: red marley on 14 December, 2015, 06:21:19 pm
I've skipped day 7* and done day 8.

*Javascript does the bitwise operations on 32-bit.

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 14 December, 2015, 07:16:18 pm
processing.org seems to fit the bill

Thanks jo.

Will play after my trip to Germany.


(Thanks also Pancho for the perl suggestion.)
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2015, 07:42:59 pm
Did you write code for 11? I started to think about how I would code it but had solved it by inspection before I worked out how I would code it.

I can see the answer to my day 11, also by inspection.  I wrote code but it is still running, though, despite applying some optimisations:-

(click to show/hide)

as an aside, I've been using this as an excuse to start playing around in test-driven development using the Python unittest framework

Code: [Select]
class TestIt(unittest.TestCase):
    # Part 1 tests
       
    def test_01(self):
        self.assertEqual(incr('aa'), 'ab')
 
    def test_02(self):
        self.assertEqual(incr('az'), 'ba')
 
    def test_03(self):
        self.assertEqual(incr('zz'), 'aaa') # my own assumption - not mentioned in TEH RULZ

    def test_04(self):
        self.assertFalse(pwOK('hijklmmn'))

    def test_05(self):
        self.assertFalse(pwOK('abbceffg'))

    def test_06(self):
        self.assertFalse(pwOK('abbcegjk'))

    def test_07(self):
        self.assertTrue(pwOK('abcdffaa'))

    def test_08(self):
        self.assertTrue(pwOK('ghjaabcc'))

(I've hidden some tests as they give a clue to some of the stuff I mention in the spoiler above):-

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2015, 08:14:59 pm
Re: my Day 11 woes...

As an alternative to looking for optimisations,  I could always just fix the bug that had it spinning in a tight loop going nowhere  :facepalm:

runs in under a second now  ::-)

I am an idiot!
Title: Re: Advent of Code
Post by: red marley on 14 December, 2015, 11:14:57 pm
Finally found an answer to Day 12b (JSON parsing)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2015, 11:23:47 pm
processing.org seems to fit the bill

Thanks jo.

Will play after my trip to Germany.


(Thanks also Pancho for the perl suggestion.)
An alternative is the python Anaconda distribution and the Spyder IDE (which is what I have done most of mine in.)
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2015, 11:27:17 pm
Finally found an answer to Day 12b (JSON parsing)

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2015, 11:31:31 pm
Day 7

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2015, 12:12:05 am
yay! finally up to date (well, at least until the next puzzle is released at 5 a.m  ;D).
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2015, 12:22:53 am
Finally found an answer to Day 12b (JSON parsing)

(click to show/hide)
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 15 December, 2015, 02:36:29 am
Have just completed days 13 and 14, which seemed a bit easier than some of the earlier ones.

Day 13 (Table planning)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2015, 01:16:08 pm
Have just completed days 13 and 14, which seemed a bit easier than some of the earlier ones.

Day 13 (Table planning)

(click to show/hide)

I had a search for a more elegant way than my brute force approach but couldn't find a suitable one. My matrix math is not up to it and your graph theory is probably far better than mine.
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2015, 05:30:16 pm
Really not happy with my solution to day 15.
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 15 December, 2015, 05:57:44 pm
Day 15:

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2015, 06:06:48 pm
You are correct - I was doing it in a bit of a rush between invigilation and marking.. Only 300 more scripts to go before then end of term.
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2015, 09:13:00 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 15 December, 2015, 09:39:50 pm
Day 9a done eventually followed by 9b two minutes later.
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2015, 09:55:59 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 15 December, 2015, 10:28:35 pm
Day 10 done. What a contrast with day 9.
Title: Re: Advent of Code
Post by: red marley on 16 December, 2015, 08:40:07 am
Day 16

(click to show/hide)

According to Eric Wastl (the Advent of Code author), today was the last of the "easy" ones.
Title: Re: Advent of Code
Post by: Oaky on 16 December, 2015, 10:41:53 am
Day 16

(click to show/hide)

According to Eric Wastl (the Advent of Code author), today was the last of the "easy" ones.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 16 December, 2015, 09:33:34 pm
(click to show/hide)
Today was very easy. I dread tomorrow.
Title: Re: Advent of Code
Post by: red marley on 16 December, 2015, 10:05:37 pm
David, that's a more elegant approach than mine. My instinct tends towards 'grab all the data and structure it, then start processing'. I think this comes from my usual need to visualise data. But it makes much more sense in this context to follow your approach.

As with almost all of the puzzles so far, in practice the data volumes involved mean that inefficient storage or processing hungry algorithms can be tolerated. I suspect this will change from the 17th onwards.

I am trying to resist the temptation to come up with a speedy answer early in the morning to get posted on the leader board (mostly because I am not speedy enough). But I do wonder whether anyone is going to be spending an antisocial Christmas morning coding in order to make it to the head of the final leader board (I certainly won't be).
Title: Re: Advent of Code
Post by: David Martin on 16 December, 2015, 10:10:19 pm
Only if you can get up early enough :)

Your line of work is based around visualising all the data - a lot of mine is stream parsing and quality filtering. I took the view that filtering out what I didn't want and seeing what was left would be the easier option.

Anyhow, tomorrow will be a toss up between marking stats reports, planning next semester's course (don't ask why it is so late) and doing the Advent of Code.

Being less than elegant I hard-coded the parse rules.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2015, 08:07:35 am
Day 17 required some thought but very few lines of code.
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 17 December, 2015, 09:56:39 am
Day 17 required some thought but very few lines of code.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2015, 11:20:14 am
That was one option. I just happen to like recursion. It took a few seconds to ru, if that. (longer to write than to run).
Title: Re: Advent of Code
Post by: Feanor on 17 December, 2015, 11:32:34 am
Elegant as it is, you need to be careful with recursion because every time you re-enter a subroutine, the previous context is pushed onto the stack.

The stack will build and build as you recurse down, and only when (if!) you reach the bottom of the rabbit-hole and start returning do you begin to pop stuff off the stack.

So unless you know there's a limit on how deeply you will be recursing, you run a risk of stack overflow.
It's a fairly small risk with modern OSes, as the stack allocation is usually quite generous, but it is a limit to be aware of.
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2015, 11:49:56 am
In this case the recursion limit is the tree depth which is the length of the list. So not a problem. If it was an optimisation I'd have some convergence criteria.
Title: Re: Advent of Code
Post by: David Martin on 18 December, 2015, 07:49:13 am
Day 18, those blinking lights again.
I didn't use recursion. Fortunately my approach meant that part B required minimal extra coding
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 18 December, 2015, 10:29:12 am
Day 18, those blinking lights again.
I didn't use recursion. Fortunately my approach meant that part B required minimal extra coding
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 18 December, 2015, 10:12:41 pm
As Mr Wall says: TMTOWTDI
It was pleasantly easy. I was expecting something like 'if the bulb has been on for 10 iterations continuously it burns out and is permanently off'
Title: Re: Advent of Code
Post by: Oaky on 19 December, 2015, 12:28:33 am
Indeed,  the part 2 variation was less taxing than I expected.

I was doing a bit of self-searching about which days i found hardest so far, and from memory the hardest two were

1. day 8 (the string storage thing)
(click to show/hide)
2. day 7 (the circuit thing)
(click to show/hide)

In terms of raw amounts of code (stripping comments), they rank as follows:-

Code: [Select]
oaky@jarlsberg ~/Dropbox/AdventOfCode $ for i in */s*.py; do echo `grep -v '^[ ]*#' $i |  wc -l` $i;done | sort -n
22 1/s1.py
26 2/s2.py
32 4/s4.py
48 17/s17.py
51 8/s8b.py
55 10/s10.py
58 12/s12.py
62 8/s8.py
71 14/s14.py
77 16/s16.py
82 3/s3.py
91 15/s15.py
95 13/s13.py
99 9/s9.py
100 6/s6.py
104 11/s11.py
137 5/s5.py
150 18/s18.py
173 7/s7.py

although it's skewed somewhat since after the first couple of days I started using a unit test framework for varying levels of testing within the script itself (some of the lmid to ater ones were more than 50% test code).
Title: Re: Advent of Code
Post by: Oaky on 19 December, 2015, 12:31:45 am
from twitter earlier:-

Quote
Eric Wastl ‏@ericwastl 3h3 hours ago

If #AdventOfCode were a roller coaster, we're about to reach the corkscrews and loops and the part where it takes your picture.
Title: Re: Advent of Code
Post by: red marley on 19 December, 2015, 06:12:14 am
Today's is right up David Martin's street.

Part two feels like a proper workout for me at least. I'm impressed that the highest entry on the leaderboard managed both parts within 18 minutes of the puzzle being released.
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2015, 09:51:49 am
I've just done part one which was easy. I'm thinking about part 2.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 19 December, 2015, 12:04:45 pm
Took a couple of days off. Just finished day 11. The concept wasn't difficult, but it took me a while to sort out the letter incrementing business.
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2015, 04:18:13 pm
Well that doesn't work for day 19 as the time/space required is too big. This requires more thought.
Title: Re: Advent of Code
Post by: Pingu on 19 December, 2015, 07:20:57 pm
Finally found an answer to Day 12b (JSON parsing)

(click to show/hide)
(click to show/hide)

I'm on 12b now. It's a bit of a bastard. I've not opened the spoilers (yet).
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2015, 09:19:20 pm
I had a look at a spoiler for 19
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 20 December, 2015, 01:30:06 am
19b is eluding me for now, although I'm sure my BFI (brute force and ignorance) approach isn't the best.

I'm going to leave the BFI job running overnight, since it's not apparently consuming exponential memory, but in the morning, I am going to try a different approach:

(click to show/hide)

It may not help, but it beats abusing the company AWS account to do an expensive massively parallel brute force search ;)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2015, 11:10:47 am
I think your revised approach is by far the most sensible (which is why I started with that. Still haven't managed a suitable solution though I think I know how to find one.
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 20 December, 2015, 05:30:21 pm
Still working on an efficient way of reducing the search space for day 19b.

Day 20 is much easier...

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2015, 08:38:03 pm
I haven't had a chance to look at 20 as my laptop has decided to overheat and kill the graphics every hour or so.
(click to show/hide)
Title: Re: Advent of Code
Post by: Afasoas on 21 December, 2015, 09:23:39 am
I took a look at day 7 yesterday and found myself in a perpetual state of confusion.

I might try and take another look at it tonight.
Title: Re: Advent of Code
Post by: red marley on 21 December, 2015, 11:43:03 am
I now have a solution for 19b, Kicking myself I didn't get it earlier.

(click to show/hide)
Title: Re: Advent of Code
Post by: Afasoas on 21 December, 2015, 05:31:47 pm
For 7b, I found someone elses explanation of the problem and now I think I understand it.
I've also found out where the bitwise operators are in PowerShell*.


*I'm learning C and Ruby, I've a smattering of experience with Python, PHP and C#. But I'm nowhere near as proficient in those as I am with PowerShell. I figure if I find time to complete all the chellanges in PowerShell, I can try porting my solutions to other languages.
Title: Re: Advent of Code
Post by: David Martin on 21 December, 2015, 05:49:16 pm
Laptop was taken to laptop hospital and I really must finish my coursework marking before getting on with AoC.
Title: Re: Advent of Code
Post by: Afasoas on 21 December, 2015, 09:13:49 pm
Still stuck on day 7. I think my logic is sound.
I'm either hitting PowerShells limitations or I'm using it wrong.

Code: [Select]
[uint16]$foo = 1
[Uint16]$bar = $foo -shl 2
[Uint16]$car = $foo -shl 15
[Uint16]$har = $foo -shl 16
write-host "foo: $foo"
write-host "bar: $bar"
write-host "car: $car"
write-host "har: $har"

Output:
Code: [Select]
foo: 1
bar: 4
car: 32768
har: 0


On Edit: I'm being dufus. "shl" and "shr" are working as expected. ... **goes back, stares at code**
Title: Re: Advent of Code
Post by: Pingu on 22 December, 2015, 09:29:28 pm
Finally found an answer to Day 12b (JSON parsing)

(click to show/hide)
(click to show/hide)

I'm on 12b now. It's a bit of a bastard. I've not opened the spoilers (yet).

12b done at last (without spoilers)!  :thumbsup:
Title: Re: Advent of Code
Post by: Pingu on 23 December, 2015, 11:35:32 pm
Day 13 completed via a mix of Javascript and spreadsheet. Very much like day 9.
Title: Re: Advent of Code
Post by: Pickled Onion on 24 December, 2015, 06:30:48 pm
Yikes, made a bit of meal out of day 9, but quite happy with what I ended up with.
Title: Re: Advent of Code
Post by: Pickled Onion on 24 December, 2015, 07:47:17 pm
Quite pleased with this for day 10

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 25 December, 2015, 06:34:52 am
In 12b, does "red" after an object mean that the object is ignored?

e.g. { 1, 2, {3, 4} , red }

Should that be 7 or 0?
Title: Re: Advent of Code
Post by: Oaky on 25 December, 2015, 10:53:40 am
...

ETA: the spoiler below doesn't contain any info about the solution to the question, but does reveal something about part (b) of the question.

(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 25 December, 2015, 11:36:21 pm
Day 14 done.
Title: Re: Advent of Code
Post by: Pingu on 25 December, 2015, 11:43:06 pm
...

ETA: the spoiler below doesn't contain any info about the solution to the question, but does reveal something about part (b) of the question.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 26 December, 2015, 06:45:05 am
...

ETA: the spoiler below doesn't contain any info about the solution to the question, but does reveal something about part (b) of the question.

(click to show/hide)

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 26 December, 2015, 03:00:19 pm
...

ETA: the spoiler below doesn't contain any info about the solution to the question, but does reveal something about part (b) of the question.

(click to show/hide)

(click to show/hide)
(click to show/hide)

 :thumbsup:
Title: Re: Advent of Code
Post by: Pingu on 26 December, 2015, 03:26:46 pm
Day 15 done. Not too difficult compared with some of the previous.
Title: Re: Advent of Code
Post by: Pingu on 26 December, 2015, 05:39:22 pm
Day 16 done entirely by the dreaded spreadsheet.
Title: Re: Advent of Code
Post by: Pingu on 27 December, 2015, 12:38:51 am
Day 17 done with judicious googling*  :-X

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 27 December, 2015, 04:00:08 pm
Day 21 was one of the easier ones. But I did enjoy Day 22 because

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 27 December, 2015, 04:08:44 pm
Day 23. Another relatively easy one to compute but with a gotcha in part 2.

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 27 December, 2015, 04:18:09 pm
Day 24. Interesting.

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 27 December, 2015, 04:24:43 pm
Day 25. A nice finish to the challenge.

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 28 December, 2015, 01:11:06 pm
Day 19 - part 2.

(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 30 December, 2015, 12:31:01 pm
Day 18 done. Plodding on  :thumbsup:
Title: Re: Advent of Code
Post by: Pickled Onion on 02 January, 2016, 10:34:22 am
Day 22. What a wind-up. This is the only one where the examples don't give an expected result, just an example of the steps. So all my tests passed but the answer was wrong.

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 02 January, 2016, 10:45:21 am
Day 25. A nice finish to the challenge.

Thanks for posting this Afasoas, it was fun.

Slight quibble - advent calendars normally have 24 windows, don't they?

Now off to solve waste more time with http://www.gchq.gov.uk/press_and_media/news_and_features/Pages/Directors-Christmas-puzzle-2015.aspx
Title: Re: Advent of Code
Post by: Oaky on 05 January, 2016, 09:16:30 am
Day 22. What a wind-up. This is the only one where the examples don't give an expected result, just an example of the steps. So all my tests passed but the answer was wrong.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 05 January, 2016, 09:31:11 am
I think one of the consequences of the kind of problem you mention for Day 22 and many of the others in the challenge is how useful test driven development can be. I like the way the examples provide a gentle introduction to testing without ever mentioning unit tests and the like. I am considering how to incorporate these coding challenges into some of our undergraduate introductory programming teaching.

If anyone is feeling withdrawal symptoms with no more AoC, I recommend attempting the Synacor Challenge (https://challenge.synacor.com) also from Eric Wastl. It is immensely satisfying, very cleverly designed and rather challenging. But like the AoC, it leads you in gently so caters for a wide range of abilities. I'd also recommend not Googling for it as spoilers abound and one of the most satisfying elements of participating comes from what is revealed and the sense of achievement as you progress through the challenge.
Title: Re: Advent of Code
Post by: David Martin on 05 January, 2016, 10:01:22 am
I have to get back into it - haven't done any since the Mac died and Christmas took over.
Title: Re: Advent of Code
Post by: Oaky on 05 January, 2016, 10:17:03 am
(click to show/hide)

Title: Re: Advent of Code
Post by: red marley on 05 January, 2016, 11:26:41 am
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 11 January, 2016, 09:21:57 am
If anyone is feeling withdrawal symptoms with no more AoC, I recommend attempting the Synacor Challenge (https://challenge.synacor.com) also from Eric Wastl.

That thing is addictive.  I've got the first four codes now.

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 01 February, 2016, 04:06:22 pm
Some additional stats from Advent of Code have been published:  http://hexatlas.com/entries/8

I like this quote: "I expected 70 users or so, maybe. By Day 2, almost 10,000 were signed up, which caused quite a bit of panic on the server capacity end of things."
Title: Re: Advent of Code
Post by: Oaky on 22 November, 2016, 12:23:01 pm
Advent of Code 2016 is imminent!  :thumbsup:

Looks like jo's private leaderboard from last year carries over to 2016 too.
Title: Re: Advent of Code
Post by: David Martin on 22 November, 2016, 01:22:59 pm
Oooh.. must do better this year.
Title: Re: Advent of Code
Post by: red marley on 22 November, 2016, 02:52:49 pm
Advent of Code 2016 is imminent!  :thumbsup:

Looks like jo's private leaderboard from last year carries over to 2016 too.

In case it is not obvious to anyone new to the Advent of Code, the 'private leaderboard' allows you to view the number of completed challenge questions from YACF people who register. To join the board, simply enter the code 48462-ea506236 under 'leaderboard -> join private leaderboard'.

To enter the challenge at all you will need to log in to the site with one of the following credentials: twitter, Google, GitHub or Reddit. This is necessary as they are used to generate a (possibly) unique set of question variations and validation of your answers. No spamming is involved (as far as I am aware).

I'd really recommend the challenge to anyone with even a passing interest in coding. So far the challenges have been very well designed providing a manageable and satisfying learning curve over the 25 days. Whether you are a beginner wanting to develop skills in a new language (I'm going to attempt some in Elm (http://elm-lang.org) and possibly Racket (http://beautifulracket.com) this year) or are an expert programmer with a familiar language, there is something on offer.
Title: Re: Advent of Code
Post by: Oaky on 25 November, 2016, 11:57:08 am
from the Advent of Code author on Twitter:-

https://twitter.com/ericwastl/status/801715851510616064

 ;D
Title: Re: Advent of Code
Post by: red marley on 01 December, 2016, 11:56:51 am
I need to apologise as I have inadvertently given out the code for the YACF private leaderboard to colleagues at work (I thought I had generated a new code from a different account, but had passed the wrong one to colleagues). The upshot is that there may be a few others joining the YACF leaderboard this month. If that is a problem for anyone, now would be the time to start a new YACF one.
Title: Re: Advent of Code
Post by: David Martin on 01 December, 2016, 12:47:04 pm
I haven't done it yet but this is the approach I will take..

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 01 December, 2016, 01:03:54 pm
And then there is part 2
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 01 December, 2016, 03:18:20 pm
Both parts of day 1
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 01 December, 2016, 05:55:03 pm
Day 1: I did pretty much the same as David Martin. Quite similar to one of the problems last year.

Diver300 - Initially I though your quick solution to part b was rather elegant but...

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 01 December, 2016, 08:48:22 pm
Day 1: I did pretty much the same as David Martin. Quite similar to one of the problems last year.

Diver300 - Initially I though your quick solution to part b was rather elegant but...

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 01 December, 2016, 08:51:54 pm
Day 1: I did pretty much the same as David Martin. Quite similar to one of the problems last year.

Diver300 - Initially I though your quick solution to part b was rather elegant but...

(click to show/hide)
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: tom_e on 01 December, 2016, 09:08:36 pm
Well, that was a bit disappointing.  I'd recommended this to mrs_e on the basis it started off really gently in last year's problems and only gradually picked up in intensity.  This was straight in with an equivalent of day 3 (2015) but with an extra level of complexity due to rotations.
Title: Re: Advent of Code
Post by: red marley on 02 December, 2016, 07:45:57 am
I think Day 2 is easier so mrs_e may have more joy today.

Day 2, my solution

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 02 December, 2016, 08:39:42 am
Interesting. I took a slightly different approach, modelling the keypad more explicitly.
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 02 December, 2016, 08:56:50 am
(click to show/hide)
Title: Re: Advent of Code
Post by: tom_e on 02 December, 2016, 10:57:12 am
I think Day 2 is easier so mrs_e may have more joy today.

S'alright, she got there in the end with day 1 last night.  And while still in bed this morning she reported the same thing you have just said after reading day 2.  ;D
Title: Re: Advent of Code
Post by: David Martin on 02 December, 2016, 11:16:20 am
Gone back to day1 in R to force myself to think differently.
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 03 December, 2016, 07:35:46 am
Day 3 seemed simpler to me than either of the previous days.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 03 December, 2016, 10:35:19 am
Agreed. Still trying to do Day 1 part 2 in R. It's very good for row level manipulations but doing all against all is taxing me a bit. I might try embedding an SQL query in the R code (because one can).
Title: Re: Advent of Code
Post by: red marley on 03 December, 2016, 03:52:27 pm
Day 3

Because I like drawing pictures, I thought I'd create some festive visualisations of my Day 3 answers. Here's part (a) with each green triangle being a 'real' triangle with edge lengths as provided and impossible ones shown as three pronged branches with the given lengths.

(http://staff.city.ac.uk/~jwo/aoc/aoc2016day3a.jpg)

And here is part b with the vertically derived triangles added in red.

(http://staff.city.ac.uk/~jwo/aoc/aoc2016day3b.jpg)
Title: Re: Advent of Code
Post by: David Martin on 04 December, 2016, 08:55:47 am
A bit lengthier to solve today but not hard - bit of regex processing and understanding ascii. Had to look up how to do nested sorts in python as I'd not done that before, otherwise pretty straightforward.
Title: Re: Advent of Code
Post by: Diver300 on 04 December, 2016, 09:58:17 am
I used Javascript again today but kept falling over my own programming inability, but got there in the end.



Title: Re: Advent of Code
Post by: Pingu on 04 December, 2016, 12:09:31 pm
Late starter  ::-)

Day 1 done, a bit harder than expected.

(https://c7.staticflickr.com/6/5576/31041094230_17449958cf_z.jpg) (https://flic.kr/p/PhZHRQ)
AoC_day_01 (https://flic.kr/p/PhZHRQ) by The Pingus (https://www.flickr.com/photos/the_pingus/), on Flickr

Title: Re: Advent of Code
Post by: Pickled Onion on 04 December, 2016, 03:48:07 pm
A bit lengthier to solve today but not hard - bit of regex processing and understanding ascii. Had to look up how to do nested sorts in python as I'd not done that before, otherwise pretty straightforward.

It was good to practice sort functions, but the best I could come up with for the checksum was

(click to show/hide)

I'm sure there must be a way to create the hash anonymously on the fly, but it's eluding me.
Title: Re: Advent of Code
Post by: David Martin on 04 December, 2016, 04:32:48 pm
A bit lengthier to solve today but not hard - bit of regex processing and understanding ascii. Had to look up how to do nested sorts in python as I'd not done that before, otherwise pretty straightforward.

It was good to practice sort functions, but the best I could come up with for the checksum was

(click to show/hide)

I'm sure there must be a way to create the hash anonymously on the fly, but it's eluding me.
Title: Re: Advent of Code
Post by: Pickled Onion on 04 December, 2016, 05:05:52 pm
I see where you're going with that, but the wriggly problem is to keep track of the counts for each letter.

Looking forward to tomorrow's offering.
Title: Re: Advent of Code
Post by: David Martin on 04 December, 2016, 05:27:03 pm
I see where you're going with that, but the wriggly problem is to keep track of the counts for each letter.

Looking forward to tomorrow's offering.

It does that implicitly doesn't it? you are sorting on the letters and it is inefficient in that it runs the regex for every comparison. You don't need to keep track of the counts for each letter if they are readily recalculable.
Title: Re: Advent of Code
Post by: David Martin on 04 December, 2016, 06:55:46 pm
OK, there is no easy way to calculate the number of occurences of a substring in Perl so I had to craft a simple function for it.
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 05 December, 2016, 06:10:01 am
Day 5:

(click to show/hide)

I rather like the challenge to produce a HollywoodOS version of the password decryption. Might have to have a go at that. Now where are those beeps...
Title: Re: Advent of Code
Post by: David Martin on 05 December, 2016, 08:11:13 am
Took mine nearly half a minute. I did have a text console holywood version.. ish.
Title: Re: Advent of Code
Post by: Diver300 on 05 December, 2016, 11:02:34 pm
The server that I ran the .php file on took about 45 seconds to do the second half.
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 06 December, 2016, 07:13:45 am
From the creator of Advent of Code this morning...

Quote from: Eric Wastl
I hope everyone has been enjoying #AdventOfCode! Today ends the warmup puzzles. It's uphill from here!
Title: Re: Advent of Code
Post by: Oaky on 06 December, 2016, 07:57:03 am
From the creator of Advent of Code this morning...

Quote from: Eric Wastl
I hope everyone has been enjoying #AdventOfCode! Today ends the warmup puzzles. It's uphill from here!

I was just about to post that the first six days felt like "limbering up", and I had a feeling that the difficult stuff was about to start.
Title: Re: Advent of Code
Post by: David Martin on 06 December, 2016, 09:38:02 am
Today was straightforward. I have then worked out how to do it in R without loops. One line to read the data in and one very long line to generate the answer.
(click to show/hide)
Title: Re: Advent of Code
Post by: Tim Hall on 06 December, 2016, 01:18:59 pm
The Boy, last night, informed me he's cracked 1-4 and was working on 5.   
Title: Re: Advent of Code
Post by: Oaky on 06 December, 2016, 06:15:18 pm
Today was straightforward. I have then worked out how to do it in R without loops. One line to read the data in and one very long line to generate the answer.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 06 December, 2016, 06:25:59 pm
My colleague has commented how he has learned so much in the last few days. I have too, and will certainly look at the bear bones of the Pandas implementation. Python seems to be my 'goto' to start off with (typically with a few sanity checks, not really tests, along the way). Then I might try something else for fun like R or the Perl from previous. I've not really looked at Pandas - I should do. Numpy is as close as I have got.

Looking forward to something a bit more stretching tomorrow.
Title: Re: Advent of Code
Post by: Oaky on 06 December, 2016, 06:34:19 pm
I did consider trying this year in something other than Python, but to be honest, up until now, my day job hasn't involved enough opportunity for data munging for me to have fully assimilated Python yet, despite learning it several years back. 

That's changing right now as I start to spend time with another team in $EMPLOYER, and one of the tools of choice in that team is pandas (plus Jupyter notebooks) so I'm sticking to Python and also playing with the Jupyter/pandas approach on some of these this year.
Title: Re: Advent of Code
Post by: David Martin on 06 December, 2016, 10:09:48 pm
I like the Jupyter notebooks approach to problem solving as you document each step along the way (or should).
Title: Re: Advent of Code
Post by: red marley on 07 December, 2016, 06:35:28 am
Day 7: (ABBA internet protocols)

Do'h. Couldn't work out why I was getting the wrong answer for part a. Spent ages slowly debugging but could not find any problems with the logic of my code. Finally redownloaded the input text to find that my first attempt to download it had missed the last few lines.

Good challenge today though with plenty of scope for creating efficient pattern matching.
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2016, 10:15:25 am
i'm sure there is an efficient and elegant way to do it. Spent far too long trying to vectorise it in R with moderate amounts of nearly success then gave up and brute-forced it in python.

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 07 December, 2016, 10:22:52 am
i'm sure there is an efficient and elegant way to do it. Spent far too long trying to vectorise it in R with moderate amounts of nearly success then gave up and brute-forced it in python.

(click to show/hide)

Brute force here too...
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 07 December, 2016, 01:15:02 pm
Interesting approaches.

Regular expressions seemed the obvious approach...

(click to show/hide)
Title: Re: Advent of Code
Post by: R_nger on 07 December, 2016, 01:41:03 pm
I'm using node.js and tried to use regular expressions as far as possible. Difficulties today due to not reading the instructions properly 😳
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2016, 02:12:01 pm
Interesting approaches.

Regular expressions seemed the obvious approach...

(click to show/hide)

And I have just learned what a zero width look ahead assertion is. Strangely most of the pages on perl re don't cover that...
Title: Re: Advent of Code
Post by: Oaky on 07 December, 2016, 04:39:51 pm
checkout askalski's brute-force Perl regexp solutions over on the adventofcode subreddit (https://www.reddit.com/r/adventofcode/comments/5gy1f2/2016_day_7_solutions/)

And Eric Wastl's response:- ;)

Quote
[–]topaz2078(AoC creator) 13 points 10 hours ago

Did you do this just to make me cry? Because it worked.

 ;D
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2016, 04:43:46 pm
Did you look at Part 2 of that thread?
Title: Re: Advent of Code
Post by: Oaky on 07 December, 2016, 04:48:56 pm
Did you look at Part 2 of that thread?

His Part 2 solution?  Yep!
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2016, 05:06:15 pm
There is some pretty rank coding on display there..
Title: Re: Advent of Code
Post by: R_nger on 07 December, 2016, 05:21:50 pm
There is some pretty rank coding on display there..
yep, I'm glad I don't have to support some of that !  I'm not saying mine is pretty or elegant, but at least I'm not on a mission to minimise the line count (and ergo readability)!
Title: Re: Advent of Code
Post by: Ben T on 07 December, 2016, 05:46:37 pm
They put in a thing to deliberately confuse (some) regex parsing implementations, i.e.
zazbz
must match zaz and zbz.

not sure whether the challenge was to simply code in one that supports one match starting before another has ended?
or simply to realise that that is what was going on


https://github.com/bjtaylor1/AoC_2016
Title: Re: Advent of Code
Post by: red marley on 07 December, 2016, 06:23:45 pm
There is some pretty rank coding on display there..
yep, I'm glad I don't have to support some of that !  I'm not saying mine is pretty or elegant, but at least I'm not on a mission to minimise the line count (and ergo readability)!

Sure. Despite spending most of my career teaching people to prioritise clarity over brevity in programming, there is nevertheless something akin to magic when a 40 line block of procedural code can be replicated with

(click to show/hide)
(an answer to Day 7 pt b from Reddit)

There's lots of geeky humour on that reddit with people deliberately choosing difficult languages (Brainfuck anyone? (http://www.muppetlabs.com/~breadbox/bf/)) so I'd take the one line solutions in that spirit. I've been impressed with the K language (http://archive.vector.org.uk/art10010830) that some have been using. Seems to produce concise and efficient functional expressions  with a limited vocabulary for the kinds of list processing that has been the main feature of the challenges so far.
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2016, 09:11:21 am
Array index munging today. With a bit of input parsing thrown in.
Title: Re: Advent of Code
Post by: Oaky on 08 December, 2016, 12:13:24 pm
There is some pretty rank coding on display there..

It is deliberately perverse,  this guy has form for it.  I believe it was the same person who posted a solution for one day of last years AoC using a Synacor challenge VM.
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2016, 04:04:54 pm
I wasn't talking about the sheer brutality of the explicit regexs but some of the other code snippets that get posted.
Title: Re: Advent of Code
Post by: red marley on 08 December, 2016, 04:55:49 pm
One of the things I like about AoC is that it works with multiple levels of coding skill and experience and on multiple levels. I can use it with my first year computing students as well as get experienced computer science academic colleagues interested. Some solutions can be created with spreadsheets and even on paper, while others benefit from highly specialised languages. Inevitably there will be some pretty clumsy attempts being shared - but again, this is one of the rewarding educational aspects of the challenge, seeing how not to approach a problem as well as what works.
Title: Re: Advent of Code
Post by: Oaky on 08 December, 2016, 05:59:26 pm
I wasn't talking about the sheer brutality of the explicit regexs but some of the other code snippets that get posted.

Ahhh,  I understand now.

I saw one solution posted in which I could see a clear bug (that I knew to be a bug because I initially did the same myself, but it was smoked out of my code by the unit tests I'd written).  The author was fessing up to that bug (and another one) which individually would have got him the wrong answer, but coincidentally conspired to cancel out.
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2016, 08:05:10 am
Ah, definitely a step up. Part one done - straightforward once I remembered to
(click to show/hide)

Part 2 is readily tractable but just need to think a little bit further.
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2016, 08:09:15 am
My computer is busted, trying to solve them on a phone would be a challenge too far. I'll have to catch up at the weekend   
Title: Re: Advent of Code
Post by: red marley on 09 December, 2016, 09:02:00 am
Day 9 (decompression)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2016, 09:25:58 am
Day 9 (decompression)

(click to show/hide)
Title: Re: Advent of Code
Post by: tom_e on 09 December, 2016, 09:49:07 am
My computer is busted, trying to solve them on a phone would be a challenge too far. I'll have to catch up at the weekend

;D  I made the mistake of starting one on the phone because it looked pretty easy.  I did succeed, but it was quite painful.
Title: Re: Advent of Code
Post by: red marley on 09 December, 2016, 11:07:29 am
I fail to see how an infinite length string could be produced from finite input with that decompression method.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2016, 11:32:24 am
I fail to see how an infinite length string could be produced from finite input with that decompression method.

(click to show/hide)

OK, I see where you are going with that but you are wrong. given that a compressed string must be formed from an uncompressed string, and given the uncompressed string is [A-Z]+ the compressed string given in your example will never occur. I admit that an invalid string can break the algorithm, but a simple check that all processing instructions are complete (ie contain N characters after the instruction where the instruction is (NxY)) should suffice.
Title: Re: Advent of Code
Post by: red marley on 09 December, 2016, 11:49:30 am
I would agree if Eric Wastl was generating the potentially tens of thousands of compressed files used by this challenge by applying the compression algorithm to multi-gigabyte originals, that would be all you need to guarantee a 'good' compression sequence. But clearly, the scale of this means he will have been generating the compressed strings directly and algorithmically, and that was my point about his input generating challenge being a significant one.
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2016, 12:06:00 pm
But all you need to do is generate a string of valid commands from other valid commands. it is straightforward. You don't need to start with the uncompressed file.

Title: Re: Advent of Code
Post by: red marley on 09 December, 2016, 12:17:42 pm
I'm probably digging myself into a hole here by failing to understand the elegance of your suggested approach to input generation, but :

(5x2)ADVENT generates a valid (finite) uncompressed sequence. And (5xn) is in principle a valid compression command, where n is any integer. But (5xn) applied to that valid sequence renders it invalid. What would be a simple way of detecting such invalid modifications (other than the trivial case of always inserting a non-compression sequence of at least 5 characters after a compression command)?
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2016, 01:24:30 pm
You ensure that n is len(what follows the command) or greater.

So (5xn)ADVENT is fine but as (5xn)ADVENT is of length 10, the smallest thing that can be included is (10xn)(5xn)ADVENT. Anything less is invalid

So to generate the input you cna basically reverse the grammar definition


text := [Expansion]?[text][text]?

Expansion :=  (Zxlen{following text}) where Y is the length of the following [text] and Z >1

buildtext :
    text = null
    loop until break:
         text = text + random select:
             (random integer x length of)buildtext
             character in [A-Z]
            break
    return text

so text=buildtext will give you, for suitable random parameterisation, a valid compressed string.



Title: Re: Advent of Code
Post by: red marley on 10 December, 2016, 07:39:01 am
^---- Nice. (I think, but I've become distracted by the day 10 challenge)
Title: Re: Advent of Code
Post by: red marley on 10 December, 2016, 07:52:57 am
Day 10 (bot dancing)

The challenges are getting more interesting, and finally varying a little more from the pattern matching that has dominated the first week or so. With the possible exception of the first day, I think the difficulty curve over time is better than last year as it feels more of a steady increase in effort.

As for today...
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 10 December, 2016, 09:49:03 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2016, 12:26:06 am
And a dotified version of the solution to today's

(https://c4.staticflickr.com/1/135/31561265035_e5c8dd1f31_k.jpg) (https://flic.kr/p/Q5XJvZ)dotfile (https://flic.kr/p/Q5XJvZ) by David Martin (https://www.flickr.com/photos/davidmam/), on Flickr
Title: Re: Advent of Code
Post by: Diver300 on 11 December, 2016, 08:14:49 am
Is the order of applications of the bot rules important?

I got the first part, once some of the chips end up at outputs, I've got 14 bots, each holding one chip, and nothing further happens.

Any suggestions?
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2016, 08:36:57 am
Yes, you have to give the bots the inputs and they only transfer when they have both chips to compare. The graph is acyclic.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2016, 08:41:46 am

The first proper hard one today.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2016, 02:38:07 pm
There is a recursion depth issue. Still bruteforcing it. There may be a way to optimise the strategy but I haven't worked out how to do that yet. This is taking some time. maybe I should set a search order based on energy minimisation?

ETA: Part 1 done. Part 2 adds substantially and my approach may not be suitable. There has to be a smarter way of doing this but I don't see it.

As a measure of difficulty I should plot my leaderboard position against time. It might be quicker to do a binary search of the final answer, waiting a minute between each input than to calculate the answer using my 'crawl the whole net' approach.

ETA:
There is a smarter way.
(click to show/hide)

However, it still looks like a binary search on the correct answer is quicker than brute forcing it.
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2016, 04:58:27 pm
Brute force mostly won the day. Got to a position that was a maximum of 6 off but wasn't sure if it was optimal. It wasn't. Iterated back through the odd numbers till I got the right one. There is a one then five then ten minute delay between answer submissions..
Title: Re: Advent of Code
Post by: red marley on 11 December, 2016, 06:34:12 pm
Day 11 (elevator isotope exercises)

That was an exercise in humility for me. By far the toughest puzzle yet of 2016, but satisfying nonetheless.

Part 1:
(click to show/hide)

Part 2:
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2016, 07:37:32 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 11 December, 2016, 08:10:12 pm
A tiny modification that knocks the Day 11 part 2 solution down to less than 2 seconds computation time:

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2016, 08:23:30 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 12 December, 2016, 03:43:33 am
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 12 December, 2016, 06:05:56 am
Comment on BenT's Day 11 solution:
(click to show/hide)

As for Day 12 - some welcome relief (especially for anyone who did Day 23 last year (http://adventofcode.com/2015/day/23) or the excellent Synacor Challenge (https://challenge.synacor.com)) after spending too much of Sunday in front of the computer. I suspect today isn't the last we'll see of assembly language interpreting.
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2016, 06:52:29 am
Day 12 again can be optimised
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 12 December, 2016, 07:02:45 am
Day 12 (response to David Martin)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2016, 10:29:01 am
Day 12 (response to David Martin)

(click to show/hide)
But then you would be in 'how to write a compiler 101' territory rather than a short wee puzzle to solve.
Title: Re: Advent of Code
Post by: Ben T on 12 December, 2016, 01:24:13 pm
I wonder how difficult it would be to convert the instructions to actual assembly language? If there are equivalents that they would map to on a 1-1 basis.
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2016, 01:45:19 pm
And then set each register as a set of binary digits on a front panel display for an arduino for example?

Title: Re: Advent of Code
Post by: Ben T on 12 December, 2016, 02:39:02 pm
You can start a C++ program on a normal computer in seconds, and it can include an "asm { ... } " block IIRC. I'm sure one of the instructions is 'mov', which would be similar to their 'jnz', etc. So I was thinking merely output them to the console to then input into the adventofcode site...but if you know a better way knock yourself out :)
Title: Re: Advent of Code
Post by: Oaky on 12 December, 2016, 04:07:13 pm
I fell behind on account of running out of time on the train to work on Friday, and having a surfeit of Real Life stuffs at the weekend.  I've since mostly caught up, but I'm leaving Day 11 until tonight when I can have a proper think about it.  That one looks considerably more difficult than the others so far.
Title: Re: Advent of Code
Post by: Diver300 on 12 December, 2016, 06:57:36 pm
I converted day 12 into assembly language for a pic24, a 16 bit microcontroller. I ran the code on a simulator on a PC, and found that 32 bit resolution is needed, well more than 16 bits anyhow.

Line numbering went to pot, so I numbered the lines, and therefore the jumps, according to the original input.

Part 2 was then trivial, and took about 10 seconds to run. It would have been <1 second on a real microcontroller.
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2016, 08:29:57 am
Haven't attempted day 13 yet but I know the algorithm
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 13 December, 2016, 08:58:39 am
Or to put it another way (day 13)...

(click to show/hide)
Title: Re: Advent of Code
Post by: Tim Hall on 13 December, 2016, 09:22:20 am
The Boy was still stuck on 11 last night, but very pleased with his solution for 12.  He tried describing to me what he'd done, finishing off with "you don't understand this do you?"  I did manage to grasp he was pleased with the elegance of his solution though.
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2016, 11:02:12 am
A colleague of mine pointed me at a way to simplify day 13.
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 13 December, 2016, 11:16:48 am
(click to show/hide)


Title: Re: Advent of Code
Post by: red marley on 13 December, 2016, 11:26:00 am
In response to David's colleague's heuristic...

(click to show/hide)
Title: Re: Advent of Code
Post by: tom_e on 13 December, 2016, 08:16:57 pm
Managed day 12 with only pencil and paper.  ;D
Title: Re: Advent of Code
Post by: Oaky on 13 December, 2016, 08:28:54 pm
Managed day 12 with only pencil and paper.  ;D

I feel guilty if I manually encode the input data into my script rather than reading it from a file and parsing it.  ;)
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2016, 01:06:27 am
Code: [Select]
Finally got round to day 13. Easy enough for the first part, second part is giving me a little grief for a reason I cannot fathom.
I've plotted it and worked through by hand but the answer I get appears to be too low for the site. Having checked it exhaustively by hand, I am convinced there is a bug.
[spoiler]
Input is 1350, value I get is 115. This is too low
[/spoiler]

ETA. Read the instructions. The maze bounds are 0,0 not 1,1.
Doh!
[spoiler]
ETA - new answer 122, still wrong.

[code rows=40]#X##X##            ###     ##### ##### 
#X#XXX# ##  ######## # #####   #  ## ##
XX##XX## ## #  #   ### #     #     ## ##
#XX#X# ## #    ##   #  # #### ####   # 
#XX#X## ####### # # #### ## ###   ## # 
##X#XXX#  #    ## #   #    #    #  # # #
##XXX#X#  # ##    #   ## #  #### #   # 
# ##XXX# ## #### ####  ## # #  ## ##  ##
#####XX#     ###  # #   #   #   ###### 
  ####X###      #  #### ## ### #  ## ###
#  ###X##### ##### ## ## #  ##  #   #   
##  #XXXX#X###  ##   # #  # # #  ##   ##
    #XX#XXXXX#     #  ##### #  # # #####
## #### ####X#  ##### ##  # ###  ###  ##
## #XX###XXXX## #  ##  #  ### ###   #  #
#  ##XXXXX##X##      # # #  #     #  # 
### #X######X##### #  ## #  # ###  #   #
XXX##X##  #XXXXXX## #    # ##   ### ####
X#XXXXXX# #XX##X# #  ##  #   ###  # #  #
XX##XX#X# #####X# ############ ####     
## ##XXX###  #XX##    #  #    #  ##### #
 #  ##X#     #X# ####    # ##        ##
######X# ##  #XX#XX####### ##### ## # ##
##XXX#X##### ##XXXXXX#  #   #  #### ## #
 #X#XXXXXX## # ##XX#XX# ##  # #        #
 ## #####X#  ## ### #X#  # ## # ##  ## #
  # #  ##X### ##  ##XX# ##    ## ##### #
  #     ##   # ##  # ##   ## # ##   #   
######    ## ## # ## # ### # ## #   #  #
     #  #  #   ## #  ### # #   ### ####
 ##  ### #   #    #     ##  ##  ## #  #
#####  ## ##  ## ###### # #   # #  #  #

Sorted: There was a hidden sidestep that added two to the path length.
[/spoiler]
Title: Re: Advent of Code
Post by: red marley on 14 December, 2016, 06:34:13 am
Day 14 Hash-mash

People who liked Day 5 will love Day 14.

Hint:
(click to show/hide)


I like to start each day by making at least one stupid mistake before breakfast. Today's was

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2016, 07:30:22 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2016, 09:17:11 am
For Diver300:
(click to show/hide)

For Jo:
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2016, 09:31:03 am

(click to show/hide)

I did that one too.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 14 December, 2016, 09:49:08 am
Day 14....
Hint:
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2016, 10:05:47 am
Day 14....
Hint:
(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 14 December, 2016, 11:27:33 am
Day 14 continued...

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2016, 03:44:26 pm
Day 14

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2016, 04:03:15 pm
Day 14

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2016, 04:32:31 pm
Managed day 12 with only pencil and paper.  ;D
I've just belatedly solved day 11 similarly.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2016, 04:33:57 pm
Mine sounds very much like Oaky's using a dict of arrays to store candidate indices which can then be reviewed if pentuples are found.
Title: Re: Advent of Code
Post by: tom_e on 14 December, 2016, 05:04:32 pm
Managed day 12 with only pencil and paper.  ;D
I've just belatedly solved day 11 similarly.

It's an interesting question - I have some sympathy for Oaky's point of view above.  Any question where the input is quite small is potentially vulnerable to a more pure mathematical approach.  Particularly something like day 11 where the answer is relatively small and you get more than one attempt.

In this case, I'd argue you've crossed that fine line to guessing.  But since I am myself putting the first answer produced by code into the box and only going back to check for bugs if it fails (and suspect I am not alone in this), I'm not sure how clear-cut the "guessing is cheating" argument is.

Also, note (https://www.reddit.com/r/adventofcode/comments/5hoia9/2016_day_11_solutions/db1v1gk/).
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2016, 06:01:23 pm
Managed day 12 with only pencil and paper.  ;D
I've just belatedly solved day 11 similarly.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2016, 06:13:20 pm
Managed day 12 with only pencil and paper.  ;D
I've just belatedly solved day 11 similarly.
(click to show/hide)

(click to show/hide)

I agree.

I am not arguing that my solution is in any way robust. The example that you give is intentionally awkward, and I think that the puzzle always starts with the elevator on the ground floor, and it has to be soluble, so I don't think that real puzzles can be quite as awkward as yours, but I am sure there are some that have to start with less efficient moves.

I suspect that once the initial awkwardness is sorted, the  bulk of a solution is perfectly efficient, but I haven't proved it.

We shall see if later puzzles leave me lost due to my lack of rigor in day 11
Title: Re: Advent of Code
Post by: Oaky on 14 December, 2016, 06:38:53 pm
Managed day 12 with only pencil and paper.  ;D
I've just belatedly solved day 11 similarly.
(click to show/hide)

(click to show/hide)

I agree.

I am not arguing that my solution is in any way robust. The example that you give is intentionally awkward, and I think that the puzzle always starts with the elevator on the ground floor, and it has to be soluble, so I don't think that real puzzles can be quite as awkward as yours, but I am sure there are some that have to start with less efficient moves.

I suspect that once the initial awkwardness is sorted, the  bulk of a solution is perfectly efficient, but I haven't proved it.

We shall see if later puzzles leave me lost due to my lack of rigor in day 11

 ;D

BTW - I gather that the position I quoted (from p_tseng's reddit post), is a subset of a position that occurs during the optimal solution of an actual input that somebody was given.

Title: Re: Advent of Code
Post by: red marley on 14 December, 2016, 11:25:15 pm
Day 14 speed of calculation.

Given the various ways of finding a solution seemed to result in quite different times taken to calculate, I thought I'd have a look at where the bottleneck was when using Java.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2016, 07:43:07 am
(click to show/hide)

Day 15:
Straightforward.
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 15 December, 2016, 08:02:48 am
Why do you need to convert to lower case? It isn't material to the problem.

Because...

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 15 December, 2016, 09:02:38 am
Day 15:
Straightforward.
(click to show/hide)
(click to show/hide)
As is often the case, part 1 could be solved by brute force, but the seemingly small addition of part 2 made brute force impractical so thinking was needed. My first solution to part 2 depended on the brute force solution to part 1, which made me realise that a far faster and more elegant solution was possible to part 1.

Title: Re: Advent of Code
Post by: David Martin on 15 December, 2016, 09:31:39 am
Smartish brute force.. in my case, though it should be possible to describe the equation analytically.
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2016, 09:42:58 am
Dumb brute force for both parts (Python 2).

Part 1 runs in ~0.6 sec and Part 2 in ~2.1 sec.

I had a feeling when I set it away using the same brute force that part 2 was going to take too long that way and that I'd have to go back and recode it to be smarter, and was surprised when that wasn't the case.

I did go back and apply a couple of optimisations to my discStack class:-

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 15 December, 2016, 09:56:17 am
Day 15 really easy. No optimizations even remotely necessary. Both parts run instantaneously
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 15 December, 2016, 10:48:44 am
Day 15 one liner
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2016, 11:29:21 pm
After day 15's relatively easy problem, what's the betting day 16 is going to be a stinker?
Title: Re: Advent of Code
Post by: Oaky on 16 December, 2016, 05:48:51 am
After day 15's relatively easy problem, what's the betting day 16 is going to be a stinker?

Apparently not.

(click to show/hide)

What am I going to do with the rest of my morning?  Might have to do some work! ;D
Title: Re: Advent of Code
Post by: red marley on 16 December, 2016, 06:14:26 am
I didn't really dig today's (Day 16). Just grinding though some standard string manipulation, which is more or less tedious depending on your language of choice.

Yesterday's was more interesting because of there was plenty of scope for optimisation and was good practice for taking a functional approach (and unlike Day 11, could be done before breakfast).
Title: Re: Advent of Code
Post by: Diver300 on 16 December, 2016, 06:17:09 am
After day 15's relatively easy problem, what's the betting day 16 is going to be a stinker?

Apparently not.

(click to show/hide)

What am I going to do with the rest of my morning?  Might have to do some work! ;D
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 16 December, 2016, 06:25:35 am
After day 15's relatively easy problem, what's the betting day 16 is going to be a stinker?

So, day 16 was another easy one.  After this much respite, I'm getting anxious about what Mr Wastl has in store for us next.

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 16 December, 2016, 06:59:13 am
Quite sensibly, our toughest one this year (Day 11) was at the weekend. Last year, arguably the toughest one was Day 19 (molecules), also at the weekend. So perhaps we should brace ourselves for a toughie either tomorrow or the day after. I'm sure he wouldn't be so cruel as to set a time consuming challenge the following weekend given we may have other commitments on Sunday morning.
Title: Re: Advent of Code
Post by: Ben T on 16 December, 2016, 09:48:24 am
Recently went back and did Day 24 of last year and thought that was pretty hard (partitioning).
https://github.com/bjtaylor1/AoC_2015/blob/master/Day24/UnitTest1.cs
Title: Re: Advent of Code
Post by: Oaky on 16 December, 2016, 10:20:42 am
for 2015, day 19 part 2 was the absolute hardest IMO.
Title: Re: Advent of Code
Post by: David Martin on 16 December, 2016, 10:44:12 am
Looking at todays (Just got to it, running part 2), it flips the checksum (almost) with each doubling, so the checksum may be calculable from the starting code without needing to calculate the entire string.

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 16 December, 2016, 12:28:16 pm
for 2015, day 19 part 2 was the absolute hardest IMO.

That's where I got stuck. This year I've skipped a second part. Maybe I should go back and look at the 2015 ones
Title: Re: Advent of Code
Post by: red marley on 16 December, 2016, 02:21:09 pm
I didn't really dig today's (Day 16). Just grinding though some standard string manipulation, which is more or less tedious depending on your language of choice.

I was wrong about this. Looking elsewhere (no links here to avoid obvious spoilers), there are some really elegant ways of processing the input that stop this being such an iterative task. If anyone's feeling like they've done too much proper work today, there's plenty of scope for thinking about some nifty optimisations. I should never have doubted Mr Wastl. What makes these challenges great is their hidden depths.
Title: Re: Advent of Code
Post by: Ben T on 16 December, 2016, 04:16:35 pm
I didn't really dig today's (Day 16). Just grinding though some standard string manipulation, which is more or less tedious depending on your language of choice.

I was wrong about this. Looking elsewhere (no links here to avoid obvious spoilers), there are some really elegant ways of processing the input that stop this being such an iterative task. If anyone's feeling like they've done too much proper work today, there's plenty of scope for thinking about some nifty optimisations. I should never have doubted Mr Wastl. What makes these challenges great is their hidden depths.

That's fine, although my viewpoint would be that if iteration works fast enough then any further optimisation is straying from science into art :)
I was hoping he was going to say that the memory would be something like many GB, not 272.

for 2015, day 19 part 2 was the absolute hardest IMO.

That's where I got stuck. This year I've skipped a second part. Maybe I should go back and look at the 2015 ones

Having done 2016 day 11, 2015 day 19 part 2 wasn't that hard as it's a similar principle:
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 16 December, 2016, 07:28:37 pm
I didn't really dig today's (Day 16). Just grinding though some standard string manipulation, which is more or less tedious depending on your language of choice.

I was wrong about this. Looking elsewhere (no links here to avoid obvious spoilers), there are some really elegant ways of processing the input that stop this being such an iterative task. If anyone's feeling like they've done too much proper work today, there's plenty of scope for thinking about some nifty optimisations. I should never have doubted Mr Wastl. What makes these challenges great is their hidden depths.

That's fine, although my viewpoint would be that if iteration works fast enough then any further optimisation is straying from science into art :)
I was hoping he was going to say that the memory would be something like many GB, not 272.

for 2015, day 19 part 2 was the absolute hardest IMO.

That's where I got stuck. This year I've skipped a second part. Maybe I should go back and look at the 2015 ones

Having done 2016 day 11, 2015 day 19 part 2 wasn't that hard as it's a similar principle:
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2016, 08:29:22 am
And day 17 appears. I may have to think a little.
Title: Re: Advent of Code
Post by: Oaky on 17 December, 2016, 04:45:22 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2016, 06:28:31 pm
Finally got round to part 1. Part 2 is running, hopefully without an infinite loop.

ETA: hopes were in vain but infinity was removed and results obtained.
Title: Re: Advent of Code
Post by: Ben T on 17 December, 2016, 07:02:33 pm
On Day 17 part 2,
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 17 December, 2016, 07:19:15 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2016, 08:02:45 pm
(click to show/hide)
 
Title: Re: Advent of Code
Post by: red marley on 17 December, 2016, 08:40:15 pm
I thought I'd do a bit of analysis of challenge difficulty (http://gicentre.net/aoctimes), as measured by leaderboard completion time, to see what we have in store for the rest of 2016 (my guess: a toughie tomorrow and a more challenging final week)
Title: Re: Advent of Code
Post by: Ben T on 18 December, 2016, 12:08:36 am
The times (and thus points) are definitely skewed though because it makes no observation of when you started it.
Did someone finish it early because they're better at coding or just because they could be bothered to get up early...
For instance, I have to be at my desk in the week, so usually start it at 9 am, but didn't even look at today's till at least 4pm.
Title: Re: Advent of Code
Post by: red marley on 18 December, 2016, 05:58:15 am
Except that the leaderboard from which those stats were derived is only the first 100 finishers. Looking at the reddit discussions it is clear that all those who feature in the top 100 will have started the second the day's puzzle was released (with the exception of day 1, 2015 which I excluded).
Title: Re: Advent of Code
Post by: red marley on 18 December, 2016, 07:02:52 am
Day 18 (trapped tiles)

(click to show/hide)

(Edited to provide a more seasonal image of the tile layout [and a design for some rather natty Christmas underpants])
Title: Re: Advent of Code
Post by: David Martin on 18 December, 2016, 07:52:39 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 18 December, 2016, 11:00:28 am
I've just caught up with day 17. Reading the question fully would have save some time.
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 18 December, 2016, 11:01:47 am
Did you manage to skip any rows, i.e. avoid having to do every single 400,000 transformations, or doesit just improve the speed at which you can generate each row from the next.
I thought if it repeated at, say, 100,000, then you could simply multiply the result at that point by 4. But it doesn't.

The ones I really like are where an optimization is essential rather than just pretty.
Title: Re: Advent of Code
Post by: red marley on 18 December, 2016, 02:23:00 pm
Did you manage to skip any rows, i.e. avoid having to do every single 400,000 transformations, or doesit just improve the speed at which you can generate each row from the next.

(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 19 December, 2016, 08:11:45 am
Day 19 (present nabbing)

Great problem today. I like it because it can be tackled from several different angles (with varying degrees of efficiency). A little more challenging in part because if you calculate the wrong result it is not immediately obvious why, so debugging can be more difficult (DAMHIKT).
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2016, 08:17:37 am
Actualy part 1 is analytic

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2016, 09:12:23 am
As is part 2 but slightly different as it is not continuous as a quick simulation of the first 45 parties shows (from 5-99 elves)
(click to show/hide)


Very pleased to have solved it elegantly without needing to brute force it.
Title: Re: Advent of Code
Post by: Ben T on 19 December, 2016, 10:51:12 am
day 19 part 1:
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 19 December, 2016, 01:10:50 pm
day 19 part 2:
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 19 December, 2016, 05:53:25 pm
generic iterator template for branch style problems
https://github.com/bjtaylor1/AoC_2016/blob/master/puzzle_iterator.h
used in day 17: https://github.com/bjtaylor1/AoC_2016/blob/master/Day17b/Day17b.cpp
part 2 runs in sub-10s in release mode with /Ox.

also works for 2015 day 19 1+2.

Title: Re: Advent of Code
Post by: Oaky on 19 December, 2016, 07:26:42 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2016, 07:28:37 am
That wasn't particularly challenging - or maybe I am missing something
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 20 December, 2016, 08:07:50 am
I agree.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2016, 10:52:35 am
(click to show/hide)
Title: Re: Advent of Code
Post by: tom_e on 20 December, 2016, 11:11:00 am
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 20 December, 2016, 01:07:19 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 20 December, 2016, 01:21:04 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 20 December, 2016, 06:41:00 pm
That wasn't particularly challenging - or maybe I am missing something
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2016, 10:19:38 pm
I was looking at the problem and thinking that it maps onto a typical biological problem 'which parts of my gene have no sequence coverage?'

I'm not sure there is a specific tool for that - I'd probably write a similar script +/- the parsing of appropriate formats.
Title: Re: Advent of Code
Post by: Ben T on 21 December, 2016, 12:37:24 pm
Day 21 relies on realising the fact that
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 21 December, 2016, 12:49:58 pm
Not done it yet. Broadband outage at home so I have sneaked into the office to get it onto the PC. Will look at it tonight, but it doesn't seem so hard.
Not looked at the spoilers either.
Title: Re: Advent of Code
Post by: R_nger on 21 December, 2016, 01:29:39 pm
What's happening to Jo"s leader board ? Some mischievous anonymous user(s) having fun ?
Title: Re: Advent of Code
Post by: tom_e on 21 December, 2016, 01:41:52 pm
 ::-)  <tries to look innocent and not childish>
Title: Re: Advent of Code
Post by: R_nger on 21 December, 2016, 01:53:17 pm
::-)  <tries to look innocent and not childish>
LOL... I just popped over to the CDC thread...and you've beaten me to it !!
Title: Re: Advent of Code
Post by: red marley on 21 December, 2016, 02:33:50 pm
Anonymous user 107436 needs to get their act together and get a nice silver star for Day 14.
Title: Re: Advent of Code
Post by: tom_e on 21 December, 2016, 02:46:36 pm
Yeah, I couldn't decide about that pixel.  A spurt would take too many rows, and I'm already norty flagged on github now.

Just for you, jo.
Title: Re: Advent of Code
Post by: red marley on 21 December, 2016, 03:12:54 pm
Day 21 relies on realising the fact that
(click to show/hide)

Or

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 21 December, 2016, 04:41:06 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 21 December, 2016, 05:37:49 pm
Day 21 relies on realising the fact that
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 21 December, 2016, 09:02:49 pm
Day 21 relies on realising the fact that
(click to show/hide)

(click to show/hide)
From 5 onwards your rotation is wrong. 

Sent from my SM-G920F using Tapatalk

Title: Re: Advent of Code
Post by: David Martin on 21 December, 2016, 11:57:50 pm
Ok, guilty of not reading the instructions. Fortunately I could grab the data at work today but have to enter the answers with the phone as I currently have no broadband. So slightly delayed but now there.

Sent from my SM-G920F using Tapatalk

Title: Re: Advent of Code
Post by: red marley on 22 December, 2016, 08:05:02 am
Day 22 (grid computing)

Nice meaty challenge today. First part straightforward but I have to go to work now before getting a solution for second part. Will think about it on way in.
Title: Re: Advent of Code
Post by: David Martin on 22 December, 2016, 09:01:14 am
Likewise. Part 1 was straightforward, almost a one-liner in python.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 22 December, 2016, 01:09:41 pm
Part 2: Not much coding needed here - easy to do by inspection and simple arithmetic.
(click to show/hide)

Title: Re: Advent of Code
Post by: Oaky on 22 December, 2016, 04:30:13 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 22 December, 2016, 04:39:29 pm
^--- Probably a bit of an unhidden spoiler there David.


(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 22 December, 2016, 09:27:11 pm
I am attempting to fill in the blanks from last years. The lack of a daily deadline doesn't seem to help.

I do think that many of them are harder than this year. The one I am currently toying with is the elves delivering presents. It is obviously some heinous factorial problem, but instead of a straight sum of factors, it is a sum of the product of every permutation.
Wondering about some sort of branch and bound strategy, and being able to set a suitable bound on the number of primes to consider.

Title: Re: Advent of Code
Post by: red marley on 22 December, 2016, 10:26:36 pm
I do think that many of them are harder than this year.

We've still got three days to go yet.  :demon:

But I agree with you. The average completion time of the top 100 finishers last year was 26 min 50s; this year so far it has been 23 min 25s. One difference (which I like) is that the hardest questions this year (Day 11 lifts; Day 19 elf present stealing; Day 22 grid computing) have all had a trick/heuristic that makes the problem considerably easier to solve.

If you want a gentle clue for the present permutation problem from last year:
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 23 December, 2016, 06:42:15 am
Day 23  (more assembunny)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2016, 08:59:40 am
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 23 December, 2016, 02:56:14 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2016, 04:58:40 pm
Did you put that into the program to generalise from any set of instructions? I had thought about trying that but didn't have time. The challenge means different things to different folks.
Title: Re: Advent of Code
Post by: Ben T on 23 December, 2016, 06:07:59 pm
I haven't found a programmatic solution to day 22 or day 23 that will work with anybody's input.

Day 22 is a perfect example of something a human is good at solving based on what they see visually but a computer isn't.
(click to show/hide)

 Day 23,
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 23 December, 2016, 06:33:58 pm
I haven't found a programmatic solution to day 22 or day 23 that will work with anybody's input.

Day 22 is a perfect example of something a human is good at solving based on what they see visually but a computer isn't.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2016, 10:27:44 pm
I haven't found a programmatic solution to day 22 or day 23 that will work with anybody's input.

Day 22 is a perfect example of something a human is good at solving based on what they see visually but a computer isn't.
(click to show/hide)

(click to show/hide)


(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 23 December, 2016, 10:35:18 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 24 December, 2016, 09:23:23 am
Day 24: A bigger challenge

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 24 December, 2016, 10:08:33 am
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 24 December, 2016, 01:02:10 pm
Oh dear - some stupid mistakes cost me plenty of time which meant with other Christmas stuff going on, I had to leave it a while before resuming.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2016, 02:26:10 pm
I haven't found a programmatic solution to day 22 or day 23 that will work with anybody's input.

Day 22 is a perfect example of something a human is good at solving based on what they see visually but a computer isn't.
(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2016, 02:38:27 pm
(That woe is day 24 not day 23... ) but:
(click to show/hide)
Title: Re: Advent of Code
Post by: red marley on 24 December, 2016, 02:38:53 pm
^--- (Ben's Day 22) Sure, but with a grid of only c. 30x30 or so cells, shouldn't it soon exhaust that bottom right corner and find a better route past the wall?

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2016, 02:42:27 pm
^--- (Ben's Day 22) Sure, but with a grid of only c. 30x30 or so cells, shouldn't it soon exhaust that bottom right corner and find a better route past the wall?

(click to show/hide)
maybe, yeah - I'll revisit and try and find out why it doesn't. I think the reason may be that the hash is 'too unique', i.e. it cares (too much) about the position of actual data rather than just the position of the space.
Title: Re: Advent of Code
Post by: David Martin on 24 December, 2016, 03:35:02 pm
Hmm.. Just got back to this and I think my code is really inefficient compared to the times reported. Still running DFS (maybe BFS would be better?)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2016, 04:10:05 pm
Hmm.. Just got back to this and I think my code is really inefficient compared to the times reported. Still running DFS (maybe BFS would be better?)
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 24 December, 2016, 04:19:29 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2016, 05:40:46 pm
Less than a second including calc of leg lengths?? If so mine must be inefficient then as that takes about 5 seconds per leg. Only reason could be that it is plodding along one square at a time rather than going as far as possible with each movement. But optimizing probably unnecessary...
Title: Re: Advent of Code
Post by: David Martin on 24 December, 2016, 09:13:09 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 25 December, 2016, 12:22:19 pm
Today's is quite fun.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 25 December, 2016, 01:22:42 pm
(click to show/hide)

or slightly more terse but less calculation:
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 26 December, 2016, 09:49:35 pm
day 19 part 1:
(click to show/hide)

I know I'm a bit behind the times (computer downtime). I liked this one too, it's clear there's an analytic solution - every second elf loses his presents. But the problem as presented looks like a queue, so I coded it in that spirit:
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 26 December, 2016, 09:51:47 pm
Very neat.
Title: Re: Advent of Code
Post by: Pickled Onion on 26 December, 2016, 10:30:58 pm
Thank you.  :)

Perl's lists/arrays are optimised for use as queues, so repeated push/pop/shift/unshift does not create a massive realloc fest. Unfortunately, removing an element from the middle is something else entirely, so part 2 in the same vein

(click to show/hide)

takes rather a long time...
Title: Re: Advent of Code
Post by: Ben T on 29 December, 2016, 03:51:17 pm
Withdrawal symptoms?
I've found this website https://projecteuler.net which offers a multitude of problems some of which appear to solvable by programming.
Some are quite interesting, e.g. this one https://projecteuler.net/problem=575 which I've managed to solve.
A lot seem very maths-heavy e.g. about sets of prime  numbers and the like, but they do appear to be simple from a brute force point of view but then you are asked from a number very high in the sequence, so either mathematical knowledge and/or heavy optimization or realizing some vast simplification is required.
Title: Re: Advent of Code
Post by: Oaky on 30 November, 2017, 12:46:51 pm
2017 AoC in about 16 hours time! :)
Title: Re: Advent of Code
Post by: Greenbank on 30 November, 2017, 01:17:00 pm
ooh, signed up

(And going back and doing 2016 as practice...)
Title: Re: Advent of Code
Post by: Diver300 on 30 November, 2017, 07:51:42 pm
2017 AoC in about 16 hours time! :)
Arrgghhh!

December productivity will be at it's usual post 2015 levels.
Title: Re: Advent of Code
Post by: David Martin on 01 December, 2017, 12:03:08 am
That's the marking taking a back seat then.

Is there a YACF league?
Title: Re: Advent of Code
Post by: Croft on 01 December, 2017, 06:27:38 am
From previous years, the YACF leaderboard code is 48462-ea506236
Title: Re: Advent of Code
Post by: davelodwig on 01 December, 2017, 10:55:06 am
Enjoyed that, once I'd remembered to read the question properly.

Am using PHP just because that's what I happen to use daily.

D.
Title: Re: Advent of Code
Post by: Oaky on 01 December, 2017, 01:03:09 pm
I'm using Python again,  trying to use Pandas/numpy wherever possible.

(click to show/hide)
Title: Re: Advent of Code
Post by: freeflow on 01 December, 2017, 03:03:31 pm
Done today's using VBA. Tomorrow I'll try python.
Title: Re: Advent of Code
Post by: David Martin on 01 December, 2017, 05:41:21 pm
I'm using Python again,  trying to use Pandas/numpy wherever possible.

(click to show/hide)
Interesting - I'd not seen that.
The second part is a special case
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 01 December, 2017, 06:49:45 pm
Ah yes, well spotted. A language that supports negative array indices is hinted by part one, and helps for part 2.

58 keystrokes. Anyone manage fewer?
Title: Re: Advent of Code
Post by: Greenbank on 01 December, 2017, 08:18:00 pm
ooh, signed up

(And going back and doing 2016 as practice...)

2016 done, will move on to 2015 too.

Doing all of mine in Perl as that's what I use for quick hacks and prototypes.
Title: Re: Advent of Code
Post by: David Martin on 01 December, 2017, 09:09:44 pm
Ah yes, well spotted. A language that supports negative array indices is hinted by part one, and helps for part 2.

58 keystrokes. Anyone manage fewer?
I presume that is CTRL-C/CTRL-V to copy and paste the original data? And is that one part or both parts.
81 characters, but some are spaces.
Title: Re: Advent of Code
Post by: Pickled Onion on 01 December, 2017, 09:42:12 pm
ok, I didn't include the data or printing out the answer. Fully working solution is 64 characters for part 1 and 67 characters for part 2

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 02 December, 2017, 12:17:57 am
2016 done, will move on to 2015 too.

Doing all of mine in Perl as that's what I use for quick hacks and prototypes.

Ugh, enough for now, done up to (and including day 16 of 2015).
Title: Re: Advent of Code
Post by: Pickled Onion on 03 December, 2017, 11:40:50 am
It's started to get more interesting today. Only day 3, is this year going to be a tough one?

Out of interest, who are Phong and mTrak? I'm iakobski.
Title: Re: Advent of Code
Post by: David Martin on 03 December, 2017, 04:14:09 pm
That was painful. The first part was elementary maths - no code needed.
The second part I used a dynamic programming approach and promptly filled it so full of bugs it took a long time to wrangle out. Was there a more elegant way that I somehow missed?

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 03 December, 2017, 05:31:23 pm
That's the thing with a lot of these - if you short-circuit part 1, you find part 2 needs the data from part 1.

I built the whole grid in part 1, even though it was obvious there would be a clever way round that, so adding on a value to each point was trivial.

However my first attempt using recursion succeeded only in turning my laptop into a lap-heater, who knew that recursing several of hundreds deep on each point was not the best use of cpu cycles  :facepalm:
Title: Re: Advent of Code
Post by: Greenbank on 03 December, 2017, 06:47:56 pm
That's the thing with a lot of these - if you short-circuit part 1, you find part 2 needs the data from part 1.

Or if you don't short-circuit part 1 you find that part 2 involves computing something so big that it would take the naive algorithm years to finish so you do need to short-circuit it.

Most of the time (having just gone back and done the whole of 2016 and 2015 over the last few days) whatever I do in part (a) is usually the wrong one. I guess this is no coincidence.

The second part I used a dynamic programming approach and promptly filled it so full of bugs it took a long time to wrangle out. Was there a more elegant way that I somehow missed?

2017.3.b spoiler:-

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 03 December, 2017, 07:08:48 pm
That's the thing with a lot of these - if you short-circuit part 1, you find part 2 needs the data from part 1.

Or if you don't short-circuit part 1 you find that part 2 involves computing something so big that it would take the naive algorithm years to finish so you do need to short-circuit it.

Most of the time (having just gone back and done the whole of 2016 and 2015 over the last few days) whatever I do in part (a) is usually the wrong one. I guess this is no coincidence.

Yes, that's what makes these so much fun. I can solve it this way... or that way... which way is going to help in part 2?
Title: Re: Advent of Code
Post by: David Martin on 03 December, 2017, 08:55:04 pm
I suppose I just had a function that mapped the 2D onto the 1D array and went from there. I went back and checked and despite the dynamic programming, I still calculated every value.

Title: Re: Advent of Code
Post by: Oaky on 03 December, 2017, 09:35:08 pm
Didn't get to doing today's until this evening owing to family visiting plus putting up the Christmas decorations.

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 03 December, 2017, 11:13:57 pm
(click to show/hide)
I used the same method.

(click to show/hide)

I did part one without programming, just a text editor for notes and a calculator.

BTW, I'm mtrak
Title: Re: Advent of Code
Post by: Greenbank on 04 December, 2017, 08:40:06 am
Was hoping for a meaty one today but no.

Still, I've got some of the older ones to revisit and make work more efficiently.
Title: Re: Advent of Code
Post by: Croft on 04 December, 2017, 10:23:15 am
I'm impressed you rattled though the 2015 and 2016 ones so quickly. I seem to recall the Isotope lifts problem, the Wizard Spells game and Medicine for Rudolph problems taking quite some effort.
Title: Re: Advent of Code
Post by: David Martin on 04 December, 2017, 10:54:46 am
Today's was very much a start of week 1 problem.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 04 December, 2017, 11:05:33 am
isotope lift
(click to show/hide)

wizard spells I spent a fair while on as I had an annoying bug (one of my effects lasted for the wrong number of turns) - when I finally sorted that I had also missed the fact that you had to cast an effect on every turn, and my code allowed nothing to be done on a turn (with my input you got a lower score if you did nothing on the last turn as the poison spell was still in effect)

Another reminder to READ THE DESCRIPTION PROPERLY!

medicine for rudolph : maybe I was lucky...
(click to show/hide)

This kind of challenge (as in AoC) is exactly my kind of thing though. I've been coding as a job for 20+ years and have degrees in both Comp Sci and Maths, I've also done many of the Valladolid Online Judge (https://uva.onlinejudge.org/) programming challenges too so many of the concepts I've covered before.
Title: Re: Advent of Code
Post by: Croft on 04 December, 2017, 11:20:04 am
Medicine for Rudolph (Day 19, 2015)

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 04 December, 2017, 11:58:23 am
Today's was very much a start of week 1 problem.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 04 December, 2017, 11:07:28 pm
My pandas fu is not that developed.
Title: Re: Advent of Code
Post by: Diver300 on 05 December, 2017, 06:38:14 am
Day 5 seemed quite straightforward.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 2017, 07:51:57 am
At this point the private leaderboard is more about who gets up earliest than anything else. (7.30am is the earliest I'll ever be in front of a computer.)

(Not grumbling, the trickier problems will come...)
Title: Re: Advent of Code
Post by: David Martin on 05 December, 2017, 10:54:01 am
Indeed. I appear to be 4th up in the morning.

I was idly thinking on whether there was a trivial way to determine the result from the values in the steps. I am led to believe it is pretty close to an ideal turing machine and therefore you only know if it will stop when it does, so there is no way to know the number of interations from the instructions without playing them out.
Title: Re: Advent of Code
Post by: David Martin on 06 December, 2017, 07:35:37 am
For day 6, the brute force is obvious, but I was wondering whether there is a more elegant way to do it.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 06 December, 2017, 08:07:03 am
Day 6:

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 06 December, 2017, 11:06:02 am
Day 6:
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 06 December, 2017, 04:16:30 pm
Day 6
The debugging output for my code had basically solved part 2 by the time that I had solved part 1
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 06 December, 2017, 05:00:15 pm
Day 6
The debugging output for my code had basically solved part 2 by the time that I had solved part 1
(click to show/hide)
very similar
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 06 December, 2017, 05:10:38 pm
Day 6
The debugging output for my code had basically solved part 2 by the time that I had solved part 1
(click to show/hide)
very similar
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 06 December, 2017, 08:16:45 pm
Day 6
The debugging output for my code had basically solved part 2 by the time that I had solved part 1
(click to show/hide)
very similar
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 07:54:45 am
That was a bit more satisfying.. Note: read the text more carefully.
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2017, 10:03:30 am
Indeed, that's a bit better.

It's the first one (of 2017) where I've had to write psuedo-code first and then flesh it out, rather than knowing what to do straight from the start.
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 10:37:36 am
The pattern and approach was quite straightforward. Better if I read the instructions for part 2 and deliver what was asked. No need for pseudo code.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2017, 11:41:07 am
Day 7:

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 01:21:28 pm
Day 7:

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2017, 01:41:31 pm
Day 7:

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 01:47:42 pm
That reminds me of the reddit competition to find the most ridiculous way to test if a number was even or odd.
It is order(N) for every lookup, making it approach order (N^2) overall.

(click to show/hide)

Title: Re: Advent of Code
Post by: Ben T on 07 December, 2017, 02:07:42 pm
did it in a probably over verbose OO way https://github.com/bjtaylor1/AoC2017/blob/day07part2/Day07/App.cs but didn't take long and was basically shot from the hip and didn't require any debugging to get right pretty much first time
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2017, 02:41:40 pm
Day 7:

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 04:10:34 pm
OK, here is my python
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 04:15:17 pm
Day 7:

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2017, 05:20:46 pm
can you not (instead of the two cases) do:

Almost certainly, but that file was pretty much the first thing that gave me the correct answer (whether it prints it explicitly like mine, or gives enough information to work out the answer like yours). I don't bother polishing it once I've submitted a correct answer. If I was going to use it for anything else in the future then I'd spend some time refactoring it and adding suitable comments. I'd also consider how it would handle much larger inputs.

The last thing I want to be doing is chasing bugs in the code that reads the input, so I've no problem with a bit of duplication there.

[EDIT] It's only when the problems start to get properly challenging that I will take more care on my programs. My goal is to get the answer as quickly as possible (and in a reasonable execution time). The competition is not really making me learn anything new (if you want that then the Valladolid Online Judge or Project Euler are much better).
Title: Re: Advent of Code
Post by: Pickled Onion on 07 December, 2017, 09:48:05 pm
My goodness I made a meal out of that one. Must remember to read the question properly  :facepalm:
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 10:49:09 pm
Thanks for the links to Project Euler and the Valladolid Judge sites. Interesting challenges though the sites are not terribly clear on how they work.
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2017, 10:58:36 pm
Valladolid was submit your code by email (at least when I was doing it back in 2001!). The automated system then sanitised it (to make sure you weren't doing anything silly or destructive) and then ran the code against an unseen input.

Their trick was the example inputs you got given on the website were a fraction of the size of the real input (which you never saw), or the real input was the pathological case for the standard algorithm.

So many times I'd be confident about my code, email it off, only to receive a "Time Limit Exceeded" response.

Can't remember much about Project Euler, only did one or two but I discussed a lot of the problems with someone from work I was mentoring.

Day 8: Will it be another fake CPU question (I do like them) or something like a knapsack or another TSP-esque classic?
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 11:06:44 pm
We have had the first tree traversal one. Must be some magic codes to parse (medicine for rudolf). Still in early days so shouldn't be too taxing (hostage to fortune there).
Title: Re: Advent of Code
Post by: Diver300 on 07 December, 2017, 11:11:19 pm
Day 7
Solved with a spreadsheet. It did get quite big but not as large as many I written that have a more serious purpose.
Title: Re: Advent of Code
Post by: David Martin on 07 December, 2017, 11:34:22 pm
I cannot imagine voluntarily choosing to do it that way. It makes me cringe even thinking about it.
Title: Re: Advent of Code
Post by: Oaky on 07 December, 2017, 11:50:43 pm
Day 7 p2 is still not done.

RL has got in the way -- I can see two ways of attacking it, both of which should work, but haven had the time yet to give either a go.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2017, 12:01:05 am
Recursion works when recursion works.
What is the non-recursive approach?
Title: Re: Advent of Code
Post by: Diver300 on 08 December, 2017, 06:18:02 am
I cannot imagine voluntarily choosing to do it that way. It makes me cringe even thinking about it.

There towers are only 6 levels high, so finding a group of formulas that works, and copying across until there are no more sub-towers doesn't take long
The spreadsheet was 6000 lines long, as each step ended up at 9 lines. In retrospect 10 would have been easier on the brain.
Title: Re: Advent of Code
Post by: Diver300 on 08 December, 2017, 06:20:41 am
Day 8 didn't seem all that difficult.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2017, 07:41:36 am
Pretty much
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2017, 09:38:23 am
Day 8:

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 08 December, 2017, 10:53:29 am
self contained dynamic compilation https://github.com/bjtaylor1/AoC2017/blob/day08part2/Day08/Program.cs
essentially the same, my TranslateCode function is your line of sed and my main function is orchestrating the running of it.
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2017, 02:00:05 pm
Day 8: Will it be another fake CPU question (I do like them) or something like a knapsack or another TSP-esque classic?

And, lo, it was a fake CPU type question.

I wrote an interpreter for my solution before doing the above horrific command line transpose nonsense.

Will we get a couple of biggies to do over the weekend? I hope so!
Title: Re: Advent of Code
Post by: Oaky on 08 December, 2017, 04:08:02 pm
Finally got round to doing day 7 part 2.  (after knocking out day 8 )

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 08 December, 2017, 04:42:47 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2017, 01:08:39 am
Hoping to sober up enough to be able to do Day 9 tomorrow today.

Hic.

I foresee much keyboard thrashing and grumpiness...
Title: Re: Advent of Code
Post by: Ben T on 09 December, 2017, 10:16:07 am
nothing taxing as long as you don't try and be too fancy.
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2017, 11:06:57 am
I've written enough stuff that parses input (specifically SQL and CSV) to understand the joy of string parsing with escape characters. Even with a slightly foggy brain from a mild hangover.

(click to show/hide)
Title: Re: Advent of Code
Post by: Manotea on 09 December, 2017, 11:42:40 am
Inspired by Greenbank, I started reading this (https://www.gamedev.net/articles/programming/general-and-gameplay-programming/finite-state-machines-and-regular-expressions-r3176/)

Then realised I had something else to do today.  :)
Title: Re: Advent of Code
Post by: Ben T on 09 December, 2017, 01:54:14 pm
I've written enough stuff that parses input (specifically SQL and CSV) to understand the joy of string parsing with escape characters. Even with a slightly foggy brain from a mild hangover.

(click to show/hide)

I'm reasonably au fait with regex but wouldn't attempt to use it to try and count group nesting.... I didn't see any need for recursion but whether it could have made it more elegant I don't know. Mine's a fairly simple literal interpretation of the logic as described https://github.com/bjtaylor1/AoC2017/blob/day09part2/Day09/Program.cs
nothing wrong with recursion if you just like it though :)
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2017, 03:23:24 pm
...then a second one to parse the garbage free input into the groups, then a recursive function to score it all.
The input was well-formed enough that it only required counting the { up and } down

Quote
I'm secretly hoping that someone attempts this with a regex and eventually learns the lesson about regular expressions and context-free grammars.

This particular one would be fairly straightforward with a regex, but yes it's the perennial question "how do I parse **ML with a regex?" A: DON'T!!

For a laugh I solved this (https://www.gchq.gov.uk/news-article/christmas-card-cryptographic-twist-charity) using regular expressions, it took rather longer to code than doing it with a pencil but the result was quite impressive nonetheless.
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2017, 04:02:32 pm
Just plough through and process it as a stream.

(click to show/hide)

I did come across an interesting puzzle that was easily solved to a certain state with matrix algebra. I then have to sort a matrix to get the minimum diagonal to get the appropriate order of rows.
Title: Re: Advent of Code
Post by: Oaky on 09 December, 2017, 04:49:26 pm
Just plough through and process it as a stream.

(click to show/hide)

I did come across an interesting puzzle that was easily solved to a certain state with matrix algebra. I then have to sort a matrix to get the minimum diagonal to get the appropriate order of rows.

I don't think you pushed your day 9 changes to github yet ;)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2017, 07:14:02 pm
Good spot. Didn't tick the 'push to origin automatically' box in Sourcetree.
Title: Re: Advent of Code
Post by: Oaky on 09 December, 2017, 08:40:38 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 10 December, 2017, 06:27:17 am
The instructions for day 10 almost lead you though the programming steps needed. It reads more like a lesson in computing than a puzzle.
Title: Re: Advent of Code
Post by: David Martin on 10 December, 2017, 08:59:01 am
Agreed. Involved but not hard. Bleary eyed typos notwithstanding. Not sure I have the oomph in the morning to test-suite it. I'd have sorted the tests after finding the things that needed to be tested, by which time they would be unnecessary.
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2017, 07:20:21 am
Ouch - my head hurts a bit after trying to sort that one out. Probably an inelegant solution to calculate the total number of steps. I'm sure there must be a better way to resolve the axes than a series of if/else looking at the relevant cases. Possibly something matrixy but my brain isn't functioning.
Title: Re: Advent of Code
Post by: Croft on 11 December, 2017, 07:37:02 am
Day 11

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2017, 10:14:45 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 11 December, 2017, 10:41:34 am
Day 11

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 11 December, 2017, 11:15:05 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2017, 12:25:55 pm
Day 11

(click to show/hide)
I must admit that trying to sort that at early morning after dealing with a frozen pipe leading to a major water leak in the house was challenging enough - I thought it should be able to be done something like that. Instead I did it the hard way.
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2017, 12:59:04 pm
Day 11

(click to show/hide)

I am struggling to see how you come up with that matrix.

Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2017, 01:45:59 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 11 December, 2017, 01:47:29 pm
Greenbank beat me to it, but..
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 11 December, 2017, 03:33:59 pm
Doh! I was looking at steps but not in the right directions.
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2017, 08:22:17 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 12 December, 2017, 07:45:31 am
Underwhelming today...

Jo's graphs seem to back up my suspicion that 2017 (so far at least) is quite a bit easier than the previous years: https://github.com/jwoLondon/adventOfCode
Title: Re: Advent of Code
Post by: Oaky on 12 December, 2017, 08:22:59 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 12 December, 2017, 09:01:31 am
(click to show/hide)

I'm far too thick to think up any 3D solution so just did it in 2D and for part 1 did a BFS that worked fine and ran in under a second.
But for part 2 I firstly assumed incorrectly that the furthest away in 2D distance (the geographical furthest) would have the furthest number of steps, in fact it didn't.
I knew that the max steps (the answer) couldn't be much more than the number of steps for geographical furthest, but didn't want to keep guessing.
So I simply optimized it by factorizing the hexagons and only considering moves outside a minimum radius inside which they couldn't possibly take as many steps as the geographical furthest.
Still takes about a minute though. https://github.com/bjtaylor1/AoC2017/blob/day11part2b/Day11/Program.cs   :facepalm:
Quite good though, first reasonably difficult one.
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2017, 09:32:08 am
Today was straightforward.
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 12 December, 2017, 01:57:06 pm
Today was straightforward.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2017, 02:30:07 am
Slowly doing the Anti-AoC:-

How close to 5am (UK time) can I still be up but with no chance of being up to 5am to attempt the challenge (let alone be sober enough!)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2017, 08:35:19 am
Today: I've done part 1 but part 2 will have to wait till I get home as I have too much marking to do. I recognize the problem but can't remember the elegant solution
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 13 December, 2017, 10:07:13 am
day 12 quite easy going from part 1 to 2 https://github.com/bjtaylor1/AoC2017/compare/day12part1...day12part2
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2017, 01:16:06 pm
My simple naive brute force version took just under 20 seconds for day 13 part b.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2017, 06:33:00 pm
I've kind of worked out how I want to do part 2 but am currently shattered so will pick it up after a wee pause.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2017, 07:43:22 pm
Still working on a more elegant solution for day 13b.

My work in progress (big spoiler):-

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2017, 08:38:53 pm
And the final bit (using my puzzle input, so it won't be the same for everyone)...

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 13 December, 2017, 08:48:56 pm
Still working on a more elegant solution for day 13b.

My work in progress (big spoiler):-




Neat!


Today's was the first this year where part 2 didn't respond well to a simplistic approach.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2017, 09:06:20 pm
Today's was the first this year where part 2 didn't respond well to a simplistic approach.

Really? I spent 5 minutes writing this to get the answer in 20 seconds:-

(click to show/hide)

My usual method is to see if the basic/naive approach will work and whether it produces the answer before I can implement something that runs faster.

But then I spent another 90 minutes or so to bring the execution time down to nothing, just to do it the right way (or at least one of the right ways).

Yes, that's 90 minutes to bring the execution time of a one-off task down from 20 seconds to 0 seconds. Unsurprisingly according to the chart (https://xkcd.com/1205/) it was not worth the time. But I did learn (or at least remind myself of) a few things along the way.
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2017, 11:26:29 pm
You have a faster computer than me. Mine took a few minutes to run and I was completely naive with searching every possibility. The approach I had been thinking about is this:
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 14 December, 2017, 08:04:04 am
The one I posted checks every possibility (delay=0,1,2,3,4,5,...),  it just does the individual checks in a more 'mathsy' way.

Anyway, Day 14 and use of previous solutions (which I like and had hoped would appear more in AoC 2017).

I wonder if I need to make my knot hash code faster in case it's used more and more in future challenges. It currently takes 10 seconds to produce the 128 knot hashes required as input for parts (a) and (b), I'm sure I can get this down (and will give me something to do for AoC for part of the rest of the day).
Title: Re: Advent of Code
Post by: Ben T on 14 December, 2017, 11:01:45 am
You have a faster computer than me. Mine took a few minutes to run and I was completely naive with searching every possibility. The approach I had been thinking about is this:
(click to show/hide)

My day 13 part 2 runs in 0.4 of a second.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 14 December, 2017, 11:22:37 am
Naive 13b down to under 3 seconds if I check them in range depth order (from smallest to largest). I was already bailing early but checking the layers in a suboptimal order. Using an interpreted language doesn't help either.

But my 'clever' solution for day13b runs in 0.002 seconds.
* For the example input I do my pre-computation then checks just one possible delay value.
* For my real input I do my pre-computation and then have to check just 36 possible delay values.

I could speed this up too as:
(click to show/hide)

I'll see if I can knock up an input that has an answer that is orders of magnitude larger.
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2017, 11:40:25 am
Today's may have to wait till tomorrow or the weekend -overrun with other things right now.

Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2017, 11:45:05 am
I used a spreadsheet (again!) for day 13.  It had far fewer active cells than for day 7 and it didn't do much more than I could have done with a pencil and paper and a calculator.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 14 December, 2017, 11:49:39 am
I'll see if I can knock up an input that has an answer that is orders of magnitude larger.

OK, try this against your 2017 day 13b solver: http://www.greenbank.org/misc/aoc2017/2017_13b.huge.txt

The answer is about ~250 times larger than my answer for 13b was, which should give you a rough idea of execution time if it's checking every number along the way. (The answer still fits inside a signed 32-bit integer though, so programs shouldn't need to be altered.)

Mine gets it in under 0.001s after only having to try 38 numbers.

[EDIT] In contrast, my naive solver took 738s to get the answer.
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2017, 12:24:18 pm
Day 14 relies on a code written for day 10.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 14 December, 2017, 12:55:18 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2017, 10:34:38 am
Pretty simple today (day 15), no surprises.
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2017, 04:50:24 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2017, 04:52:49 pm
Ooh. Do 4 colours suffice?
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2017, 05:12:30 pm
Ooh. Do 4 colours suffice?

Well, given my input, I'm using
(click to show/hide)
  colours (including the black for the background), but in the 4-colour sense, two suffices for this pattern. :)  Doesn't look as nice then, though.
Title: Re: Advent of Code
Post by: Oaky on 15 December, 2017, 05:48:24 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 15 December, 2017, 09:56:56 pm
Day 15

I thought that Javascript might struggle doing modulus 231. It didn't, and only takes a few seconds to run.

The whole point about day 13 was that it took too long to run when brute-forced. When reading day 15, I thought that the maths that is simple in principle would have some feature that would trip up the simple approach.
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2017, 11:13:32 pm

Far too busy to do yesterday and today till now.

Day 14 was easy for part 1,
(click to show/hide)

Day 15 was straightforward
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 16 December, 2017, 07:53:22 am
day 16 part 2 is proving difficult.....
Title: Re: Advent of Code
Post by: Pickled Onion on 16 December, 2017, 08:10:00 am
day 16 part 2 is proving difficult.....
You're not the only one stuck on that

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 16 December, 2017, 10:03:52 am
I am finding part 2 challenging
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 16 December, 2017, 10:40:21 am
I didn't think that would work.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 16 December, 2017, 10:45:00 am
OK, simple error
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 16 December, 2017, 10:45:32 am
I didn't think that would work.

(click to show/hide)
That is now obvious. :)
Title: Re: Advent of Code
Post by: Greenbank on 16 December, 2017, 12:57:50 pm
Bit late to it today...

(click to show/hide)

It's annoying as I'm solving the majority of these in a faster time than the 100th person on the main leaderboard (today I would have scraped into the top 10). But I guess quite a few other people are too (who also just don't happen to be at their computer at midnight EST).
Title: Re: Advent of Code
Post by: Diver300 on 16 December, 2017, 04:43:35 pm
I didn't think that would work.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 16 December, 2017, 05:25:07 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 16 December, 2017, 05:31:18 pm
Day 16
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 16 December, 2017, 05:38:58 pm
Day 16
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 16 December, 2017, 09:11:40 pm
Day 16
(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 16 December, 2017, 10:36:19 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 17 December, 2017, 06:53:36 am
Day 17 was quite straightforward.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 17 December, 2017, 08:41:39 am
Day 17 was quite straightforward.
(click to show/hide)

64 characters for part 2, including input data.  ;D

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2017, 09:59:29 am
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2017, 10:05:54 am
(click to show/hide)

64 characters for part 2, including input data.  ;D

I can get it down to 84 in perl, but then I'm not very good at code golf.
Title: Re: Advent of Code
Post by: Pickled Onion on 17 December, 2017, 10:43:24 am
64 characters for part 2, including input data.  ;D

I can get it down to 84 in perl, but then I'm not very good at code golf.

I look forward to comparing line noise tomorrow!
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2017, 02:01:18 pm
17a was quite straightforward.
17b required minor thought but eventually succumbed to brute force
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 17 December, 2017, 02:17:44 pm
17a was quite straightforward.
17b required minor thought but eventually succumbed to brute force
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 17 December, 2017, 02:24:39 pm
pretty much the same here. Took a bit longer than 3 seconds (about 10 or so)
Title: Re: Advent of Code
Post by: Pickled Onion on 17 December, 2017, 02:32:26 pm
Don't you need to increment buf_len?

My Perl version took 18 seconds with a grep BLOCK, but that's because grep allocates the whole list before it starts. Turning that into a for(RANGE) runs in 8 seconds. Oh and I'm down to 61 characters in the golf version  :)
Title: Re: Advent of Code
Post by: Ben T on 17 December, 2017, 03:13:28 pm
17a was quite straightforward.
17b required minor thought but eventually succumbed to brute force
(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 17 December, 2017, 03:33:35 pm
Ben T:
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 17 December, 2017, 05:08:27 pm
Ben T:
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 17 December, 2017, 06:27:35 pm
Don't you need to increment buf_len?
Yes.

I put that after the conditional bit for some reason.
Title: Re: Advent of Code
Post by: Croft on 17 December, 2017, 07:14:23 pm
Ben T:
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 18 December, 2017, 09:25:38 am
Day 18.

Part a: Yet another psuedo CPU question. Boooring, or so I thought.

But part b was a lovely twist on it.

(00:15:45 from start to part a solution, 00:35:14 from start to part b solution, would have been a minute quicker if I'd read which answer I needed to give more closely.)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 18 December, 2017, 09:29:48 am
64 characters for part 2, including input data.  ;D

I can get it down to 84 in perl, but then I'm not very good at code golf.

I look forward to comparing line noise tomorrow!

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 18 December, 2017, 01:11:16 pm
First read the instructions..

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 18 December, 2017, 01:21:15 pm
64 characters for part 2, including input data.  ;D

I can get it down to 84 in perl, but then I'm not very good at code golf.

I look forward to comparing line noise tomorrow!

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: R_nger on 18 December, 2017, 06:05:00 pm
First read the instructions..

(click to show/hide)

Should that be Day 18 ?
Title: Re: Advent of Code
Post by: Oaky on 18 December, 2017, 09:58:13 pm

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 18 December, 2017, 10:32:19 pm
First read the instructions..

(click to show/hide)

Should that be Day 18 ?

That was probably one of the bugs..
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 08:12:59 am
Not much of a workout today. (Day 19). And scarily I wrote a 97 line perl program that ran first time with no syntax errors (but one minor logic error that my checking caught).

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2017, 08:39:53 am
Again, a lot of code for not much intellectual input - overengineered it but that isn't a bad thing.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 08:50:38 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2017, 11:59:55 am
Fortunately the input was well behaved, I had considered cases like two corners in consecutive steps, realised that the coding would be more involved and if it came across a not immediately tractable solution to print the local environment and ask for guidance. It didn't need to as there was at least one step between each corner.
Title: Re: Advent of Code
Post by: Croft on 19 December, 2017, 12:14:50 pm
A bit disappointed in the simplicity of Part 1. I was almost certain when doing part 1, that the second part was going to ask for the shortest path from start to destination point of part 1.
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2017, 12:21:50 pm
By only taking known routes and adding corners where they cross.. I'm just expecting a humdinger tomorrow then.
Title: Re: Advent of Code
Post by: Pickled Onion on 19 December, 2017, 12:33:40 pm
Tripped up by having my packet fall off the end of the route and carry on going. The test data was fine as that took it off the circuit board and stopped, but on the actual circuit it found another path and carried on in circles. Oops.
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 01:05:05 pm
Fortunately the input was well behaved, I had considered cases like two corners in consecutive steps, realised that the coding would be more involved and if it came across a not immediately tractable solution to print the local environment and ask for guidance. It didn't need to as there was at least one step between each corner.

Not sure why this would be a problem, there are no decisions to be made at any corners. Either you can continue on in a straight line still or you have to choose left or right (and there won't be a choice).

For example:-

Code: [Select]
  |
B++A
  ++

is unambiguous.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 19 December, 2017, 01:55:07 pm

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 03:45:47 pm

(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 19 December, 2017, 04:19:59 pm

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 19 December, 2017, 04:21:26 pm
Fortunately the input was well behaved, I had considered cases like two corners in consecutive steps, realised that the coding would be more involved and if it came across a not immediately tractable solution to print the local environment and ask for guidance. It didn't need to as there was at least one step between each corner.

Not sure why this would be a problem, there are no decisions to be made at any corners. Either you can continue on in a straight line still or you have to choose left or right (and there won't be a choice).

For example:-

Code: [Select]
  |
B++A
  ++

is unambiguous.

but
Code: [Select]
   ||||
   ++++
isn't unless you look further afield than immediately adjacent characters. I couldn't be bothered so just wrote a prompt in to look at it by eye and indicate where it should go

Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 04:35:52 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 04:39:13 pm
but
Code: [Select]
   A|BC
   ++++
isn't unless you look further afield than immediately adjacent characters. I couldn't be bothered so just wrote a prompt in to look at it by eye and indicate where it should go

If you're coming down from A then it's unambiguous. You go down, turn left (as you can't turn right), to the end of that line (because you only turn when you can't continue straight on) and then the only choice is to turn left (up) to get to C.

Likewise coming down from C is unambiguous (C down, right, all the way to the end, right and up to A).

Coming down from B is ambiguous as you have a choice of which way to turn, but my reading of the instructions was that this was not going to occur since it didn't say what to do in such cases.
Title: Re: Advent of Code
Post by: Oaky on 19 December, 2017, 06:01:01 pm

(click to show/hide)

(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 06:37:09 pm
(click to show/hide)

(click to show/hide)

[EDIT] Sorry, I keep editing the above, we need a YACF-AOC Slack channel. I've created one but would this be a good idea or do people want to keep the discussion here?
Title: Re: Advent of Code
Post by: Oaky on 19 December, 2017, 07:33:41 pm
I'd join a Slack channel.

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 19 December, 2017, 07:50:26 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 09:01:02 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 19 December, 2017, 09:31:20 pm
(click to show/hide)

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2017, 10:43:52 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2017, 09:10:49 am
Relatively simple today (day 20).

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2017, 12:49:43 pm
I must have something wrong with my iterations as it is taking a long time and not finding collisions.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2017, 01:23:20 pm
*blush* Silly bug. Not updating z coordinate. Now solved.
Title: Re: Advent of Code
Post by: Diver300 on 20 December, 2017, 01:59:44 pm
Day 20
First part was solved with one run through the data.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2017, 02:17:00 pm
Day 20
First part was solved with one run through the data.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 20 December, 2017, 02:47:23 pm
Day 20
First part was solved with one run through the data.
(click to show/hide)

(click to show/hide)
True. I'm not claiming that my algorithm for part 1 would work with all possible inputs.
Title: Re: Advent of Code
Post by: Oaky on 20 December, 2017, 03:10:29 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2017, 03:47:55 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 20 December, 2017, 07:47:45 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 20 December, 2017, 09:06:48 pm
Day 20 b
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 20 December, 2017, 09:39:18 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2017, 10:27:04 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 20 December, 2017, 11:50:29 pm
 how have you all identified the state where won't be any more collisions for part b, ( or changes in closest to origin for a)?
Did you identify merely a point at which there probably won't be any more or that there can't possibly be?
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2017, 08:50:04 am
Day 21 looking meaty...

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 21 December, 2017, 09:23:33 am
Definitely requiring more thought. First time this year in the top 1000

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2017, 09:54:57 am
Day 21.

Correct answer for part (a), wrong answer for part (b).

The madness begins.
Title: Re: Advent of Code
Post by: David Martin on 21 December, 2017, 10:17:42 am
Off by one in your iteration count?
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2017, 11:33:36 am
Off by one in your iteration count?

Nope, more serious than that, but I got it (took me about 20 minutes to find it but I've been doing some real work for the last couple of hours). 43 minutes from submitting part (a) to submitting part (b). Ugh.

(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 21 December, 2017, 02:13:36 pm
Off by one in your iteration count?

Nope, more serious than that, but I got it (took me about 20 minutes to find it but I've been doing some real work for the last couple of hours). 43 minutes from submitting part (a) to submitting part (b). Ugh.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2017, 03:07:09 pm
Down to 30s for 21.b. I'd left my test code in there so I was doubling up on the expensive split/combine work for each iteration.

Will work on ways to get this down to <1s if I can in-between bouts of RealWork(TM).

[EDIT] 17s after simplifying some of the steps, still a way to go.
[EDIT] 15.38s and I think I know how to remove a lot of the complexity from here
[EDIT] 5.23s and much simpler now too, enthusiasm for further refactoring is waning
Title: Re: Advent of Code
Post by: David Martin on 21 December, 2017, 03:12:14 pm
Calculating part 2 from scratch took <20secs with my rather naive implementation. Adding in the minor optimisation of adding patterns as you find them took it down to sub 14s from scratch.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 21 December, 2017, 04:27:58 pm
55 seconds. Probably some optimizations but possibly marginal gains.
Was hoping it would  create a christmas tree but it didn't.
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 21 December, 2017, 05:10:14 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 21 December, 2017, 11:55:15 pm
Day 21, part 2 took my computer 4.637 seconds
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 22 December, 2017, 12:47:27 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 22 December, 2017, 09:12:45 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 22 December, 2017, 11:56:18 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 22 December, 2017, 12:33:25 pm
(click to show/hide)

Late to it today as I was helping set up a family party.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 22 December, 2017, 12:58:06 pm
(click to show/hide)

They have been a little bit samey. Maybe a new thread with some 'extra' puzzles on?
Title: Re: Advent of Code
Post by: Greenbank on 22 December, 2017, 01:22:29 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 22 December, 2017, 03:15:11 pm
(click to show/hide)

They have been a little bit samey. Maybe a new thread with some 'extra' puzzles on?

Agree, unlike last year, there hasn't been any this year that I have found hard. Some fairly 'involved', that took a few hours, but nothing more than that.
Title: Re: Advent of Code
Post by: David Martin on 22 December, 2017, 03:27:44 pm
OK, new thread started. I'll throw some data up for the first in due course.
Title: Re: Advent of Code
Post by: Pickled Onion on 22 December, 2017, 03:46:55 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 22 December, 2017, 04:01:28 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 22 December, 2017, 06:35:40 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 22 December, 2017, 07:59:19 pm
I did the same as Ben T.
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 22 December, 2017, 10:09:35 pm
(click to show/hide)

Got it!

My code was doing exactly what I expected, apart from the input data importer, which had a mistake in my regexp so that I was truncating the z coordinates to one digit only.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2017, 09:26:58 am
Day 23 part A is straightforward

Part B:
(click to show/hide)
ETA: Where was I going wrong? An inability to count the number of zeros. *blush*
And then an off by one errror
Title: Re: Advent of Code
Post by: Pickled Onion on 23 December, 2017, 10:16:08 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2017, 10:34:24 am
(click to show/hide)
That is why it is in (ETA: now multiple) spoiler tags.
Title: Re: Advent of Code
Post by: Pickled Onion on 23 December, 2017, 11:34:22 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2017, 11:45:42 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 23 December, 2017, 11:53:14 am
Neat  ;)
Title: Re: Advent of Code
Post by: Diver300 on 23 December, 2017, 12:39:10 pm
Day 23 part 2
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 23 December, 2017, 01:28:59 pm
Thankfully I chose wisely at the start of today's challenge.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 23 December, 2017, 03:35:40 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 23 December, 2017, 03:47:41 pm
With my numbers, the first time f was not 0 was at row 38 in a table similar to yours.

Title: Re: Advent of Code
Post by: Pickled Onion on 23 December, 2017, 03:51:35 pm
I've not done 21, so now my circuit shows the connections for 22 & 23 but won't light up.  :-[
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2017, 05:06:37 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2017, 05:28:03 pm
The different patterns in the circuit are getting more creative. Just had a chip labelled 1.21GW - must be a flux capacitor.
Title: Re: Advent of Code
Post by: Ben T on 23 December, 2017, 07:04:12 pm
(click to show/hide)


(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 23 December, 2017, 07:18:11 pm
(click to show/hide)


(click to show/hide)


(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 23 December, 2017, 08:06:12 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 24 December, 2017, 08:59:05 am
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 24 December, 2017, 09:06:46 am
Day 24 a bit more interesting, but not complicated.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 24 December, 2017, 09:32:05 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 24 December, 2017, 12:27:01 pm
Day 24
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 24 December, 2017, 01:42:21 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 25 December, 2017, 09:58:54 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Oaky on 25 December, 2017, 10:09:47 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 27 December, 2017, 09:47:40 am
Day 24.

Well that took me far too long, but it taught me quite a lot about what takes time in a program.

I wrote a routine that worked out strengths of possible bridges made out of components, and when it comes to more than one that fits, another possible bridge is created, to be looked at later. I had sorted the components so that they could be indexed by number of pins, so finding the next available connector was quick.

Stupidly, I got the programme to look for the first unfinished possible bridge each time a component was added to a possible bridge. It was that looking that took most of the time, being a loop within a loop. As the number of bridges got large, that got too large to manage, while with small numbers of bridges it wasn't a problem. I didn't realise the cause initially.

I looked at the data to optimise it, and saw that there were various unusable components, some components that would always be worse than others, and many combinations that could only usefully fit together one way. I used that to create a reduced data input set, but one with an extra column for the "strength" of the missed connectors. For instance, if I found that the only connectors with 33 pins were 1/33 and 2/33, I would create a new component that was 1/2 but had an extra 66 of strength to be added when used.

With that, I got the answer, but the code took a minute or more to run.

Then I saw that everyone else had code that ran in seconds or less, and I realised that my loop within a loop was the problem. I sorted that, and worked out the statistics.

The full data ran added 1.8 million components, and tried 600,000 possible bridges
The reduced data added 66,000 components and tried 31,000 possible bridges.

The reduced data, when the code was searching for unfinished bridges, did 485 million loops just looking for the next bridge to try.


Title: Re: Advent of Code
Post by: Greenbank on 18 March, 2018, 11:05:32 pm
Decided to learn go so redoing 2017 in go.

https://github.com/alexgreenbank/AdventOfCode

It's certainly easier when you know how to solve each one efficiently (or at least efficiently enough).

Day 5 and I finally got to the point where I wrote the complete program for part one and only had to correct typos after the first attempt at running it.
Title: Re: Advent of Code
Post by: David Martin on 18 March, 2018, 11:46:30 pm
Really not got the time till after the Easter break. Love to get back into it, but that will have to wait till the summer.
Title: Re: Advent of Code
Post by: Ben T on 19 March, 2018, 06:33:20 am
Decided to learn go so redoing 2017 in go.

https://github.com/alexgreenbank/AdventOfCode

It's certainly easier when you know how to solve each one efficiently (or at least efficiently enough).

Day 5 and I finally got to the point where I wrote the complete program for part one and only had to correct typos after the first attempt at running it.
If you want more practice try some project euler problems, AoC is easy in comparison (mostly).  :P
Title: Re: Advent of Code
Post by: Greenbank on 19 March, 2018, 12:27:35 pm
If you want more practice try some project euler problems, AoC is easy in comparison (mostly).  :P

Yep, and the UVA (https://uva.onlinejudge.org/). The limiting factor in all of this is free time.
Title: Re: Advent of Code
Post by: Croft on 30 November, 2018, 06:59:30 am
Anyone getting up early tomorrow morning?
Title: Re: Advent of Code
Post by: Greenbank on 30 November, 2018, 12:03:52 pm
I'll never get up early to do it, it has to fit into my day somehow. I won't get around to Sunday's until late in the evening (and I'll probably still be hungover).

I'll probably do mine first time in perl or C and then reimplement in Go. Have been meaning to look at Rust too.
Title: Re: Advent of Code
Post by: telstarbox on 30 November, 2018, 02:19:24 pm
I've solved a couple of the puzzles from last year using Excel (formulae not Visual Basic) but it's clearly not the best solution for most of them. I don't know any specific programming languages so would you recommend any particular one for having a go at this year's puzzles?
Title: Re: Advent of Code
Post by: Croft on 30 November, 2018, 03:51:42 pm
If all programming languages are new to you, I think the best choice would be the one you would most like to learn. Most are going to be languages that at least could be used to answer the AoC challenges, so really it's about what might motivate you to learn any one of them.

Some common candidates would be Python (probably the sweet spot between ease of learning and suitability for AoC-type questions), Javascript (or one of its variants such as Typescript) and Java. But there are plenty more to chose from (someone in the last couple of years set themselves the challenges of using a different language for every question - that's 50 over two years! But not something I would recommend unless you have a lot of time on your hands and feel the need to have programmed in 50 languages).
Title: Re: Advent of Code
Post by: SoreTween on 30 November, 2018, 05:19:27 pm
VBA is a perfectly decent programming language for tasks at this level, why not just use that as you have it available?  Most other languages will have a learning curve associated with the tools, excel VBA is about as simple as it gets in that respect. Plus excel formulae are well suited to some puzzles, use whatever works best for each and keep it all together in one file.  You'll soon start subliminally learning about code re-use too.

Aside: addictive innit.
Title: Re: Advent of Code
Post by: David Martin on 02 December, 2018, 02:16:14 pm
It has started off gently enough though the part twos are a bit more complex than typical from previous years. I am left thinking there must be a better/more efficient way to solve some of them.
Title: Re: Advent of Code
Post by: Ben T on 02 December, 2018, 05:29:12 pm
Day 1 part 2 looks like there might be a Dynamic Programming solution but I can't see exactly what it is at the moment.
Title: Re: Advent of Code
Post by: vorsprung on 02 December, 2018, 05:30:07 pm
Did day 1 and 2 with perl one liners.  Although the second part of day 2 was a bit long

Not sure if ICBA to carry on with this :)
Title: Re: Advent of Code
Post by: Croft on 02 December, 2018, 06:23:53 pm
Did day 1 and 2 with perl one liners.  Although the second part of day 2 was a bit long

Not sure if ICBA to carry on with this :)

You can join the YACF leaderboard with the code 48462-ea506236. And it does get quite addictive (and the puzzles more varied).
Title: Re: Advent of Code
Post by: Greenbank on 02 December, 2018, 08:35:13 pm
Caught up with day 1 and 2 now I'm back from a weekend away. Nice gentle start.

(click to show/hide)
Title: Re: Advent of Code
Post by: vorsprung on 02 December, 2018, 08:46:21 pm
Jo,

I am anonymous user #241788  apparently
Title: Re: Advent of Code
Post by: Greenbank on 02 December, 2018, 09:00:50 pm
Jo left here a long time ago.

Forgot to say, now that it has started I can now legitimately wear my AoC t-shirt.
Title: Re: Advent of Code
Post by: Greenbank on 03 December, 2018, 10:07:45 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 04 December, 2018, 09:50:11 pm
Is it just me or are they quite involved with no obvious 'simple algorithm'? Day 4 took me a while - not difficult, just involved.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 04 December, 2018, 11:45:44 pm
Yes, not a difficult algorithm but like you say involved. https://github.com/bjtaylor1/AoC2018/blob/master/Day04/Program.cs (link contains spoiler). Didn't take long but I did use classes where I normally wouldn't have to bother.
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 2018, 09:35:29 am
Day 4 wasn't about a specific algorithm, it was just about using appropriate data structures for the job. The better choice of data structure the easier it would be to implement the solution.

That and...
(click to show/hide)

With some of the puzzles there's usually only one (high-level) algorithm that will work in a reasonable time frame, and certainly only one (high-level) algorithm that would work if the input was considerably larger (which would show up the inefficient algorithm choices).

There's a number of different ways that you could have approached day 4, all perfectly valid.

I guess it highlights the fact that it's important to know when to optimise something, or choose to correct algorithm, and when you can just get away with anything that works.
Title: Re: Advent of Code
Post by: Ben T on 05 December, 2018, 11:09:01 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 2018, 02:44:42 pm
Ooh, if we're doing timings...

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 05 December, 2018, 03:09:35 pm
Hmm. Interesting. Code?
Only reason I'm curious is if single threaded, I would have expected 5.2 to take 26 times as long as 5.1. Your perl solution did, but C took only 11 times longer, so are you doing some sort of BFS/DFS type search?
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 2018, 04:51:24 pm
There's an initial cost to parsing the input string which will mean part 2 won't take exactly 26 times as long as the first.

Code and comments:
(click to show/hide)
Title: Re: Advent of Code
Post by: telstarbox on 05 December, 2018, 05:15:06 pm
For day 1 part 2 - do you need to use more than one loop of the input text? It's confusing me lots!
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 2018, 06:58:29 pm
For day 1 part 2 - do you need to use more than one loop of the input text? It's confusing me lots!

"
Note that your device might need to repeat its list of frequency changes many times before a duplicate frequency is found, and that duplicates might be found while in the middle of processing the list.
"
Title: Re: Advent of Code
Post by: David Martin on 05 December, 2018, 08:32:27 pm
My code for day 5 is obviously inefficient (it does a lot of string allocation) in Python
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 05 December, 2018, 09:04:47 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 06 December, 2018, 09:08:15 am
Day 6 was nicely different.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 06 December, 2018, 11:23:56 am
Day 6 is interesting, weirdly I found part 1 harder than part 2.
(click to show/hide)

Title: Re: Advent of Code
Post by: Greenbank on 06 December, 2018, 11:41:39 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2018, 08:52:08 am
Day 7: That was ok. Dependencies and scheduling.

What's scary, apart from the two syntax errors (missing parens), is both parts produced the correct answer first time without needing any tweaks.
Title: Re: Advent of Code
Post by: Ben T on 07 December, 2018, 12:30:09 pm
Done day 7 in Java but I might do it again in .NET with an actual thread to represent each worker.
https://github.com/bjtaylor1/AoC2018/blob/master/Day07/src/main/java/com/bjt/App.java
Title: Re: Advent of Code
Post by: Pickled Onion on 07 December, 2018, 01:17:11 pm
Day 7: That was ok. Dependencies and scheduling.

What's scary, apart from the two syntax errors (missing parens), is both parts produced the correct answer first time without needing any tweaks.

Bah. I got the code correct but typed in the wrong starting parameters for part 2 then spent ages implementing a "fix" to the logic :(
Title: Re: Advent of Code
Post by: Diver300 on 08 December, 2018, 08:45:30 am
Day 8. The first part didn't take me too long. For the second part, the example given didn't find a lot of the mistakes in my code.
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2018, 10:08:00 am
Both bits of day 8 simple, made considerably easier by the fact that perl arrays automatically return a blank entry (interpreted as 0 in an integer context) for uninitialized elements, no need for any kind of bounds checking.

Was hoping for something a bit meatier at the weekend. We'll see tomorrow...
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2018, 10:41:33 am
Day 8. The first part didn't take me too long. For the second part, the example given didn't find a lot of the mistakes in my code.
This - took a wee while for the code to run.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2018, 10:45:05 am
And day 8 - the first really fun one. Ran extremely rapidly, so much so that I thought I had an error :)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2018, 11:03:14 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2018, 12:17:46 pm
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 08 December, 2018, 12:49:16 pm
(click to show/hide)

The hardest part of that was understanding the instructions. My version was similar to yours with added fluff.

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 08 December, 2018, 11:19:47 pm
OK, here is my python version for day 8 - not so different.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2018, 10:22:33 am
Aha. Day 9 starts to make it really interesting.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2018, 10:23:35 am
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2018, 11:29:32 am
Part 1.

Frustrating out-by-one error gave the correct answer for all but one of the examples. Implementing the instructions as written, array-splicing all the way, ran in sub-second.

Part 2.

No idea. Times ten ran in about a minute. Times 100 - forget it. Can't see the pattern or formula.
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2018, 01:05:55 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 09 December, 2018, 05:29:28 pm
Part 1.

Frustrating out-by-one error gave the correct answer for all but one of the examples. Implementing the instructions as written, array-splicing all the way, ran in sub-second.

Part 2.

No idea. Times ten ran in about a minute. Times 100 - forget it. Can't see the pattern or formula.

As above.

Put a progress counter on and realised that 100 times would take hours and hours.

Had to go out and do real stuff and it was done by the time I came home.

I also tried to code a time-saving routine but I didn't get that to work before I had to go out.

edit:- corrected my time-saving routine and it ran in about 20 minutes. It is still O(n2).
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 09 December, 2018, 09:24:04 pm
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 09 December, 2018, 11:14:19 pm
(click to show/hide)

similar to mine but C++ is far easier than plain C...
https://github.com/bjtaylor1/AoC2018/blob/master/Day09/Day09.cpp
 (link contains spoiler)

runs in a fraction of a second for my x100 input.
Title: Re: Advent of Code
Post by: Diver300 on 10 December, 2018, 08:46:58 am
I found day 10 straightforward.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2018, 09:56:10 am
I found day 10 straightforward.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2018, 10:37:09 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2018, 11:12:12 am
(click to show/hide)

Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2018, 11:38:34 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2018, 11:54:13 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2018, 11:55:47 am
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 10 December, 2018, 12:03:23 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2018, 12:05:20 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2018, 12:17:48 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2018, 12:29:00 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 10 December, 2018, 10:33:22 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2018, 08:59:50 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 11 December, 2018, 09:19:59 am
Day 11 part  2
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2018, 10:33:27 am
Day 11 part  2
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 11 December, 2018, 11:18:02 am
naive implementation in C++ https://github.com/bjtaylor1/AoC2018/blob/master/Day11/Day11.cpp (link may contain spoiler)
takes about a couple or three seconds
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2018, 02:20:49 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 11 December, 2018, 02:44:55 pm
Day 10 extension  :)
Code: [Select]
position=<679, 117> velocity=<-7, -1>
position=<584, 498> velocity=<-6, -5>
position=<489, 594> velocity=<-5, -6>
position=<109, 310> velocity=<-1, -3>
position=<585, 399> velocity=<-6, -4>
position=<300, 305> velocity=<-3, -3>
position=<680, 211> velocity=<-7, -2>
position=<586, 493> velocity=<-6, -5>
position=<586, 494> velocity=<-6, -5>
position=<397, 398> velocity=<-4, -4>
position=< 18, 683> velocity=< 0, -7>
position=< 19,  18> velocity=< 0,  0>
position=<399, 399> velocity=<-4, -4>
position=< 19,  20> velocity=< 0,  0>
position=<115,  21> velocity=<-1,  0>
position=<591, 402> velocity=<-6, -4>
position=<401, 403> velocity=<-4, -4>
position=<307, 308> velocity=<-3, -3>
position=<498, 305> velocity=<-5, -3>
position=<308, 686> velocity=<-3, -7>
position=<688, 117> velocity=<-7, -1>
position=<404, 586> velocity=<-4, -6>
position=<594, 112> velocity=<-6, -1>
position=< 24, 398> velocity=< 0, -4>
position=< 24, 399> velocity=< 0, -4>
position=<215,  16> velocity=<-2,  0>
position=<216, 491> velocity=<-2, -5>
position=<121,  17> velocity=<-1,  0>
position=< 27, 588> velocity=< 0, -6>
position=< 28,  18> velocity=< 0,  0>
position=<503,  19> velocity=<-5,  0>
position=<218, 495> velocity=<-2, -5>
position=<503, 686> velocity=<-5, -7>
position=<598, 212> velocity=<-6, -2>
position=<601, 223> velocity=<-6, -2>
position=< 31, 319> velocity=< 0, -3>
position=<126, 510> velocity=<-1, -5>
position=<411, 701> velocity=<-4, -7>
position=<221, 227> velocity=<-2, -2>
position=<127, 223> velocity=<-1, -2>
position=<412, 323> velocity=<-4, -3>
position=<697, 419> velocity=<-7, -4>
position=<603, 507> velocity=<-6, -5>
position=<128, 705> velocity=<-1, -7>
position=<318, 326> velocity=<-3, -3>
position=<319, 696> velocity=<-3, -7>
position=<224, 232> velocity=<-2, -2>
position=<130, 696> velocity=<-1, -7>
position=<605, 707> velocity=<-6, -7>
position=< 36, 696> velocity=< 0, -7>
position=<226, 510> velocity=<-2, -5>
position=<606, 518> velocity=<-6, -5>
position=<322, 601> velocity=<-3, -6>
position=<702, 511> velocity=<-7, -5>
position=< 37, 139> velocity=< 0, -1>
position=<513, 601> velocity=<-5, -6>
position=<418, 511> velocity=<-4, -5>
position=<418, 140> velocity=<-4, -1>
position=< 39, 506> velocity=< 0, -5>
position=<609,  36> velocity=<-6,  0>
position=<514, 710> velocity=<-5, -7>
position=<705, 221> velocity=<-7, -2>
position=<705, 131> velocity=<-7, -1>
position=<135, 615> velocity=<-1, -6>
position=<326, 506> velocity=<-3, -5>
position=<136, 319> velocity=<-1, -3>
position=<231, 225> velocity=<-2, -2>
position=< 41, 701> velocity=< 0, -7>
position=<516, 236> velocity=<-5, -2>
position=<137,  31> velocity=<-1,  0>
position=<517, 319> velocity=<-5, -3>
position=<612, 236> velocity=<-6, -2>
position=<613, 506> velocity=<-6, -5>
position=<233, 412> velocity=<-2, -4>
position=<613,  33> velocity=<-6,  0>
position=<613,  46> velocity=<-6,  0>
position=< 50,  54> velocity=< 0,  0>
position=<145, 340> velocity=<-1, -3>
position=<525, 436> velocity=<-5, -4>
position=<620, 152> velocity=<-6, -1>
position=<525, 153> velocity=<-5, -1>
position=<240, 344> velocity=<-2, -3>
position=< 50, 155> velocity=< 0, -1>
position=<430, 156> velocity=<-4, -1>
position=<525, 442> velocity=<-5, -4>
position=<431, 624> velocity=<-4, -6>
position=<432, 624> velocity=<-4, -6>
position=<242, 245> velocity=<-2, -2>
position=< 53, 530> velocity=< 0, -5>
position=<434, 245> velocity=<-4, -2>
position=<625, 435> velocity=<-6, -4>
position=<721, 340> velocity=<-7, -3>
position=<721,  56> velocity=<-7,  0>
position=<351, 255> velocity=<-3, -2>
position=<161, 541> velocity=<-1, -5>
position=<161, 162> velocity=<-1, -1>
position=<352, 730> velocity=<-3, -7>
position=<257, 448> velocity=<-2, -4>
position=< 67, 354> velocity=< 0, -3>
position=<257, 450> velocity=<-2, -4>
position=<162, 166> velocity=<-1, -1>
position=<637, 262> velocity=<-6, -2>
position=<352, 738> velocity=<-3, -7>
position=<448, 159> velocity=<-4, -1>
position=<544, 634> velocity=<-5, -6>
position=<260,  64> velocity=<-2,  0>
position=<736, 444> velocity=<-7, -4>
position=<357,  64> velocity=<-3,  0>
position=<168, 729> velocity=<-1, -7>
position=<367, 741> velocity=<-3, -7>
position=<558, 171> velocity=<-5, -1>
position=< 83,  93> velocity=< 0,  0>
position=<274, 361> velocity=<-2, -3>
position=<369, 473> velocity=<-3, -4>
position=<465, 552> velocity=<-4, -5>
position=<180, 553> velocity=<-1, -5>
position=<370,  93> velocity=<-3,  0>
position=<181, 554> velocity=<-1, -5>
position=<561, 473> velocity=<-5, -4>
position=<752,  80> velocity=<-7,  0>
position=<372, 283> velocity=<-3, -2>
position=<468, 271> velocity=<-4, -2>
position=<373, 188> velocity=<-3, -1>
position=<184, 645> velocity=<-1, -6>
position=<469, 171> velocity=<-4, -1>
position=<279, 172> velocity=<-2, -1>
position=<754, 268> velocity=<-7, -2>
position=<659, 744> velocity=<-6, -7>
position=<184, 650> velocity=<-1, -6>
position=< 89,  81> velocity=< 0,  0>
position=<374, 747> velocity=<-3, -7>
position=<469,  83> velocity=<-4,  0>
position=<564, 559> velocity=<-5, -5>
position=<564, 750> velocity=<-5, -7>
position=<374, 656> velocity=<-3, -6>
position=<279, 562> velocity=<-2, -5>
position=<754, 373> velocity=<-7, -3>
position=<469, 374> velocity=<-4, -3>
position=<564, 565> velocity=<-5, -5>
position=<564, 186> velocity=<-5, -1>
position=<184, 472> velocity=<-1, -4>
position=< 89, 283> velocity=< 0, -2>
position=<280,  75> velocity=<-2,  0>
position=<565,  76> velocity=<-5,  0>
position=<185, 172> velocity=<-1, -1>
position=<375, 743> velocity=<-3, -7>
position=<470, 744> velocity=<-4, -7>
position=<470, 460> velocity=<-4, -4>
position=<566, 455> velocity=<-5, -4>
position=<566, 551> velocity=<-5, -5>
position=<625, 775> velocity=< 3,  2>
position=<626, 490> velocity=< 3,  5>
position=<342, 490> velocity=< 6,  5>
position=<817, 593> velocity=< 1,  4>
position=<342, 784> velocity=< 6,  2>
position=<818, 585> velocity=< 1,  4>
position=<818, 403> velocity=< 1,  6>
position=<344, 396> velocity=< 6,  6>
position=<344, 777> velocity=< 6,  2>
position=<439, 496> velocity=< 5,  5>
position=<249, 592> velocity=< 7,  4>
position=<440, 873> velocity=< 5,  1>
position=<725, 684> velocity=< 2,  3>
position=<915, 305> velocity=< 0,  7>
position=<251, 970> velocity=< 7,  0>
position=<442, 875> velocity=< 5,  1>
position=<917, 306> velocity=< 0,  7>
position=<348, 304> velocity=< 6,  7>
position=<823, 782> velocity=< 1,  2>
position=<634, 494> velocity=< 3,  5>
position=<349, 878> velocity=< 6,  1>
position=<730, 403> velocity=< 2,  6>
position=<920, 309> velocity=< 0,  7>
position=<449, 400> velocity=< 5,  6>
position=<829, 496> velocity=< 1,  5>
position=<449, 687> velocity=< 5,  3>
position=<354, 973> velocity=< 6,  0>
position=<354, 404> velocity=< 6,  6>
position=<544, 880> velocity=< 4,  1>
position=<639, 786> velocity=< 3,  2>
position=<449, 882> velocity=< 5,  1>
position=<544, 408> velocity=< 4,  6>
position=<450, 305> velocity=< 5,  7>
position=<641, 780> velocity=< 3,  2>
position=<927, 400> velocity=< 0,  6>
position=<453, 590> velocity=< 5,  4>
position=<359, 305> velocity=< 6,  7>
position=<359, 401> velocity=< 6,  6>
position=<740, 401> velocity=< 2,  6>
position=<836, 782> velocity=< 1,  2>
position=<362, 783> velocity=< 6,  2>
position=<362, 879> velocity=< 6,  1>
position=<742, 785> velocity=< 2,  2>
position=<743, 974> velocity=< 2,  0>
position=<933, 975> velocity=< 0,  0>
position=<743, 311> velocity=< 2,  7>
position=<269, 973> velocity=< 7,  0>
position=<934, 596> velocity=< 0,  4>
position=<554, 597> velocity=< 4,  4>
position=<839, 978> velocity=< 1,  0>
position=<650, 783> velocity=< 3,  2>
position=<461, 783> velocity=< 5,  2>
position=<937, 878> velocity=< 0,  1>
position=<558, 403> velocity=< 4,  6>
position=<844, 973> velocity=< 1,  0>
position=<655, 498> velocity=< 3,  5>
position=<941, 879> velocity=< 0,  1>
position=<562, 784> velocity=< 4,  2>
position=<658, 689> velocity=< 3,  3>
position=<658, 785> velocity=< 3,  2>
position=<469, 691> velocity=< 5,  3>
position=<849, 977> velocity=< 1,  0>
position=<671, 498> velocity=< 3,  5>
position=<576, 404> velocity=< 4,  6>
position=<291, 785> velocity=< 7,  2>
position=<861, 501> velocity=< 1,  5>
position=<482, 972> velocity=< 5,  0>
position=<387, 692> velocity=< 6,  3>
position=<578, 686> velocity=< 4,  3>
position=<958, 883> velocity=< 0,  1>
position=<389, 591> velocity=< 6,  4>
position=<389, 979> velocity=< 6,  0>
position=<579, 505> velocity=< 4,  5>
position=<295, 401> velocity=< 7,  6>
position=<580, 505> velocity=< 4,  5>
position=<866, 876> velocity=< 1,  1>
position=<866, 315> velocity=< 1,  7>
position=<677, 306> velocity=< 3,  7>
position=<867, 505> velocity=< 1,  5>
position=<393, 686> velocity=< 6,  3>
position=<583, 409> velocity=< 4,  6>
position=<393, 315> velocity=< 6,  7>
position=<394, 401> velocity=< 6,  6>
position=<964, 972> velocity=< 0,  0>
position=<774, 974> velocity=< 2,  0>
position=<394, 314> velocity=< 6,  7>
position=<775, 879> velocity=< 2,  1>
position=<680, 883> velocity=< 3,  1>
position=<490, 979> velocity=< 5,  0>
position=<586, 404> velocity=< 4,  6>
position=<396, 405> velocity=< 6,  6>
position=<871, 786> velocity=< 1,  2>
position=<871, 977> velocity=< 1,  0>
position=<682, 501> velocity=< 3,  5>
position=<588, 406> velocity=< 4,  6>
position=<778, 312> velocity=< 2,  7>
position=<589, 502> velocity=< 4,  5>
position=<495, 977> velocity=< 5,  0>
position=<506, 318> velocity=< 5,  7>
position=<792, 508> velocity=< 2,  5>
position=<603, 401> velocity=< 4,  6>
position=<698, 687> velocity=< 3,  3>
position=<413, 878> velocity=< 6,  1>
position=<413, 974> velocity=< 6,  0>
position=<603, 785> velocity=< 4,  2>
position=<793, 982> velocity=< 2,  0>
position=<889, 971> velocity=< 1,  0>
position=<509, 500> velocity=< 5,  5>
position=<604, 691> velocity=< 4,  3>
position=<414, 407> velocity=< 6,  6>
position=<794, 788> velocity=< 2,  2>
position=<699, 697> velocity=< 3,  3>
position=<415, 306> velocity=< 6,  7>
position=<795, 599> velocity=< 2,  4>
position=<700, 792> velocity=< 3,  2>
position=<701, 496> velocity=< 3,  5>
position=<416, 410> velocity=< 6,  6>
position=<891, 316> velocity=< 1,  7>
position=<797, 505> velocity=< 2,  5>
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2018, 05:09:30 pm
Day 10 extension  :)

Excellent, found it but will need to work on an algorithm to detect when to stop as I had to manually step through once in the right area to get the exact frame.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 11 December, 2018, 09:01:32 pm
Day 10 extension  :)

Excellent, found it but will need to work on an algorithm to detect when to stop as I had to manually step through once in the right area to get the exact frame.

What does it say then? And at what time (frame)?


(click to show/hide)

You don't need all that - see #669  ...  https://yacf.co.uk/forum/index.php?topic=94710.msg2349625#msg2349625

Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2018, 11:18:15 pm
What does it say then? And at what time (frame)?

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 12 December, 2018, 12:24:38 am
Day 11 was nice. I have only got round to it but looked at it briefly at Makerspace tonight. One of my fellow hackers had done it naively and it took a while, so having the benefit of seeing part 2 I realised that
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 12 December, 2018, 08:15:37 am
Day 12. Can't see why my part 2 is wrong.
Title: Re: Advent of Code
Post by: Diver300 on 12 December, 2018, 08:27:40 am
Day 12. Can't see why my part 2 is wrong.
Nor me.
Title: Re: Advent of Code
Post by: Greenbank on 12 December, 2018, 09:08:58 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 12 December, 2018, 09:10:52 am
Day 12. Can't see why my part 2 is wrong.
Nor me.
(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 12 December, 2018, 05:19:05 pm
(click to show/hide)

Nice.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 12 December, 2018, 10:50:26 pm
(click to show/hide)

Nice.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2018, 12:00:34 am
(click to show/hide)

Nice.

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2018, 12:06:17 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2018, 01:13:11 am
Got it - massive speed up.
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2018, 08:10:20 am
OK, not quite enough
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2018, 09:37:27 am
(click to show/hide)

It's not the answer but it will lead you in the right direction, up to you whether you read it obviously.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2018, 09:48:31 am
Day 13 done.

(click to show/hide)

Looking forward to the first pseudo-assembly-language type question of 2018. I liked those from previous years.
Title: Re: Advent of Code
Post by: Croft on 13 December, 2018, 10:26:02 am

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 13 December, 2018, 12:58:04 pm
(click to show/hide)

It's not the answer but it will lead you in the right direction, up to you whether you read it obviously.
interesting idea. Will try that.
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2018, 08:17:01 am
Day 14, part 2
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 14 December, 2018, 11:46:05 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2018, 08:45:52 pm
(click to show/hide)

It's not the answer but it will lead you in the right direction, up to you whether you read it obviously.
interesting idea. Will try that.
Been rather busy so AoC has been on hold.
(click to show/hide)

Now onward and upward.
Title: Re: Advent of Code
Post by: David Martin on 14 December, 2018, 10:48:23 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2018, 10:48:14 am
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 15 December, 2018, 10:52:38 am
Day 15. It has taken so long to read the question and it will be a long time to code. Other things to do so I might come back to it later. Trying to think of how I can avoid calculating a shortest path every time, though it is easy to only calculate one per round per enemy.

Later
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2018, 08:23:47 pm
Oof, hungover and family around but managed to get Day 15 done.

Hours. Hours and hours. Oof.

Will rework it tomorrow if/when I have time.
Title: Re: Advent of Code
Post by: Greenbank on 16 December, 2018, 03:12:29 pm
Day 16: Wasted far too long chasing a silly bug in the implementation of one of the opcodes which made part (a) give the wrong answer.

Guessed at what part (b) would be so implemented part (a) in a way that would make it easier without a load of rework.
Title: Re: Advent of Code
Post by: Ben T on 16 December, 2018, 04:29:02 pm
My code for Day 15's horrible. Lots of nested loops with break-outs, inline functions and branches. Eugh.   ::-) ;D
(click to show/hide)
Title: Re: Advent of Code
Post by: David Martin on 16 December, 2018, 08:29:08 pm
Horrible cold so I have put day 15 and 16 on hold for the moment. Will return when my brain does.
Title: Re: Advent of Code
Post by: Greenbank on 16 December, 2018, 11:52:23 pm
My code for Day 15's horrible. Lots of nested loops with break-outs, inline functions and branches. Eugh.   ::-) ;D
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2018, 11:52:29 am
Missing something in Day 17. Part (a) answer is correct but part (b) is wrong and can't see why.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 17 December, 2018, 02:31:07 pm
My code for Day 15's horrible. Lots of nested loops with break-outs, inline functions and branches. Eugh.   ::-) ;D
(click to show/hide)
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2018, 03:47:48 pm
Day 15: Some people go a little over the top on their visualisations:

https://www.reddit.com/r/adventofcode/comments/a6sej7/day_15_unity_visualization/
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2018, 08:54:55 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 18 December, 2018, 10:21:45 am
Nice to have a relatively simple one again today. Lucky as I have lots of real work to do!
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2018, 09:42:32 am
I suppose I did ask for a psuedo assembly language one.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2018, 07:05:16 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2018, 11:19:37 am
Interesting one today, but a bit of a slog to the answer.

(click to show/hide)

The recent challenges have seemed harder than in recent years, I wonder if this is responsible for, what looks like, a drop in participation.
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2018, 11:57:09 am
Also liked this touch:

"Clearly, the Elves who wrote this system were worried that someone might introduce a bug while trying to emulate this system with a scripting language."

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 21 December, 2018, 12:00:10 pm
Still stuck on day 17, havent' tried any subsequent ones - have had to go out to the shops for new jelly and nails as I keep running out, and start again in a new room with a fresh ceiling.
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2018, 03:02:13 pm
Still stuck on day 17, havent' tried any subsequent ones - have had to go out to the shops for new jelly and nails as I keep running out, and start again in a new room with a fresh ceiling.

Ooh. What's the problem? Wrong answer, not fast enough or just can't get it to work properly at all?

I had a bug in mine where it wouldn't accept my answer for part (b), when I eventually fixed it I got the right answer for part (b) but the answer it gave for part (a) changed as well but my original (now incorrect) answer for part (a) was accepted.
Title: Re: Advent of Code
Post by: Ben T on 21 December, 2018, 08:07:53 pm
Still stuck on day 17, havent' tried any subsequent ones - have had to go out to the shops for new jelly and nails as I keep running out, and start again in a new room with a fresh ceiling.

Ooh. What's the problem? Wrong answer, not fast enough or just can't get it to work properly at all?

I had a bug in mine where it wouldn't accept my answer for part (b), when I eventually fixed it I got the right answer for part (b) but the answer it gave for part (a) changed as well but my original (now incorrect) answer for part (a) was accepted.

I've come up with an answer but it doesn't accept it at all.
I have produced a pretty picture of what it looks like: https://1drv.ms/u/s!AtNSfl0sxZVlgZIQQ8xv9FsIru8Jww

I have got a loop which I can't figure out how to exit, but at the point where it is not finding any new tiles the situation is as the picture above (should open in paint or simple bmp editor), and it gets to that situation in under a second.
I guessed
(click to show/hide)

Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2018, 08:25:11 pm
FWIW, my program agrees with yours for your input. I get the same answer and I can't see anything wrong in the output.

My previous version the program also gives the same answer (even though it exhibits a bug with my input).

I'd move on.
Title: Re: Advent of Code
Post by: Ben T on 21 December, 2018, 08:35:12 pm
FWIW, my program agrees with yours for your input. I get the same answer and I can't see anything wrong in the output.

My previous version the program also gives the same answer (even though it exhibits a bug with my input).

I'd move on.

Groan............... found it,
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 21 December, 2018, 08:40:17 pm
Ah - part 2 was easy for my algorithm.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2018, 08:49:26 pm
Groan............... found it,
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 22 December, 2018, 11:10:25 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 23 December, 2018, 11:04:15 am
Ooh, day 23 part b looks like a stinker, have ideas and not going to look anywhere for hints. Might take a while!

[EDIT] Got the answer for part b but not satisfied with my method at all. It doesn't work at all on the simple example given in the problem.

Some details in this spoiler.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 23 December, 2018, 06:55:44 pm
Quite enjoyed day 19.
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 23 December, 2018, 08:34:17 pm
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2018, 03:27:03 pm
Done day 21... dog alone knows what the algorithm is trying to do, unlike 19 that there actually seems to be a point to it.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 24 December, 2018, 07:47:23 pm
Ooh, day 23 part b looks like a stinker, have ideas and not going to look anywhere for hints. Might take a while!
[EDIT] Got the answer for part b but not satisfied with my method at all. It doesn't work at all on the simple example given in the problem.
My method was something similar but opposite results - it worked for the example but unfortunately not the real data  :(
Title: Re: Advent of Code
Post by: Ben T on 25 December, 2018, 07:24:28 pm
Ooh, day 23 part b looks like a stinker, have ideas and not going to look anywhere for hints. Might take a while!

[EDIT] Got the answer for part b but not satisfied with my method at all. It doesn't work at all on the simple example given in the problem.

Some details in this spoiler.

(click to show/hide)

To be honest I had absolutely no idea.
However if you read this (contains spoiler) (https://raw.githack.com/ypsu/experiments/master/aoc2018day23/vis.html), the methodology makes perfect sense and from the description of the method, I was able to code it in C++ (https://github.com/bjtaylor1/AoC2018/blob/master/Day23/Day23.cpp) purely from my understanding of the method, and without looking at his algorithm. But I've got to admit, I'm not sure I would have come up with that idea on my own.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 26 December, 2018, 11:31:19 am
Ooh, day 23 part b looks like a stinker, have ideas and not going to look anywhere for hints. Might take a while!
[EDIT] Got the answer for part b but not satisfied with my method at all. It doesn't work at all on the simple example given in the problem.
My method was something similar but opposite results - it worked for the example but unfortunately not the real data  :(
Finally got it.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 27 December, 2018, 11:53:38 am
Finished now (didn't get a chance to do more than a few minutes during the last 3 days).

Wasted a bit of time with a misreading of the 24th but got it in 10 minutes this morning and part 2 followed on simply. Not a big fan of big wordy plods like this, but they're quite representative of real world coding with slightly imprecise specs and long slogs of boring programming!
Title: Re: Advent of Code
Post by: Ben T on 27 December, 2018, 05:08:35 pm
Finished now (didn't get a chance to do more than a few minutes during the last 3 days).

Wasted a bit of time with a misreading of the 24th but got it in 10 minutes this morning and part 2 followed on simply. Not a big fan of big wordy plods like this, but they're quite representative of real world coding with slightly imprecise specs and long slogs of boring programming!

 :-\ :-\ Not sure where you work - but can I have a job there?!

Whilst I think it's nice that AoC has presented a dimension of difficulty in terms of having a verbose, complicated spec - I would disagree that they're representative - I would say that AoC specs are far, far better written and more concise than real world specs.
 :)

e.g. AoC
Spec: "During the target selection phase, each group attempts to choose one target. In decreasing order of effective power, groups choose their targets; in a tie, the group with the higher initiative chooses first. The attacking group chooses to target the group in the enemy army to which it would deal the most damage (after accounting for weaknesses and immunities, but not accounting for whether the defending group has enough units to actually receive all of that damage)."

Real world would be:
Spec: "The strongest [sic] attack first."
Dev: " 'Strongest' meaning? The one with the most power, or the most units?"
Sponsor: "Oh, er... the one with the most power."
Dev: "Ok."
Later:
Sponsor: "This is a BUG! Unit C has attacked before unit D!"
Dev: "Yes, well, they've both got the same power. As designed."
Sponsor: "Yes but D has got higher initiative!"
Dev: "You didn't say anything about higher initiative attacking first in the event of a tie."
Sponsor: "Well, that should have been obvious!"

Recent AoC problems like Day 24 test the skill of data modelling, as well as just procedural logic.

I don't think any of the specs have been ambiguous. Some have been confusing, particularly Day 17, which required reading every single bit of it very very carefully, with crucial detail being in the letter rather than the spirit of the rules, but I don't think any have actually required a leap of faith or reading between the lines, or been noticeably ambiguous.

Clarifications like 'not accounting for whether the defending group has enough units to actually receive all of that damage' are the exact sort of things that are missing from real world specs as it is the sort of thing only a developer would think about.
In reality, if you were programming a real army, some devs might decide that the sponsor wouldn't want to see a powerful unit "waste" an attack on one that is already nearly dead, and insert that into the logic, even though the sponsor didn't specify that - but other devs might not. Here, he's thought about it from the programmer's point of view and clarified it.
Title: Re: Advent of Code
Post by: Ben T on 27 December, 2018, 11:44:40 pm
What was a bit sneaky though was
(click to show/hide)
Title: Re: Advent of Code
Post by: SoreTween on 06 January, 2019, 10:39:20 am
(click to show/hide)

It's not the answer but it will lead you in the right direction, up to you whether you read it obviously.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 08 January, 2019, 11:32:22 am
"271 people have gotten all 200 stars over the four years of #AdventOfCode."

https://twitter.com/ericwastl/status/1082420178510667781

:smug:
Title: Re: Advent of Code
Post by: Greenbank on 22 November, 2019, 09:04:53 am
9 days to go until #AdventOfCode 2019

(Already donated so I have my AOC++ badge for 2019).
Title: Re: Advent of Code
Post by: Greenbank on 01 December, 2019, 09:42:50 am
Day 1 2019.

Didn't read part b properly (as usual) and made the expected mistake, easily fixed though.

Find the first few days a bit underwhelming after the anticipation, looking forward to a nice meaty problem.
Title: Re: Advent of Code
Post by: Greenbank on 02 December, 2019, 09:26:17 am
Day 2 2019 (no need for spoiler tags yet).

"Good, the new computer seems to be working correctly! Keep it nearby during this mission - you'll probably use it again. Real Intcode computers support many more features than your new one, but we'll let you know what they are as you need them."

I guess this is going to be one of the themes for this year. I'll spend a bit of time making sure it's nicely cleaned up and ready for inclusion in the aoc/2019 directory rather than buried in a specific day's directory.
Title: Re: Advent of Code
Post by: Greenbank on 03 December, 2019, 10:50:40 am
Day 3 2019 (no spoiler tags required)

Today's small delay was caused by a typo in some regex. I initially had /^U(\d)+$/ instead of /^U(\d+)$/ when extracting the number of steps on each instruction (and copy-pasta'd for the other directions). Thankfully the basic test cases provided made it very easy to spot that there was a problem.
Title: Re: Advent of Code
Post by: vorsprung on 03 December, 2019, 05:27:53 pm
ICBA this year.  I am interviewing at the moment and have various "tech tasks" to do of random IT puzzles

"no, we don't mind what skills you have.  We are looking for a good attitude and general grasp.  Here's the tech task, should take 4-5 hours"  Yeah right 4-5 hours if I had EXACTLY the same experience as your inhouse staff :(
Title: Re: Advent of Code
Post by: Pickled Onion on 03 December, 2019, 06:32:07 pm
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.
Title: Re: Advent of Code
Post by: vorsprung on 03 December, 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!
Title: Re: Advent of Code
Post by: Greenbank on 03 December, 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. ;)
Title: Re: Advent of Code
Post by: Ben T on 04 December, 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.

Title: Re: Advent of Code
Post by: Greenbank on 04 December, 2019, 09:30:21 am
28 seconds?

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 04 December, 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
Title: Re: Advent of Code
Post by: Greenbank on 04 December, 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.)
Title: Re: Advent of Code
Post by: Ben T on 04 December, 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)
Title: Re: Advent of Code
Post by: freeflow on 04 December, 2019, 04:59:47 pm
For me day 5 is in 12 hours time.  Passwords with doubles was day 4.
Title: Re: Advent of Code
Post by: Greenbank on 04 December, 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.)
Title: Re: Advent of Code
Post by: Ben T on 04 December, 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)
Title: Re: Advent of Code
Post by: Greenbank on 04 December, 2019, 11:07:42 pm
Only because someone suggested it could be done with grep:-

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 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.
Title: Re: Advent of Code
Post by: Ben T on 05 December, 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:
Title: Re: Advent of Code
Post by: freeflow on 05 December, 2019, 03:27:02 pm
I might observe that Day 5 instructions include some artful misdirection


(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 2019, 03:47:45 pm
I might observe that Day 5 instructions include some artful misdirection


(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: freeflow on 05 December, 2019, 03:52:08 pm
No.  5 & 6
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 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.
Title: Re: Advent of Code
Post by: Ben T on 05 December, 2019, 05:21:50 pm
I might observe that Day 5 instructions include some artful misdirection


(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 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.
Title: Re: Advent of Code
Post by: freeflow on 05 December, 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.
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 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.
Title: Re: Advent of Code
Post by: Ben T on 05 December, 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.
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 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".
Title: Re: Advent of Code
Post by: Ben T on 05 December, 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
Title: Re: Advent of Code
Post by: Greenbank on 06 December, 2019, 09:30:17 am
Yet more "READ IT PROPERLY" fun today.

(click to show/hide)
Title: Re: Advent of Code
Post by: freeflow on 06 December, 2019, 04:41:41 pm
Yup -2 and understanding the input data in part 2 finally got me there.
Title: Re: Advent of Code
Post by: Croft on 07 December, 2019, 10:29:05 am
Da7 7:

You see the future!


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.

You see the future (almost)!
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2019, 11:33:30 am
Indeed, but it was a nice twist on that.

My code to implement it was hideous.

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 07 December, 2019, 07:15:24 pm
Interesting.

(click to show/hide)
Title: Re: Advent of Code
Post by: freeflow on 08 December, 2019, 05:49:59 am
Bum. I am stymied on Day 7 Part 2. All current and historical tests for my computer give the correct results. Day 7 Part1 was correct at the first attempt. Part 2 tests pass. But part2  input doesn't give the correct answer. Pointers to wrinkles I may have missed are most welcome.

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 08 December, 2019, 07:31:23 am
I get a smaller number.

Do your tests include a full run of all permutations on the last example, or just the permutation shown?
Title: Re: Advent of Code
Post by: freeflow on 08 December, 2019, 07:49:15 am
That is the maximum value I get when I run all 120 permutations of "567892".  Advent of Code says my result is too low.
Title: Re: Advent of Code
Post by: freeflow on 08 December, 2019, 10:14:31 am
Whizzed through day 8 :-D
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2019, 05:20:23 pm
If you get a different answer could you please say so BUT NOT WHAT YOUR ANSWER IS.  Thanks

I too get a different (lower) answer. If it's any help here's my input and what I get as an answer (as that isn't giving you the answer to your problem).

Code: [Select]
3,8,1001,8,10,8,105,1,0,0,21,46,55,68,89,110,191,272,353,434,99999,3,9,1002,9,3,9,1001,9,3,9,102,4,9,9,101,4,9,9,1002,9,5,9,4,9,99,3,9,102,3,9,9,4,9,99,3,9,1001,9,5,9,102,4,9,9,4,9,99,3,9,1001,9,5,9,1002,9,2,9,1001,9,5,9,1002,9,3,9,4,9,99,3,9,101,3,9,9,102,3,9,9,101,3,9,9,1002,9,4,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,99,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,99,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,99

Code: [Select]
$ ./7d.pl | sort -rn -k3 | head
57968 gives 3745599
57698 gives 3742019
75968 gives 3689151
75698 gives 3685571
57986 gives 3671647

And here are the values passed between each amplifier for phase arrangement 57968:-

(click to show/hide)

Again, this is the answer to my input for day 7 not yours!
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2019, 05:21:51 pm
Day 8 nice and quick although there was a ~7 hour gap between part 1 and part 2 as I didn't get time to finish part 2 before I had to go out and was out most of the day.
Title: Re: Advent of Code
Post by: freeflow on 08 December, 2019, 06:45:04 pm
Thanks.  I get a different number to you so it seems I have a logic problem in by computer.  I also downloaded a solution in python which gave a different number to my computer.  So a bit of head scratching is the order of the day.
Title: Re: Advent of Code
Post by: freeflow on 09 December, 2019, 08:29:51 am
Day 9 completed successfully, but my computer is still giving the wrong result for Day7Part2
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2019, 09:05:31 am
Opposite problem for me, and it wasn't fixed in the 15 minutes I have this morning so I'll have to pick it up later this afternoon when I've done all of my chores.

[EDIT] Spotted it, fixed and day 9 part 2 ran without problems!
Title: Re: Advent of Code
Post by: freeflow on 09 December, 2019, 10:19:55 am
I'm working in VBA so much of today's problem solving time was spent ensuring appropriate variables were LongLong rather than Long. :demon:
Title: Re: Advent of Code
Post by: Ben T on 09 December, 2019, 12:43:09 pm
foxed by day 8 part 2  :-\
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 09 December, 2019, 01:02:42 pm
Bum. I am stymied on Day 7 Part 2. All current and historical tests for my computer give the correct results. Day 7 Part1 was correct at the first attempt. Part 2 tests pass. But part2  input doesn't give the correct answer. Pointers to wrinkles I may have missed are most welcome.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2019, 01:13:37 pm
foxed by day 8 part 2  :-\
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 09 December, 2019, 04:37:39 pm
foxed by day 8 part 2  :-\
(click to show/hide)
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: freeflow on 09 December, 2019, 06:18:26 pm
Finally got the correct answer for Day 7 part 2.  The logic in the computer was perfectly fine but obviously that was where I was spending my time.  The error was in how I collected the output when the computer was run in loop mode.  A very silly logic error but depressingly elusive.
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2019, 09:44:45 pm
Day 9: very clever. In "test mode" with input=1 it output 2 opcodes which pointed straight at the places where I had left the original day 5 code for finding the offset.
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2019, 08:34:06 am
I've got into a bad habit of checking the leaderboards of the top 100 to see how tricky the upcoming day is, the times shown there give me an idea how tough it's going to be.

I fear for the days where the top 100 hasn't been solved by the time I get everything else done (school run this morning) before I can look at it, hasn't happened yet.

Not that bad today but part 2 is obviously relatively involved.
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2019, 09:41:23 am
That was fun.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2019, 10:54:20 am
Day 9 a bit bloody tenuous to say the least... had to look on the reddit and instantly found a reference to "the 203 error" which was what I had run into, despite passing all the tests. But quite clever how it actually tells you which instruction there is a problem with. I thought by mention of "large numbers" but no indication as to how large, he might make the tests handle >32bit, but <64 bit numbers but deliberately require >64 bit numbers in the final solution, I was braced for that... but seemingly not for slight misinterpretation of how read/write parameters are handled.
Don't think I've got time to do day 10 today, spent long enough not doing actual work as it is :)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2019, 02:06:19 pm
BTW, Eric's talk about AoC is well worth a watch: https://www.youtube.com/watch?v=gibVyxpi-qA

Will be late to Day 11 thanks to school running club and then an eye test.
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2019, 12:28:22 pm
Day 11. Found a bug in opcode 3 of all places. Left wondering how it ever worked. Done though, will go through and rejig things properly as this Intcode computer is not going anywhere.
Title: Re: Advent of Code
Post by: Greenbank 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?
Title: Re: Advent of Code
Post by: Greenbank 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.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2019, 10:18:45 am
Day 13 is awesome.
Title: Re: Advent of Code
Post by: Greenbank 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
Title: Re: Advent of Code
Post by: Greenbank 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.
Title: Re: Advent of Code
Post by: Ben T 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 :)
Title: Re: Advent of Code
Post by: Greenbank 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)
Title: Re: Advent of Code
Post by: Greenbank on 16 December, 2019, 04:18:04 pm
Day 16.

Easy!

What? Eh? What?! Ah.
Title: Re: Advent of Code
Post by: Greenbank on 16 December, 2019, 06:47:22 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: freeflow 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.
Title: Re: Advent of Code
Post by: Greenbank 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)
Title: Re: Advent of Code
Post by: Greenbank 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)
Title: Re: Advent of Code
Post by: Greenbank 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)
Title: Re: Advent of Code
Post by: freeflow 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.
Title: Re: Advent of Code
Post by: Greenbank on 18 December, 2019, 02:18:28 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2019, 09:45:30 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank 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.)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2019, 01:26:57 pm
(click to show/hide)

Expecting a horror show tomorrow or Sunday though.
Title: Re: Advent of Code
Post by: Greenbank 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.
Title: Re: Advent of Code
Post by: Greenbank 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)
Title: Re: Advent of Code
Post by: Greenbank on 22 December, 2019, 02:25:54 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2019, 11:23:35 pm
day 16 been grriiiiiiinnnnding away since, well, day 16. Think I might have to stop it.  :-[
Title: Re: Advent of Code
Post by: Ben T 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)
Title: Re: Advent of Code
Post by: Davef 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.
Title: Re: Advent of Code
Post by: Greenbank 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 )
Title: Re: Advent of Code
Post by: Greenbank on 04 January, 2020, 09:37:40 am
(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 )

As of recently only 283 have all 250 stars:-

https://twitter.com/ericwastl/status/1213134461229031424
Title: Re: Advent of Code
Post by: Ashaman42 on 31 March, 2020, 10:57:44 am
Well I made a start at AoC 2019 in January to learn some new skills for work and to occupy slow spots at work. Got halfway through Day 3 and stalled somewhat - mostly due to work getting busy.

Well given the current lockdown and the fact I can't do much of my job from home I started again from scratch. I'm up to Day 5 now and plodding away. I don't really know how to program so it's a lot of Googling and head scratching. I'm pretty sure in days 1 - 3 I made exactly the same mistakes as I managed the first time round  ::-)

I'm also fairly sure that some of what I'm doing is completely the opposite of best practise but there we go. Definitely doing something wrong as each run of my day 3 solution with the full input takes well over an hour to chug through.

Currently programming in C++ via Visual Studio Community 2019.
Title: Re: Advent of Code
Post by: Greenbank on 31 March, 2020, 11:08:27 am
Definitely doing something wrong as each run of my day 3 solution with the full input takes well over an hour to chug through.

If you can describe here in words how your algorithm works then someone here can give pointers...
Title: Re: Advent of Code
Post by: Ashaman42 on 31 March, 2020, 11:10:30 am
Cheers  :thumbsup:

I'll probably take you up on that at some point. Probably not today as I'm hip deep in day 5 and I think I'm getting somewhere with it. May as well keep on when I'm on a roll  ;D
Title: Re: Advent of Code
Post by: vorsprung on 31 March, 2020, 11:52:57 am
Definitely doing something wrong as each run of my day 3 solution with the full input takes well over an hour to chug through.

If you can describe here in words how your algorithm works then someone here can give pointers...

given that he is coding in C++ pointers are the problem
Title: Re: Advent of Code
Post by: Davef on 31 March, 2020, 01:40:33 pm
If you get stuck I have all 49 solutions in  Microsoft c++ and can give some hints.

I also have some ludicrously large intcode programs.


Sent from my iPad using Tapatalk
Title: Re: Advent of Code
Post by: Greenbank on 12 November, 2020, 07:30:16 am
Not long to go...I hope Eric has been busy.
Title: Re: Advent of Code
Post by: Ben T on 12 November, 2020, 01:30:36 pm
could do with it this month really :)
Title: Re: Advent of Code
Post by: Greenbank on 30 November, 2020, 02:36:51 pm
Tomorrow...
Title: Re: Advent of Code
Post by: R_nger on 01 December, 2020, 08:33:07 am
Broken ?

"We'll be right back!"
Title: Re: Advent of Code
Post by: Greenbank on 01 December, 2020, 08:39:16 am
I think the input generator is broken for some people.

Ah, he's posted over on reddit to say it was just his AWS instances running out of resources and shutting down. All due to the site being utterly swamped in the first few seconds after day 1 went live.

(I'm happy that happens at 5am UK time as I'm not interested in trying to get into the top 100.)

I got my input and was able to get both stars.
Title: Re: Advent of Code
Post by: Diver300 on 01 December, 2020, 11:26:42 am
Eric really has managed to set up the perfect conditions for an unintentional DDoS attack on his servers.

I thought that today's puzzle was a bit simple.
Title: Re: Advent of Code
Post by: Greenbank on 01 December, 2020, 11:54:02 am
The first two or three days are usually very gentle.

There's still plenty of scope for different approaches to even this simple problem though, some more efficient than others.

(Mine runs nigh on instantaneously even when I tell it to look for more than 4 numbers that add to 2020 - there is a 4 number solution for my input - no solutions other numbers though.)
Title: Re: Advent of Code
Post by: grams on 01 December, 2020, 01:00:44 pm
I did mine in Google Sheets with Vlookup. Managed to bodge it to find the four number solution too.

It runs with much fan noise and beachballing, like all great programs.
Title: Re: Advent of Code
Post by: Ben T on 01 December, 2020, 01:04:26 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 01 December, 2020, 02:40:03 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 01 December, 2020, 02:56:00 pm
I am redoing it in nostalgic intcode.
Title: Re: Advent of Code
Post by: Davef on 01 December, 2020, 03:33:54 pm
http://cloud.tapatalk.com/s/5fc661d8a8566/day1.txt (http://cloud.tapatalk.com/s/5fc661d8a8566/day1.txt)
If anyone wants to test their intcode computer from last year attached is this years day1 part 1 solution in intcode. It reads 200 lines from stdin and then produces the answer. It is large as it includes a pile of unneeded utility code.
Title: Re: Advent of Code
Post by: Pingu on 01 December, 2020, 05:02:31 pm
Day 1 done. Maybe I'll quit while I'm ahead.
Title: Re: Advent of Code
Post by: Greenbank on 02 December, 2020, 08:15:52 am
Once again it pays to read the problem description, including the bit highlighted in bold.
Title: Re: Advent of Code
Post by: Ben T on 02 December, 2020, 10:29:33 am
two lines of easily maintainable code  ;)
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 02 December, 2020, 11:08:15 am
Another victory for Google Sheets:
https://docs.google.com/spreadsheets/d/17LXRC-kEewCl3K1mvA1dzWJE8geZx9bK78o2fClZc0g
Title: Re: Advent of Code
Post by: freeflow on 02 December, 2020, 01:15:30 pm
Bah humbug.  Day2 with VBA using an interface and injected code!!!!!


Title: Re: Advent of Code
Post by: Greenbank on 02 December, 2020, 02:11:35 pm
Some ugly / semi-minimalist perl:-

(click to show/hide)

(I know it can be code golfed to a lot less than that, but that's about as minimalist as I'd go before it starts to become a puzzle rather than recognisable code.)
Title: Re: Advent of Code
Post by: Pingu on 02 December, 2020, 06:08:22 pm
Day 2 done  :thumbsup: I'm not brave enough to share my crappy JS coding though  :)
Title: Re: Advent of Code
Post by: tonycollinet on 02 December, 2020, 08:27:53 pm
Well this is rather fun. Not done any coding outside of simple VBA for years (about 20), and I'm trying this as a vehicle for learning python.

Day one:
(click to show/hide)


***************
And day 2: (for day two, I learned to read the input data from a text file into a list rather than declaring the data in the list)
(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 02 December, 2020, 08:38:58 pm
Some ugly / semi-minimalist perl:-

(click to show/hide)

(I know it can be code golfed to a lot less than that, but that's about as minimalist as I'd go before it starts to become a puzzle rather than recognisable code.)

Call that recognisable? Let me give you a layman's  ;D ;D ;D :) ::-) ::-) ::-) ;D ;D ;D :facepalm:
Title: Re: Advent of Code
Post by: Greenbank on 03 December, 2020, 11:15:27 am
(click to show/hide)

Still waiting for the first nasty one.
Title: Re: Advent of Code
Post by: freeflow on 03 December, 2020, 04:57:01 pm
Yes.  The introduction is quite gentle this year.
Title: Re: Advent of Code
Post by: Pingu on 03 December, 2020, 06:16:09 pm
Day 3 done  :)

I've been putting my amateur JS code efforts here: http://www.pinniped.plus.com/AoC/index.htm
Title: Re: Advent of Code
Post by: Pingu on 03 December, 2020, 06:31:50 pm
Today's lesson is arrays and the modulo operator...

Could you put hints in a Spoiler, please?
Title: Re: Advent of Code
Post by: tonycollinet on 03 December, 2020, 08:14:22 pm
Day 3 done  :)

I've been putting my amateur JS code efforts here: http://www.pinniped.plus.com/AoC/index.htm

There is no source to view (firefox)
Title: Re: Advent of Code
Post by: Pingu on 03 December, 2020, 08:17:53 pm
Day 3 done  :)

I've been putting my amateur JS code efforts here: http://www.pinniped.plus.com/AoC/index.htm

There is no source to view (firefox)

Ctrl-u or right-click > View source
Title: Re: Advent of Code
Post by: tonycollinet on 03 December, 2020, 11:18:38 pm
Ahhhhh - of course  ;D
Title: Re: Advent of Code
Post by: Greenbank on 04 December, 2020, 11:00:06 am
Today's lesson is arrays and the modulo operator...

Could you put hints in a Spoiler, please?

Ah, ok, sorry, will do.

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 04 December, 2020, 11:41:23 am
Found day 4 a bit boring to be honest.
Reading arbitrary rules and writing validation code is a bit too much like actual work... :-\
Title: Re: Advent of Code
Post by: Ben T on 04 December, 2020, 11:43:37 am
(click to show/hide)

Quote
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 04 December, 2020, 02:01:51 pm
Still sticking with Google Sheets until they force me to stop.

Day 3:
https://docs.google.com/spreadsheets/d/1­7_5yPJ8oNENFlRtqBnbCOLqE50RDK5QlLC_3p1v8­Csg/edit

Day 4:
https://docs.google.com/spreadsheets/d/1Gj7tgbzQUkiwS5_wJ62lvNfRNmbqBpAjdYLCAD1ulQw/edit
Title: Re: Advent of Code
Post by: freeflow on 04 December, 2020, 04:35:52 pm
Day04 has me scratching my head.  My VBA (with interfaces and code injection!!)  works OK with the test  data but fails on the real stuff < mumble mumble mumble go read the question again again again again>
Title: Re: Advent of Code
Post by: Pingu on 04 December, 2020, 04:45:42 pm
Day 4 done.

http://www.pinniped.plus.com/AoC/index.htm
Title: Re: Advent of Code
Post by: Pingu on 04 December, 2020, 04:50:12 pm
Still sticking with Google Sheets until they force me to stop.

Do you have a link to your Day 1 solution?
Title: Re: Advent of Code
Post by: Greenbank on 04 December, 2020, 04:57:11 pm
Still sticking with Google Sheets until they force me to stop.

Do you have a link to your Day 1 solution?

He posted it elsewhere: https://docs.google.com/spreadsheets/d/1joA1oMsoGaDCwX0u8CAK7IUuMeFqyfLEYzzIWzGB1d0/edit#gid=0
Title: Re: Advent of Code
Post by: Pingu on 04 December, 2020, 05:12:17 pm
Still sticking with Google Sheets until they force me to stop.

Do you have a link to your Day 1 solution?

He posted it elsewhere: https://docs.google.com/spreadsheets/d/1joA1oMsoGaDCwX0u8CAK7IUuMeFqyfLEYzzIWzGB1d0/edit#gid=0

Ta  :thumbsup:
Title: Re: Advent of Code
Post by: vorsprung on 04 December, 2020, 10:08:26 pm
I spent all day writing 4 unit tests for a react state filter

So excuse me if ICBA
Title: Re: Advent of Code
Post by: tonycollinet on 05 December, 2020, 12:06:51 am
Found day 4 a bit boring to be honest.
Reading arbitrary rules and writing validation code is a bit too much like actual work... :-\

This

Though I am using it as an excuse to learn

(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 05 December, 2020, 12:19:57 am
Found day 4 a bit boring to be honest.
Reading arbitrary rules and writing validation code is a bit too much like actual work... :-\

I learnt more about how JSON works  :)
Title: Re: Advent of Code
Post by: Ben T on 05 December, 2020, 11:15:21 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 05 December, 2020, 11:57:08 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 05 December, 2020, 01:17:49 pm
Day 5 done.

http://www.pinniped.plus.com/AoC/index.htm
Title: Re: Advent of Code
Post by: Ben T on 05 December, 2020, 02:59:39 pm
(click to show/hide)


(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 05 December, 2020, 09:16:21 pm
Day 5 relatively trivial.

(click to show/hide)

EDIT: or more efficiently with direct conversion...

(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 05 December, 2020, 10:49:03 pm
Day 5 probably the easiest spreadsheet yet:
https://docs.google.com/spreadsheets/d/1urBVcFFAz4HzJshKldFKtgobE_Zi8DGGNgY4Na5ATHw/edit?usp=sharing
Title: Re: Advent of Code
Post by: Pingu on 05 December, 2020, 11:01:24 pm
Day 5 probably the easiest spreadsheet yet:
https://docs.google.com/spreadsheets/d/1urBVcFFAz4HzJshKldFKtgobE_Zi8DGGNgY4Na5ATHw/edit?usp=sharing

Loving the spreadsheet solutions :thumbsup: You are Dido Harding AICMFP  :D
Title: Re: Advent of Code
Post by: tonycollinet on 05 December, 2020, 11:08:48 pm
Day 5 probably the easiest spreadsheet yet:
https://docs.google.com/spreadsheets/d/1urBVcFFAz4HzJshKldFKtgobE_Zi8DGGNgY4Na5ATHw/edit?usp=sharing

So - your data set is different than mine - bigger even. Does that mean each participant gets their own data?
Title: Re: Advent of Code
Post by: Pingu on 05 December, 2020, 11:16:47 pm
Day 5 probably the easiest spreadsheet yet:
https://docs.google.com/spreadsheets/d/1urBVcFFAz4HzJshKldFKtgobE_Zi8DGGNgY4Na5ATHw/edit?usp=sharing

So - your data set is different than mine - bigger even. Does that mean each participant gets their own data?

Yes
Title: Re: Advent of Code
Post by: tonycollinet on 06 December, 2020, 12:20:02 am
That is very cool.

The creators obviously put a lot of work into that.
Title: Re: Advent of Code
Post by: Greenbank on 06 December, 2020, 09:43:32 am
Day 6 was nowhere near as difficult as I expected.

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 06 December, 2020, 09:44:38 am
Day 6 complete.

I have to say Python has an incredibly rich set of functionality. Almost every operation I need to do has a pre-defined method.

(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 06 December, 2020, 10:22:47 am
Day 6: Still spreadsheeting
https://docs.google.com/spreadsheets/d/1VXcXG-N5KLMXUIs0Tdb7ObusNgZVVFaLnjdTCfD4AsA/edit?usp=sharing

I cocked up this time because this is the first dataset that's longer than 1000 lines (Google Sheets default size) and I handed bothered filling down my formulae.
Title: Re: Advent of Code
Post by: Pingu on 06 December, 2020, 12:24:06 pm
Day 6 done.

http://www.pinniped.plus.com/AoC/index.htm
Title: Re: Advent of Code
Post by: grams on 07 December, 2020, 01:16:23 pm
Day 7:

Spent much longer wrestling with the shitty lookup functions (VLOOKUP and MATCH) then I did with making recursion work.

https://docs.google.com/spreadsheets/d/11cUvSGYl9NT2-3prdotWaXyiD_-DfIFLJmeRujuxXwQ/edit?usp=sharing
Title: Re: Advent of Code
Post by: Greenbank on 07 December, 2020, 02:14:26 pm
Luckily part 2 didn't ask about the shiny purple bag:

BAG: shiny purple = 365714937810

Still waiting for a humdinger.
Title: Re: Advent of Code
Post by: Davef on 07 December, 2020, 02:30:45 pm
Just done days 2 through 7. Not very exciting so far.
Title: Re: Advent of Code
Post by: Pickled Onion on 07 December, 2020, 07:29:53 pm
Just done 2016 day 11. Had a mental block on it at the time, not sure why, it was fairly straightforward when I actually started coding it, with some interesting puzzles over optimisation.
Title: Re: Advent of Code
Post by: tonycollinet on 07 December, 2020, 09:14:56 pm
Well, as a relative novice, today had me scratching my head a little.

Getting head around recursion is tricky. I also had a function return statement that prevented the function processing anything other than the first "subbag" - which took nearly an hour to find.

Even just working out how to parse the input takes some time if you've never done it before.

Still - got there in the end.

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 08 December, 2020, 09:42:23 am
A little more interesting today. I can see there could be some fun ahead.
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2020, 09:45:47 am
Indeed, the beginnings of the VM.

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 08 December, 2020, 09:50:19 am
I was thinking Gödel’s incompleteness theorem and the Turing halting problem. It might inspire you to go back to your bookshelf.
Title: Re: Advent of Code
Post by: Ben T on 08 December, 2020, 10:01:58 am
I bloody hate these ones where you have to try and reverse engineer the machine code to find out what it's doing. For day 8 it was quite easy to test whether it's an infinite loop or not, as the program is effectively immutable. It's the ones where it jumps by the amount of a variable that are annoying.
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2020, 10:09:25 am
I kind of like this ones.

I end up rewriting it in something like perl and then replacing the instructions/jumps/branches with higher level constructs (while loops, for loops, etc) and then working out what the code is doing (such as painfully slowly implementing Eulers totient or phi function or similar).
Title: Re: Advent of Code
Post by: Greenbank on 08 December, 2020, 10:17:31 am
I was thinking Gödel’s incompleteness theorem and the Turing halting problem. It might inspire you to go back to your bookshelf.

And my degree(s). I did a fair bit on both of those in each of them.

Looking forward to some other problems like:-
* a big nasty number theory problem (like the Chinese Remainder Theorem inspired one [2017 day 13], or the famous Space Cards [2019 day 22]).
* an A* or SAT style solver
* ...probably in a maze of some sort
* Writing something to interactively play a game (like Breakout [2019 day 13])
* A 3D (or even 4D) problem
Title: Re: Advent of Code
Post by: Ben T on 08 December, 2020, 11:07:48 am
I kind of like this ones.

I end up rewriting it in something like perl and then replacing the instructions/jumps/branches with higher level constructs (while loops, for loops, etc) and then working out what the code is doing (such as painfully slowly implementing Eulers totient or phi function or similar).
I'll usually just leave it grinding away in C++ on my old ubuntu laptop unless it's literally going to take years.  :)
Title: Re: Advent of Code
Post by: grams on 08 December, 2020, 11:52:56 am
Day 8 done:
https://docs.google.com/spreadsheets/d/1QLnJ--jc1d18qHiwcO1QXnqyaoG078-09HlYiXvoA_0/edit#gid=1072555748

I started doing part 2 by inspection, but that seemed against the spirit of it. So executed it 500 times in one spreadsheet instead. Fan is still spinning.
Title: Re: Advent of Code
Post by: tonycollinet on 08 December, 2020, 07:51:37 pm
Day 8 done.

Quite liked this one - though tied myself up with failing to modify global variables in a function. Eventually found the "global" statement.

(click to show/hide)

Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2020, 07:59:08 am
Day 9 underwhelming.

Lucky as I've got a busy day.
Title: Re: Advent of Code
Post by: tonycollinet on 09 December, 2020, 08:56:44 am
Key learning point for day 9, as in most tests:

Read the fecking question  ::-) ::-)
Title: Re: Advent of Code
Post by: Greenbank on 09 December, 2020, 05:36:11 pm
Had the time to redo my day 9 properly.

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 10 December, 2020, 07:13:34 am
Day 10 was quite interesting.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2020, 08:43:02 am
Spent far too long on part 2 as I was distracted by a work call where I had to be paying attention for most of it.

Got the answer with similar observations to Diver300 above.
Title: Re: Advent of Code
Post by: Davef on 10 December, 2020, 09:42:00 am
I am not sure a solution that only works with a subset of the possibilities even if it happens to work for your data set is satisfactory.
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2020, 09:55:12 am
Well yes, getting the two stars the bare minimum, but I rarely ever stop there.

Other things to consider are:
a) Does it handle exceptions or assume the input data is clean?
b) Will it work on slightly different input (eg, what would your code for today [2020 Day 10] have done if the input consisted of the numbers to 1 to 8)?
c) Will it be performant on pathalogical cases of inputs of the same magnitude
d) Will it be performant/correct on inputs of a much greater magnitude
...etc...
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2020, 10:43:22 am
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2020, 10:50:44 am
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 10 December, 2020, 01:05:46 pm
Day 9:
https://docs.google.com/spreadsheets/d/1­aRLwJyPDhppCY4Xuy6ciW_zAutiHcRFAGpK4CkQF­yy4/edit?usp=sharing

Day 10 part 2:
https://docs.google.com/spreadsheets/d/1­2uXNKlJWxkxXb80ATMF3YRxS9fdXDgycL_ViGti3­gu0/edit?usp=sharing

I populated the lookup tab by figuring out what numbers would make the two examples work. That was enough to make the real data work.

I am not sure a solution that only works with a subset of the possibilities even if it happens to work for your data set is satisfactory.

I think they must deliberately generate the data to allow simpler approaches to work. Seems unnecessary to go beyond that.

It is just for fun after all.
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2020, 01:27:38 pm
I think they must deliberately generate the data to allow simpler approaches to work. Seems unnecessary to go beyond that.

It is just for fun after all.

Indeed, as I said above, there's a challenge in going beyond it. (But then that's easier for me as programming has been my job for years.)

And, without going beyond the two stars you may not learn about lovely things such as:

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 10 December, 2020, 01:52:34 pm
Well that (day 10) had me scratching my head for a bit.

I am not sure a solution that only works with a subset of the possibilities even if it happens to work for your data set is satisfactory.

The data is set up so that you have to do it that way....

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 10 December, 2020, 02:10:40 pm
How do you do this spoiler malarkey ?
Title: Re: Advent of Code
Post by: tonycollinet on 10 December, 2020, 02:12:00 pm
Click the Sp button next to the
Quote
quote
button.
Title: Advent of Code
Post by: Davef on 10 December, 2020, 02:18:38 pm
Single sequential pass, ‘one line’ solution to day 10 part 2.

(click to show/hide)
Edit: Realised it was a bit longwinded so abbreviated
Edit: could remove the curly brackets and use comma operator, but that might make it less readable.
Title: Re: Advent of Code
Post by: Ben T on 10 December, 2020, 02:47:00 pm
How do you do this spoiler malarkey ?
[spoiler]the code[/spoiler]
Title: Re: Advent of Code
Post by: Davef on 10 December, 2020, 02:47:47 pm
How do you do this spoiler malarkey ?
[spoiler]the code[/spoiler]
Thanks. Done now. See above.
Title: Re: Advent of Code
Post by: Diver300 on 11 December, 2020, 08:00:01 am
Day 11 done.

I keep making the mistake of writing something like:-
Code: [Select]
} while ( done = 0 ) when I mean
Code: [Select]
} while ( done == 0 )
Title: Re: Advent of Code
Post by: Davef on 11 December, 2020, 08:28:49 am
Day 9:
https://docs.google.com/spreadsheets/d/1­aRLwJyPDhppCY4Xuy6ciW_zAutiHcRFAGpK4CkQF­yy4/edit?usp=sharing

Day 10 part 2:
https://docs.google.com/spreadsheets/d/1­2uXNKlJWxkxXb80ATMF3YRxS9fdXDgycL_ViGti3­gu0/edit?usp=sharing

I populated the lookup tab by figuring out what numbers would make the two examples work. That was enough to make the real data work.

I am not sure a solution that only works with a subset of the possibilities even if it happens to work for your data set is satisfactory.

I think they must deliberately generate the data to allow simpler approaches to work. Seems unnecessary to go beyond that.

It is just for fun after all.
I agree - but the fact there is a simple solution because of a quirk of the data - it would be nice if that quirk was guaranteed by the spec. It would only need one more sentence that would not really give much away.
Title: Re: Advent of Code
Post by: Davef on 11 December, 2020, 09:18:26 am
Day 11 done.

I keep making the mistake of writing something like:-
Code: [Select]
} while ( done = 0 ) when I mean
Code: [Select]
} while ( done == 0 )
If you habitually write it as (0==done) then if you forget an = you get a compiler error . Personally I prefer (!done)
Title: Re: Advent of Code
Post by: Diver300 on 11 December, 2020, 09:40:13 am
Day 11 done.

I keep making the mistake of writing something like:-
Code: [Select]
} while ( done = 0 ) when I mean
Code: [Select]
} while ( done == 0 )
If you habitually write it as (0==done) then if you forget an = you get a compiler error . Personally I prefer (!done)
I'll try the (0==done) route.
Title: Re: Advent of Code
Post by: Davef on 11 December, 2020, 09:54:42 am
Day 11 done.

I keep making the mistake of writing something like:-
Code: [Select]
} while ( done = 0 ) when I mean
Code: [Select]
} while ( done == 0 )
If you habitually write it as (0==done) then if you forget an = you get a compiler error . Personally I prefer (!done)
I'll try the (0==done) route.
As I read “!” as “not” .... while (!done) out loud is “while not done”
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2020, 10:06:39 am
Day 11 done.

I keep making the mistake of writing something like:-
Code: [Select]
} while ( done = 0 ) when I mean
Code: [Select]
} while ( done == 0 )
If you habitually write it as (0==done) then if you forget an = you get a compiler error . Personally I prefer (!done)

Personally I think "0 == done" looks ugly, I much prefer the "!done" option but if I have to check for a specific value I still write "done == 1256" rather than "1256 == done".

If you use the right compiler options you get a warning for
Code: [Select]
} while ( done = 0 ), plus a load of other warnings for things you probably need to fix too:-

Code: [Select]
$ cat x.c
int main(void)
{
        int x=0;
        do { } while( x = 0 );
}
$ gcc x.c -o x
$ gcc -ansi -pedantic -Wall x.c -o x
x.c: In function ‘main’:
x.c:4:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
x.c:5:1: warning: control reaches end of non-void function [-Wreturn-type]
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2020, 01:32:14 pm
2020 day 11 done easily enough, but I haven't worked out the right trick to make it fast. (Bit busy with real work at the mo.)

Forgot the "cellular automata" item from the list of expected AoC challenges.
Title: Re: Advent of Code
Post by: grams on 11 December, 2020, 01:40:06 pm
Day 11 Part 1 is here. It takes about 20 minutes to recalculate 100 iterations, if it doesn't crash, and that's with hardcoding the cell references to make it easier*. I had a typo in my adjacent seat calculating formula that didn't cause a problem on the test data and had to redo all of it. Grrrr.

https://docs.google.com/spreadsheets/d/1QYtHllA3OYWupEnHUZmtXDV07zLlpniRcSfaBZpyDPg/edit?usp=sharing

(click to show/hide)

(* will, if Google Sheets has a proper recalculations optimiser. I'm increasingly doubtful it does)
Title: Re: Advent of Code
Post by: Davef on 11 December, 2020, 01:40:31 pm
Perhaps it was a tribute the great John Conway who sadly died earlier this year.
Title: Re: Advent of Code
Post by: Greenbank on 11 December, 2020, 02:28:16 pm
All of the previous AoC years have had a similar puzzle at some point in them I think.

Some time next year I'm going to go through all of the years and reimplement them in a few different languages, I'll also take the time to classify them so I can see how common individual things come up.

I may even write a load of template code/functions[1] ready to have a go at getting on the top 100 leaderboard, however I don't think I can be arsed getting up and having my brain ready and switched on for 5am even for a few days let alone every day.

1. This is how the majority of the top 100 get such fast times. Preparation (based on guesswork and experience) and then knowing which template would be best used as a basis for each puzzle...
Title: Re: Advent of Code
Post by: tonycollinet on 11 December, 2020, 06:15:27 pm
Day 11 Part 1 is here. It takes about 20 minutes to recalculate 100 iterations,

Really? - mine is taking about 5 seconds for 102 iterations of part one. Haven't got round to part 2 yet.
Title: Re: Advent of Code
Post by: grams on 11 December, 2020, 06:18:42 pm
Really? - mine is taking about 5 seconds for 102 iterations of part one. Haven't got round to part 2 yet.

That's for a Google Sheet with two million cells running in a browser tab.

More efficient approaches are no doubt available.
Title: Re: Advent of Code
Post by: Davef on 11 December, 2020, 06:24:46 pm
Day 11 Part 1 is here. It takes about 20 minutes to recalculate 100 iterations,

Really? - mine is taking about 5 seconds for 102 iterations of part one. Haven't got round to part 2 yet.
63 trillion iterations of a 100,000 by 100,000 grid might take a while.

https://conwaylife.com/wiki/Pi_calculator
Title: Re: Advent of Code
Post by: grams on 11 December, 2020, 09:50:35 pm
OK, did day 11 part 2:
https://docs.google.com/spreadsheets/d/1mfMTK1UA9qBIduBxIRKw92QYtu95AZ6LUPiETdR_uZA/edit?usp=sharing

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 12 December, 2020, 12:14:43 am
Really? - mine is taking about 5 seconds for 102 iterations of part one. Haven't got round to part 2 yet.

That's for a Google Sheet with two million cells running in a browser tab.

More efficient approaches are no doubt available.

Ah - fair enough.
Title: Re: Advent of Code
Post by: tonycollinet on 12 December, 2020, 08:33:24 am
So time constraints meant that I've only just completed day 11 p2.

(click to show/hide)
Title: Advent of Code
Post by: Davef on 12 December, 2020, 11:02:53 am
So time constraints meant that I've only just completed day 11 p2.

(click to show/hide)
All that typing takes a while.

(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 12 December, 2020, 11:12:29 am
Day 12 is oddly simple:
https://docs.google.com/spreadsheets/d/1NyEKHBwBLrFNKyLmZ63jB8CxNB6vBg3_ci3R9WBDgPM/edit?usp=sharing

(click to show/hide)
Title: Re: Advent of Code
Post by: Arellcat on 12 December, 2020, 11:21:28 am
Code: [Select]
user@cinelli ~ $ python -V
Python 2.7.6

Woah, slow down, Einstein.  ???

This may be why I am not a programmer, although I do like a good spreadsheet.
Title: Re: Advent of Code
Post by: Davef on 12 December, 2020, 12:42:18 pm
Day 12 is oddly simple:
https://docs.google.com/spreadsheets/d/1NyEKHBwBLrFNKyLmZ63jB8CxNB6vBg3_ci3R9WBDgPM/edit?usp=sharing

(click to show/hide)
My terse version

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 12 December, 2020, 01:20:58 pm
Day 12 is oddly simple:
https://docs.google.com/spreadsheets/d/1NyEKHBwBLrFNKyLmZ63jB8CxNB6vBg3_ci3R9WBDgPM/edit?usp=sharing

(click to show/hide)
I used a spreadsheet as well.
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 12 December, 2020, 01:28:50 pm
snip

Tactical fallthrough. Nice.
Title: Advent of Code
Post by: Davef on 12 December, 2020, 02:37:02 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 12 December, 2020, 03:04:46 pm
2020 day 11 done easily enough, but I haven't worked out the right trick to make it fast. (Bit busy with real work at the mo.)

Forgot the "cellular automata" item from the list of expected AoC challenges.

Really? not sure how "fast" you want it, mine takes about a second although that's in debug and probably includes compilation, they all take that - so I think the actual calculation, if I produced a release binary it would probably be sub-second.

my code is distinctly 'pedestrian', but reasonably efficient enough
(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 12 December, 2020, 04:00:41 pm
So time constraints meant that I've only just completed day 11 p2.

(click to show/hide)
All that typing takes a while.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 12 December, 2020, 04:19:20 pm
Day 12:
I provided for calculation of arbitrary turn angles - I'm hoping tomorrow will have similar with non 90 degree turns.  ;D

(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 12 December, 2020, 04:48:42 pm
Day 12:
I provided for calculation of arbitrary turn angles - I'm hoping tomorrow will have similar with non 90 degree turns.  ;D


The reason you know it won't have is because you (probably) won't end up with integer coordinates.
Problems usually only deal in integers, full stop. They (only very occasionally) use floating point numbers, but then it will be obvious it's a "floating points" question and it will be floating points throughout.
It's very rare to have one that's mainly integers, but you might sometimes have to round off.
Title: Re: Advent of Code
Post by: Davef on 12 December, 2020, 05:08:35 pm
2020 day 11 done easily enough, but I haven't worked out the right trick to make it fast. (Bit busy with real work at the mo.)

Forgot the "cellular automata" item from the list of expected AoC challenges.

Really? not sure how "fast" you want it, mine takes about a seconds although that's in debug and probably includes compilation, they all take that - so I think the actual calculation, if I produced a release binary it would probably be sub-second.

my code is distinctly 'pedestrian', but reasonably efficient enough
(click to show/hide)
that is the way I am doing it (with the slight optimisation of discarding the dots from the matrix to reduce the number of elements ). It is not however an efficient way of solving the problem. You will need to get a slower computer to see the benefits.
Title: Re: Advent of Code
Post by: Greenbank on 12 December, 2020, 05:13:27 pm
Day 12:
I provided for calculation of arbitrary turn angles - I'm hoping tomorrow will have similar with non 90 degree turns.  ;D


The reason you know it won't have is because you (probably) won't end up with integer coordinates.
Problems usually only deal in integers, full stop. They (only very occasionally) use floating point numbers, but then it will be obvious it's a "floating points" question and it will be floating points throughout.
It's very rare to have one that's mainly integers, but you might sometimes have to round off.

Two variants then that would still be possible given care:-

a) Angles of 30, 45 or 60 degrees. You've then only got to also keep track of 1/2s, sqrt(2) and sqrt(3) as well as integers. The input would be chosen so that the end point (or answer) ends up on an integer set of co-ordinates
b) Movements along arbitrary angles that cancel out, e.g.

R47
F10
R90
F1
R90
F1
R90
F1
L90
F9
R133

Which (if I've got it right) should leave you in the initial state.
Title: Re: Advent of Code
Post by: Ben T on 12 December, 2020, 06:20:20 pm
Theoretically it would be possible for intermediate points to be floating point (or multiples of sqrt(2) etc) if he was being mean, but experience tells you he doesn't generally set questions where the description generally talks in integers, and the answer is an integer, but you are expected to have to deal with floating point numbers for intermediate points.

I may yet be proved wrong :)

My general strategy is make an assumption, and structure the code such that it throws an exception if the assumption is wrong.
Title: Advent of Code
Post by: Davef on 12 December, 2020, 06:52:02 pm
Different approach to day 11 part 2. Throws away the 2D grid and just keeps numbered seats ....

(click to show/hide)

This reduces the work in each iteration dramatically
Title: Re: Advent of Code
Post by: Croft on 12 December, 2020, 06:58:39 pm
Day 12:
I provided for calculation of arbitrary turn angles - I'm hoping tomorrow will have similar with non 90 degree turns.  ;D

(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 12 December, 2020, 07:06:53 pm

Two variants then that would still be possible given care:-

a) Angles of 30, 45 or 60 degrees. You've then only got to also keep track of 1/2s, sqrt(2) and sqrt(3) as well as integers. The input would be chosen so that the end point (or answer) ends up on an integer set of co-ordinates
b) Movements along arbitrary angles that cancel out, e.g.

R47
F10
R90
F1
R90
F1
R90
F1
L90
F9
R133

Which (if I've got it right) should leave you in the initial state.

I wonder if there might be an integer approach for arbitrary integer angles using taxicab geometry. http://sites.science.oregonstate.edu/~tevian/physics/taxicab/taxicab.pdf (http://sites.science.oregonstate.edu/~tevian/physics/taxicab/taxicab.pdf)

You can define trig functions in Manhattan space using modulo arithmetic, which I think would give you a pretty good degree of precision when scaled by a large integer. But your mathematical intuition is much better than mine, so perhaps you'd have a stronger idea as to whether this would be possible.
Title: Re: Advent of Code
Post by: tonycollinet on 12 December, 2020, 08:30:12 pm
Day 12:
I provided for calculation of arbitrary turn angles - I'm hoping tomorrow will have similar with non 90 degree turns.  ;D

(click to show/hide)

Will look at those - thanks.
Title: Re: Advent of Code
Post by: grams on 12 December, 2020, 08:44:06 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 13 December, 2020, 08:13:20 am
Day 13 is more about maths than programming
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 09:38:04 am
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 13 December, 2020, 11:30:01 am
Are they trying to make me learn things? Fuck that.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 12:53:51 pm
Yep, and so this will be one of the first days with a big drop off between 1 star and 2 stars.

As I said on our internal company #advent-of-code Slack channel, today's problem is firmly over to the right of this scale:-

<------ "Programming" ----------------- "Computer Science" ---------------- "Discrete Mathematics" ------>

There's usually a good 2 or 3 each year that require something not usually covered in general "programming" or "Comp Sci".

Ob-xkcd:-

(https://imgs.xkcd.com/comics/purity.png)
Title: Advent of Code
Post by: Davef on 13 December, 2020, 12:54:07 pm
Day 13 part 2, keeping to my terse programming, 1 loop, 1ish lines, no function calls, no Chinese takeaways.

(click to show/hide)
I seem to have smileys. How to I get rid ?

This is quite efficient. For my part 2 data it loops 1000 times which is microseconds.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 12:56:18 pm
I seem to have smileys. How to I get rid ?

Modify the post, expand the "Additional Options" box below it, check the "Don't use smileys" checkbox.
Title: Re: Advent of Code
Post by: Davef on 13 December, 2020, 01:01:19 pm
I seem to have smileys. How to I get rid ?

Modify the post, expand the "Additional Options" box below it, check the "Don't use smileys" checkbox.
I don’t seem to have those options. I put some spaces in. Is there some [] tags you can use? Even with the extra spaces I feel I am within the 80 character limit so I can keep the source code on one punch card.
Title: Re: Advent of Code
Post by: Croft on 13 December, 2020, 01:41:12 pm
Yep, and so this will be one of the first days with a big drop off between 1 star and 2 stars.

As I said on our internal company #advent-of-code Slack channel, today's problem is firmly over to the right of this scale:-

<------ "Programming" ----------------- "Computer Science" ---------------- "Discrete Mathematics" ------>

There's usually a good 2 or 3 each year that require something not usually covered in general "programming" or "Comp Sci".

Not sure I agree. It doesn’t require knowledge of that theorem and is quite computable with a fairly simple approach. Davef’s is a nice example of that.

We often see a similar pattern develop around the mid and later puzzles. The fastest and most experienced people spot a theory or solution from computer science or maths, share their observations on reddit. Others struggle for a bit, consult reddit, see lots of discussion on theorem X, and assume it is required for solution.

Eric is quite careful not to require such knowledge to derive a solution, even if it can help. We saw similar last year with the Slam Shuffle (day 22) that did allow solutions without detailed knowledge of modular arithmetic, even if it made spotting a solution easier.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 01:42:30 pm
I don’t seem to have those options. I put some spaces in. Is there some [] tags you can use? Even with the extra spaces I feel I am within the 80 character limit so I can keep the source code on one punch card.

Are you using a browser to view the forum or something like Tapatalk?

You should be able to avoid it using code tags I guess.

Code: [Select]
Does this appear as a smiley? 8)
Title: Advent of Code
Post by: Davef on 13 December, 2020, 01:57:45 pm
If anyone is interested in how my simple solution to 13 day 2 works ...

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 02:11:20 pm
Yep, and so this will be one of the first days with a big drop off between 1 star and 2 stars.

As I said on our internal company #advent-of-code Slack channel, today's problem is firmly over to the right of this scale:-

<------ "Programming" ----------------- "Computer Science" ---------------- "Discrete Mathematics" ------>

There's usually a good 2 or 3 each year that require something not usually covered in general "programming" or "Comp Sci".

Not sure I agree. It doesn’t require knowledge of that theorem and is quite computable with a fairly simple approach. Davef’s is a nice example of that.

We often see a similar pattern develop around the mid and later puzzles. The fastest and most experienced people spot a theory or solution from computer science or maths, share their observations on reddit. Others struggle for a bit, consult reddit, see lots of discussion on theorem X, and assume it is required for solution.

Eric is quite careful not to require such knowledge to derive a solution, even if it can help. We saw similar last year with the Slam Shuffle (day 22) that did allow solutions without detailed knowledge of modular arithmetic, even if it made spotting a solution easier.

Sure, but my point is that in pretty much every case the solutions that people come up with (like Davef's above) are just implementing simple (and/or non-optimal) cases of the underlying theorem.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 02:32:53 pm
If anyone is interested in how my simple solution to 13 day 2 works ...

(click to show/hide)

(click to show/hide)
Title: Advent of Code
Post by: Davef on 13 December, 2020, 02:37:41 pm
If anyone is interested in how my simple solution to 13 day 2 works ...

(click to show/hide)

(click to show/hide)
The version I initially wrote sorted the numbers and worked largest first. It made little difference on the sample so I posted a simplified version.

Longer version with presorting (should start with step=a[0] too)
(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 13 December, 2020, 02:43:08 pm
Sure, but my point is that in pretty much every case the solutions that people come up with (like Davef's above) are just implementing simple (and/or non-optimal) cases of the underlying theorem.

I agree, which is what I really like about AoC. It is possible to get those gold stars (and so not necessarily a drop-off in puzzle competitions), but the process encourages us to find out more. What better way for to introduce Theorem X by inviting us to 'discover' it via our own implementation that uses a (possibly compromised) version of it? This is pretty much the gold standard in teaching - "create" is better than "discover" is better than "show" is better than "tell".

This year's so far has been better than most in that respect. Few have been hard in the sense of preventing casual programmers from finding a solution, but many have invited further thought on ways of refining / generalising.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 02:50:57 pm
The version I initially wrote sorted the numbers and worked largest first. It made little difference on the sample so I posted a simplified version.

Sure, but I wrote that particular pathological case specifically for the version of the algorithm you posted.

I know your algorithm would work (and be much quicker than most) for all of the example inputs within AoC but, as I've said before, I'm talking about people choosing to use AoC to learn how to solve the general case and not just get the two stars each day before moving on.

If you provided an algorithm that worked largest case first I can provide a different pathological case that will attempt to maximise runtime for that version of the algorithm.

For most problems this back and forth can be repeated again and again until the program tends to be an implementation of the optimal algorithm.

You should try the https://onlinejudge.org/ coding puzzles. The difference between AoC and those is that with the OnlineJudge ones you don't get to see the final input your program is tested against, you submit your code (in whatever language you want) for that one. The examples that are given are all quite simplistic and the input your program is actually tested on is specifically crafted to stretch the designs of most programs to the limit. It's much harder when anything less than an optimal solution just comes back with "Time exceeded, execution aborted" each time.
Title: Re: Advent of Code
Post by: Croft on 13 December, 2020, 02:57:43 pm

(click to show/hide)

(click to show/hide)

Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 03:15:45 pm

(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 13 December, 2020, 03:19:51 pm
Ah, yes of course ^.

That kind of sloppy thinking on my part is why I'll never be any good at those blind coding challenges.
Title: Re: Advent of Code
Post by: grams on 13 December, 2020, 04:25:57 pm
Day 13:
https://docs.google.com/spreadsheets/d/1AqziDqaSP6ThPImbihOYHoUNlIHToVUPxhCX_A_a2ks/edit?usp=sharing

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 13 December, 2020, 05:17:42 pm
Well Day13 stretched my capability to logic to it's limit. My head now officially hurts. I'm in the camp of no comp_sci training, and weak engineering maths so just have to puzzle it out. ;D

Pleased I didn't look at spoilers though.

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 13 December, 2020, 05:44:04 pm
Lots of talk about theorems above, and now I've completed would be interested to learn more. Can anyone point out what theorem is applicable to day 13, and ideally a link to a primer of some sort.

Ta.
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2020, 06:28:27 pm
Lots of talk about theorems above, and now I've completed would be interested to learn more. Can anyone point out what theorem is applicable to day 13, and ideally a link to a primer of some sort.

It's in this post: https://yacf.co.uk/forum/index.php?topic=94710.msg2568783#msg2568783
Title: Re: Advent of Code
Post by: Ben T on 13 December, 2020, 06:54:53 pm
If anyone is interested in how my simple solution to 13 day 2 works ...

(click to show/hide)

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 13 December, 2020, 07:00:39 pm
Lots of talk about theorems above, and now I've completed would be interested to learn more. Can anyone point out what theorem is applicable to day 13, and ideally a link to a primer of some sort.

It's in this post: https://yacf.co.uk/forum/index.php?topic=94710.msg2568783#msg2568783

Thanks - missed that in the nested spoilers :-)
Title: Re: Advent of Code
Post by: Davef on 13 December, 2020, 07:05:55 pm
If anyone is interested in how my simple solution to 13 day 2 works ...

(click to show/hide)

(click to show/hide)

(click to show/hide)
I did actually a version that sorted first but I stripped it out to get my solution down to 80 characters.
Title: Re: Advent of Code
Post by: tonycollinet on 13 December, 2020, 08:05:22 pm
Realising (now) that lowest common multiplier wasn't actually needed in day 13 - still a question that came up:

Is it true that LCM (a,b,c,d...)

Is equal to

LCM(d,LCM(c,LCM(b,a)))

?? (Assuming I've got the brackets in the correct places  ;D )
Title: Re: Advent of Code
Post by: Croft on 13 December, 2020, 08:34:59 pm
Yes.

Informally, because you can calculate LCM by finding the maximum prime factor exponent of each number and max more obviously satisfies the same property: max (a,b,c) = max (a, max(b,c))
Title: Advent of Code
Post by: Davef on 14 December, 2020, 08:29:43 am
Or that the lcm of a set of numbers is their product divided by their gcd. I find it easier to visualise the gcd in a  mental venn diagram of prime factors. It is fundamental that set intersection works this way from the colouring in I did at school.
Title: Re: Advent of Code
Post by: Davef on 14 December, 2020, 09:42:16 am

(click to show/hide)

(click to show/hide)

(click to show/hide)
Doesn’t your favourite theorem require the bus numbers to be relatively prime too ?
Title: Re: Advent of Code
Post by: Greenbank on 14 December, 2020, 12:43:53 pm
Doesn’t your favourite theorem require the bus numbers to be relatively prime too ?

The basic one yes, but the more generalised version works on non-co-prime moduli too.
Title: Re: Advent of Code
Post by: Ben T on 14 December, 2020, 02:15:42 pm
I think day 14 part 2's badly explained, I don't even get what the program's meant to be doing.

Quote
After applying the mask, four bits are overwritten, three of which are different, and two of which are floating. Floating bits take on every possible combination of values; with two floating bits, four actual memory addresses are written:

000000000000000000000000000000011010  (decimal 26)
000000000000000000000000000000011011  (decimal 27)
000000000000000000000000000000111010  (decimal 58)
000000000000000000000000000000111011  (decimal 59)
Next, the program is about to write to memory address 26 with a different bitmask:

address: 000000000000000000000000000000011010  (decimal 26)
mask:    00000000000000000000000000000000X0XX
result:  00000000000000000000000000000001X0XX
This results in an address with three floating bits, causing writes to eight memory addresses:

000000000000000000000000000000010000  (decimal 16)
000000000000000000000000000000010001  (decimal 17)
000000000000000000000000000000010010  (decimal 18)
000000000000000000000000000000010011  (decimal 19)
000000000000000000000000000000011000  (decimal 24)
000000000000000000000000000000011001  (decimal 25)
000000000000000000000000000000011010  (decimal 26)
000000000000000000000000000000011011  (decimal 27)

The entire 36-bit address space still begins initialized to the value 0 at every address, and you still need the sum of all values left in memory at the end of the program. In this example, the sum is 208.

"four actual memory addresses are written"... written with what?
"In this example, the sum is 208".... which of the above values sum to 208?

They seem to sum to 342 to me. Even if you only count each one once (26 and 27 are twice), they sum to 289.

How does he get 208?

???
Title: Re: Advent of Code
Post by: grams on 14 December, 2020, 02:28:18 pm
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.
Title: Re: Advent of Code
Post by: Davef on 14 December, 2020, 02:35:48 pm
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.
My first go splurged stuff all over the place but worked. I then redid it imagining I had a quantum processor using a superposition of quantum states. I then fell back through a wormhole to day 13 part 2.
Title: Re: Advent of Code
Post by: Davef on 14 December, 2020, 02:42:18 pm
Day 13 part 2, only loops 38 times rather than 1000 now, but I feel sorry for the person taking over code maintenance

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 14 December, 2020, 03:17:17 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 14 December, 2020, 03:52:08 pm
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 14 December, 2020, 04:40:51 pm
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.

Oh, I see...
yeah you might have to wheel a programming language out.
Title: Re: Advent of Code
Post by: Lightning Phil on 14 December, 2020, 05:56:09 pm
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.

Oh, I see...
yeah you might have to wheel a programming language out.

You can do bit operations in Google sheets.  Haven’t looked at what you need to do but bit manipulation via ORs ANDs, shifts etc should not stop you using sheets.
Title: Re: Advent of Code
Post by: grams on 14 December, 2020, 06:12:12 pm
You can do bit operations in Google sheets.  Haven’t looked at what you need to do but bit manipulation via ORs ANDs, shifts etc should not stop you using sheets.

That's not the problem. Part 1 was straightforward enough.

The problem is storing the intermediate results of each write, and combining the overwrites to get the final total. Without hashtables or nested loops or a 2^36 array.

There's probably some clever radical simplification of the problem.
Title: Re: Advent of Code
Post by: Davef on 14 December, 2020, 06:29:39 pm
You can do bit operations in Google sheets.  Haven’t looked at what you need to do but bit manipulation via ORs ANDs, shifts etc should not stop you using sheets.

That's not the problem. Part 1 was straightforward enough.

The problem is storing the intermediate results of each write, and combining the overwrites to get the final total. Without hashtables or nested loops or a 2^36 array.

There's probably some clever radical simplification of the problem.
You could have one column with memory addresses in an the values in the next. They are are just labels.
Title: Re: Advent of Code
Post by: tonycollinet on 14 December, 2020, 06:40:09 pm
Day 14 complete - less tricky than 13, but...

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2020, 11:59:36 pm
Day 14 complete.
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 15 December, 2020, 01:27:11 am
Day 14 part 1. Relatively trivial.
https://docs.google.com/spreadsheets/d/1uprQs9jfVjy9C7WC-q9_iVRd9lz6VEts1kPm-iAzPaA/edit?usp=sharing

Day 14 part 2.
https://docs.google.com/spreadsheets/d/1wTfCJDeHbetXmXDTj6ZkR7Z_KBjIpG2dLe91rwaOyNg/edit?usp=sharing

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 15 December, 2020, 08:45:20 am
Day 15 oddly trivial, even brute forcing part2. I assume there is a more intelligent method for that, but if there is, I haven't found it yet.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2020, 08:57:41 am
Occasionally there are 'easy' days to give people a break and let them catch up.

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 15 December, 2020, 09:02:17 am
Occasionally there are 'easy' days to give people a break and let them catch up.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2020, 09:15:10 am
(click to show/hide)

Yes, a hash is another name for a dictionary. Different languages use different names.

Dictionaries, hashes, hashmaps, maps, ...
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2020, 09:52:02 am
Rewrote it in C to see how quick I could get it:-

Code: [Select]
$ gcc -ansi -pedantic -Wall -O4 15.c -o 15
$ time ./15 2 3 1
2020: 78
30000000: 6895259

real    0m0.813s
user    0m0.761s
sys     0m0.052s

(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 15 December, 2020, 10:08:54 am
(click to show/hide)

Title: Re: Advent of Code
Post by: grams on 15 December, 2020, 10:33:48 am
Day 14, part 2
(click to show/hide)

Day 15, part 2
(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 15 December, 2020, 11:43:58 am
Rewrote it in C to see how quick I could get it:-

Code: [Select]
$ gcc -ansi -pedantic -Wall -O4 15.c -o 15
$ time ./15 2 3 1
2020: 78
30000000: 6895259

real    0m0.813s
user    0m0.761s
sys     0m0.052s

(click to show/hide)

I tried the same in python, and it increased  execution time from 13s to nearly 15s

EDIT
(click to show/hide)
Title: Re: Advent of Code
Post by: freeflow on 15 December, 2020, 01:41:38 pm
My Day 15 Part 2 is forecast to complete in around 4 hours :jurek:
Title: Advent of Code
Post by: Davef on 15 December, 2020, 02:46:38 pm
My whopping array takes a few milliseconds

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2020, 03:27:16 pm
My whopping array takes a few milliseconds

You can shave a tiny bit off if you remove the memset(). Linux should automatically give you zeroed memory.
Title: Re: Advent of Code
Post by: grams on 15 December, 2020, 03:34:01 pm
I finally wheeled out a programming language and decided to see quite how slow a naive C implementation would actually be. It's taken 45 minutes to get to 2.8 million and progress has fallen well below 1000 numbers per second.

Meanwhile I tried to use Applescript. The closest thing it has to a hashtable has keys fixed at compile time, so no good.

So in leiu of a spreadsheet or a programming language, some PHP, which does 30 million iterations in about 7 seconds:
(click to show/hide)

Davef, do you want to talk us through your code a little bit? My head indirectly hurts.
Title: Re: Advent of Code
Post by: Greenbank on 15 December, 2020, 03:50:33 pm
I finally wheeled out a programming language and decided to see quite how slow a naive C implementation would actually be. It's taken 45 minutes to get to 2.8 million and progress has fallen well below 1000 numbers per second.

Meanwhile I tried to use Applescript. The closest thing it has to a hashtable has keys fixed at compile time, so no good.

So in leiu of a spreadsheet or a programming language, some PHP, which does 30 million iterations in about 7 seconds:
(click to show/hide)

Davef, do you want to talk us through your code a little bit? My head indirectly hurts.

Here's my fast C code (it's slightly faster, and significantly more readable, than Davef's if I run both on my machine):-

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 15 December, 2020, 03:52:25 pm
I finally wheeled out a programming language and decided to see quite how slow a naive C implementation would actually be. It's taken 45 minutes to get to 2.8 million and progress has fallen well below 1000 numbers per second.

Meanwhile I tried to use Applescript. The closest thing it has to a hashtable has keys fixed at compile time, so no good.

So in leiu of a spreadsheet or a programming language, some PHP, which does 30 million iterations in about 7 seconds:
(click to show/hide)

Davef, do you want to talk us through your code a little bit? My head indirectly hurts.

Here's my fast C code (it's slightly faster, and significantly more readable, than Davef's if I run both on my machine):-

(click to show/hide)
Mine was specifically designed to be unreadable.
Title: Advent of Code
Post by: Davef on 15 December, 2020, 03:59:36 pm
I finally wheeled out a programming language and decided to see quite how slow a naive C implementation would actually be. It's taken 45 minutes to get to 2.8 million and progress has fallen well below 1000 numbers per second.

Meanwhile I tried to use Applescript. The closest thing it has to a hashtable has keys fixed at compile time, so no good.

So in leiu of a spreadsheet or a programming language, some PHP, which does 30 million iterations in about 7 seconds:
(click to show/hide)

Davef, do you want to talk us through your code a little bit? My head indirectly hurts.
Basically the same as yours but a big array instead of a dictionary And then I have pissed around to use as few characters as possible and make it as unreadable as possible!

e.g.
Int a[3000000]
a[19] = 1

How I actually wrote it first time with more characters  ...
(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 15 December, 2020, 04:43:15 pm
I finally wheeled out a programming language and decided to see quite how slow a naive C implementation would actually be. It's taken 45 minutes to get to 2.8 million and progress has fallen well below 1000 numbers per second.

Meanwhile I tried to use Applescript. The closest thing it has to a hashtable has keys fixed at compile time, so no good.

So in leiu of a spreadsheet or a programming language, some PHP, which does 30 million iterations in about 7 seconds:
(click to show/hide)

Davef, do you want to talk us through your code a little bit? My head indirectly hurts.

Here's my fast C code (it's slightly faster, and significantly more readable, than Davef's if I run both on my machine):-

(click to show/hide)

Where I am struggling with a lot of these C implementations - I can't see where your input arrives in the code - the first 5 (or whatever) numbers.
Title: Advent of Code
Post by: Davef on 15 December, 2020, 04:50:21 pm
I finally wheeled out a programming language and decided to see quite how slow a naive C implementation would actually be. It's taken 45 minutes to get to 2.8 million and progress has fallen well below 1000 numbers per second.

Meanwhile I tried to use Applescript. The closest thing it has to a hashtable has keys fixed at compile time, so no good.

So in leiu of a spreadsheet or a programming language, some PHP, which does 30 million iterations in about 7 seconds:
(click to show/hide)

Davef, do you want to talk us through your code a little bit? My head indirectly hurts.

Here's my fast C code (it's slightly faster, and significantly more readable, than Davef's if I run both on my machine):-

(click to show/hide)

Where I am struggling with a lot of these C implementations - I can't see where your input arrives in the code - the first 5 (or whatever) numbers.
In my obscure version at post 1004 above there is a ‘for’ loop after the comment that says parse input

It reads the input string
const char *s = "0,14,6,20,1,4";
 one ascii character at a time and converts to numbers and puts the numbers in the array. Normally I would use a library function for that but instead I convert the asciii to decimal by subtracting ‘0’ (and repeatedly multiplying by 10 if more than one char)

Edit: looking at greenbanks, his input is coming in on the command line. C programs main() function are invoked with an array of arguments in char *argv[]
Title: Re: Advent of Code
Post by: Diver300 on 15 December, 2020, 07:42:11 pm
On day 15 part 1, I had a list of numbers, and for 2020 numbers it didn't take long.

Once I set the same code to run to 30,000,000 numbers it was heading for all day with the computer fan running flat out, and it was slowing down.

(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 15 December, 2020, 08:37:03 pm

Edit: looking at greenbanks, his input is coming in on the command line. C programs main() function are invoked with an array of arguments in char *argv[]

That'll be it - thanks.
Title: Re: Advent of Code
Post by: grams on 15 December, 2020, 11:43:01 pm
Once I set the same code to run to 30,000,000 numbers it was heading for all day with the computer fan running flat out, and it was slowing down.

So I've worked out that (for my data), to get to 30 million by brute force you'd need to do 71 trillion comparisons. Whereas for 1 million it only needs to do 92 billion. Which is 771, and computer science tells us that's the same as 900.

So to finish in under an hour it needs to get to a million in under 4 seconds, or 23 billion comparisons per second. It's not implausible you could get there with SIMD and/or running it on a GPU.

ETA: I've got the inner loop down to three x86 assembly instructions (load+compare, decrement pointer, conditional jump) and it still takes 45 seconds to get to a million, suggesting a 10 hour completion time. Bah.
Title: Re: Advent of Code
Post by: Davef on 16 December, 2020, 09:05:36 am
Once I set the same code to run to 30,000,000 numbers it was heading for all day with the computer fan running flat out, and it was slowing down.

So I've worked out that (for my data), to get to 30 million by brute force you'd need to do 71 trillion comparisons. Whereas for 1 million it only needs to do 92 billion. Which is 771, and computer science tells us that's the same as 900.

So to finish in under an hour it needs to get to a million in under 4 seconds, or 23 billion comparisons per second. It's not implausible you could get there with SIMD and/or running it on a GPU.

ETA: I've got the inner loop down to three x86 assembly instructions (load+compare, decrement pointer, conditional jump) and it still takes 45 seconds to get to a million, suggesting a 10 hour completion time. Bah.
I think you have the problem the wrong way round. It should only take 30,000,000 loops

I have moved on to trying to squeeze my day 16 down in size. I feel it is going to spread to a couple of punch cards.
Title: Re: Advent of Code
Post by: grams on 16 December, 2020, 01:12:57 pm
I think you have the problem the wrong way round. It should only take 30,000,000 loops

I have the problem the right way round, which is O(n^2), and that's how I like it. I'm trying to figure out if computers are fast enough yet to JFDI, at least for n = 30 million.


Title: Advent of Code
Post by: Davef on 16 December, 2020, 02:01:05 pm
I think you have the problem the wrong way round. It should only take 30,000,000 loops

I have the problem the right way round, which is O(n^2), and that's how I like it. I'm trying to figure out if computers are fast enough yet to JFDI, at least for n = 30 million.
Are you doing it with no storage then ?

With no storage it is O(n^2). With n integers of storage it is O(n)
Title: Re: Advent of Code
Post by: grams on 16 December, 2020, 02:06:58 pm
I'm storing the raw list of numbers and looking backwards until I find a matching number (or, worse, don't).
Title: Advent of Code
Post by: Davef on 16 December, 2020, 03:23:57 pm
Day 16 2
(click to show/hide)
Better result processing using bitmask
Title: Advent of Code
Post by: Davef on 16 December, 2020, 03:26:35 pm
I'm storing the raw list of numbers and looking backwards until I find a matching number (or, worse, don't).
Why ? The beauty of arrays is that they provide fast access via an integer key

(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 16 December, 2020, 06:19:18 pm
Why ? The beauty of arrays is that they provide fast access via an integer key

Idle curiosity.

Clearly the question was set with the expectation that many people would create a naive O(n^2) algorithm for Part 1 and then have to replace it with something at least O(n log n) to calculate Part 2 in reasonable time. But I reckon it's possible to run an O(n^2) solution for n = 30 million in reasonable time.

Day 16:
(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 16 December, 2020, 06:34:55 pm
Day 16 done.

But I really don't enjoy the ones that result in a mess of data manipulation (how to code it) as distinct from puzzle solving (what do I need to code). It was more like work than fun.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 16 December, 2020, 08:00:29 pm
Why ? The beauty of arrays is that they provide fast access via an integer key

Idle curiosity.

Clearly the question was set with the expectation that many people would create a naive O(n^2) algorithm for Part 1 and then have to replace it with something at least O(n log n) to calculate Part 2 in reasonable time. But I reckon it's possible to run an O(n^2) solution for n = 30 million in reasonable time.

Have implemented what I think is the fastest O(n^2) algorithm for day 15 part 2. So far:-

Code: [Select]
$ time ./15slow 2 1 3
t=4 turn=300000
t=17 turn=600000
t=39 turn=900000
t=68 turn=1200000
t=106 turn=1500000
t=153 turn=1800000
t=208 turn=2100000
t=272 turn=2400000
t=347 turn=2700000

Each one of those lines represents 1% of the number of turns with the t value being the time in seconds it has been running.

Extrapolating I'd be happy if it's done in <24 hours.

[EDIT] The rate of change of the rate of change is about 10 seconds per 1%.

So extrapolating that gives 10 * 100 * 99 / 2 = 49500 seconds =~ 14h
Title: Re: Advent of Code
Post by: grams on 16 December, 2020, 09:41:35 pm
Day 16 done:
https://docs.google.com/spreadsheets/d/1t3jC4tIqWEm3IPSIk0FSWWqPeY4BrNc9HMUSfa0R2fg/edit?usp=sharing

Reasonably straightforward but a lot of steps and therefore a lot of annoying debugging cell reference typos.
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2020, 08:13:41 am
Have implemented what I think is the fastest O(n^2) algorithm for day 15 part 2. So far:-

Code: [Select]
$ time ./15slow 2 1 3
t=4 turn=300000
t=17 turn=600000
t=39 turn=900000
t=68 turn=1200000
t=106 turn=1500000
t=153 turn=1800000
t=208 turn=2100000
t=272 turn=2400000
t=347 turn=2700000

Each one of those lines represents 1% of the number of turns with the t value being the time in seconds it has been running.

Extrapolating I'd be happy if it's done in <24 hours.

[EDIT] The rate of change of the rate of change is about 10 seconds per 1%.

So extrapolating that gives 10 * 100 * 99 / 2 = 49500 seconds =~ 14h

It's exciting (and that updated prediction is looking quite accurate). Should be done inside an hour.

Code: [Select]
...
t=41498 turn=28800000
t=42355 turn=29100000
t=43223 turn=29400000
t=44095 turn=29700000

(The question is whether it will give the right answer! [Which should be 3544142 for the input I gave it.])
Title: Re: Advent of Code
Post by: vorsprung on 17 December, 2020, 08:17:10 am
I see day 17 is a 3-d Conway's Life
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2020, 08:17:30 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2020, 08:30:02 am
I see day 17 is a 3-d Conway's Life

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2020, 08:38:42 am
Have implemented what I think is the fastest O(n^2) algorithm for day 15 part 2. So far:-

Code: [Select]
$ time ./15slow 2 1 3
t=4 turn=300000
t=17 turn=600000
t=39 turn=900000
t=68 turn=1200000
t=106 turn=1500000
t=153 turn=1800000
t=208 turn=2100000
t=272 turn=2400000
t=347 turn=2700000

Each one of those lines represents 1% of the number of turns with the t value being the time in seconds it has been running.

Extrapolating I'd be happy if it's done in <24 hours.

[EDIT] The rate of change of the rate of change is about 10 seconds per 1%.

So extrapolating that gives 10 * 100 * 99 / 2 = 49500 seconds =~ 14h

It's exciting (and that updated prediction is looking quite accurate). Should be done inside an hour.

Code: [Select]
...
t=41498 turn=28800000
t=42355 turn=29100000
t=43223 turn=29400000
t=44095 turn=29700000

(The question is whether it will give the right answer! [Which should be 3544142 for the input I gave it.])

And ...

Code: [Select]
$ time ./15slow 2 1 3
t=4 turn=300000
t=17 turn=600000
t=39 turn=900000
t=68 turn=1200000
...
t=42355 turn=29100000
t=43223 turn=29400000
t=44095 turn=29700000
3544142

real    749m39.241s
user    750m18.228s
sys     0m1.734s

That is the right answer! You are one gold star closer to saving your vacation.

750m = 12 hours and 30 minutes

Source:-

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int mem[30000000];

int main( int argc, char **argv) {
        int turn=0;
        int last=-1;
        time_t start;
        time(&start);
        while( argv[turn+1] ) {
                last=atoi(argv[turn+1]);
                mem[turn]=last;
                turn++;
        }
        while( turn < 30000000 ) {
                int say=0;
                int f;
                if( turn % 300000 == 0 ) {
                        time_t now;
                        time(&now);
                        printf( "t=%d turn=%d\n", (int)(now-start), turn );
                }
                f=turn-2;
                while( f >= 0 ) {
                        if( mem[f] == last )
                                break;
                        f--;
                }
                if( f >= 0 ) {
                        say = turn-f-1;
                }
                /* printf( "turn=%d last=%d say=%d f=%d\n", turn, last, say, f ); */
                mem[turn-1]=last;
                last=say;
                turn++;
        }
        printf( "%d\n", last );
        return(0);
}
Title: Re: Advent of Code
Post by: grams on 17 December, 2020, 10:49:00 am
Source:-

Code: [Select]
                while( f >= 0 ) {
                        if( mem[f] == last )
                                break;
                        f--;
                }

If you stick the value of last into mem[0] (and shuffle the other numbers up) you only need to do one comparison per loop and it will run considerably quicker. And turn and f will no longer be 1 different.
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2020, 02:24:18 pm
If you stick the value of last into mem[0] (and shuffle the other numbers up) you only need to do one comparison per loop and it will run considerably quicker. And turn and f will no longer be 1 different.

Good point...

Old:-

t=347 turn=2700000

New:-

t=191 turn=2700000

So almost twice as fast (so far, although I don't see why that shouldn't continue). Surprised me as I would have thought the infrequent negatives would have trained the branch predictor to err on the side of looping (and then only having to occasionally buck the pipeline), and also that it would have been mostly memory bound given the fact that a ~100MB array isn't going to be very cache friendly.

So, likely to finish take 5-6 hours.
Title: Re: Advent of Code
Post by: tonycollinet on 17 December, 2020, 03:22:26 pm
So day 17:

Part 1 took me about 2.5 hours to sort out, mainly finding a way to efficiently represent infinite 3d space**, with one abortive start***, and a number of stupid typo type bugs. Fortunately I'd structured it in a way that suited part 2. Part 2 took an additional 5 minutes.

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: vorsprung on 17 December, 2020, 03:42:53 pm
I see day 17 is a 3-d Conway's Life

(click to show/hide)

doesn't bother me coz I am still at work and have plenty of programming puzzles to figure out
Title: Re: Advent of Code
Post by: Greenbank on 17 December, 2020, 03:45:06 pm
So day 17:

That's pretty similar to mine:

(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 17 December, 2020, 04:22:59 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 17 December, 2020, 04:42:21 pm
So almost twice as fast (so far, although I don't see why that shouldn't continue). Surprised me as I would have thought the infrequent negatives would have trained the branch predictor to err on the side of looping (and then only having to occasionally buck the pipeline),

The branch predictor just keeps the pipline full. The operations for each compare (a compare and a conditional branch) will still take up their normal number of cycles, even if the branch predictor is perfect.

Quote
and also that it would have been mostly memory bound given the fact that a ~100MB array isn't going to be very cache friendly.

It ought to load a whole block into cache at once, so I'd expect it to spend very little time waiting for memory loads.

I reckon it's entirely CPU bound.
Title: Re: Advent of Code
Post by: tonycollinet on 17 December, 2020, 06:00:19 pm
(click to show/hide)

But:
(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 17 December, 2020, 06:03:59 pm
So day 17:

That's pretty similar to mine:

(click to show/hide)

Ive just done a simple optimisation that...

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 17 December, 2020, 09:53:32 pm
For day 16, I created a sort routine for the 20 fields against the 20 columns, but it was really slow and took half an hour or so. That actually gave me the answer.

Then I realised that one field only worked with one column, that allowed all other fields to be eliminated as option for that column. Columns and rows could be thinned out to the final solution that way, and the code ran in a fraction of a second.

I don't know if the thinning out method will always work when there is a unique solution.
Title: Re: Advent of Code
Post by: grams on 18 December, 2020, 12:16:00 am
Day 17 remains spreadsheetable, although it has so many rows it was immensely crashy on recalculation:
https://docs.google.com/spreadsheets/d/1vb2HE64SbJN3acZpFipF3T01m-ABLNuUje7UEQpx_C4/edit?usp=sharing

(click to show/hide)

I don't know if the thinning out method will always work when there is a unique solution.

It ought to. I did worry they might have made it extra hard as you don't need to figure out which departure field is which for the answer they want.
Title: Re: Advent of Code
Post by: Ben T on 18 December, 2020, 12:24:40 pm
Day 18 quite interesting
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 18 December, 2020, 12:52:18 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 18 December, 2020, 12:58:59 pm
Day 18 part 1:
https://docs.google.com/spreadsheets/d/1SmJDMWM0QfYyfTanZWOrZEGvkDF6yA8EabCrKCAXtdc/edit?usp=sharing

(click to show/hide)

ETA: Part 2
https://docs.google.com/spreadsheets/d/1r78qCZenNR7SrqM1HmzznSoJcvQ4im_SmbZ1TcKr0UY/edit?usp=sharing
Title: Re: Advent of Code
Post by: tonycollinet on 18 December, 2020, 09:20:20 pm
Excuse my French, but Holy Hell day 18 (part 1) was a fucking BASTARD.

I could not get my head round parsing the brackets, and then calculating in parsed order. I have a serious headache now. And that was *with*
(click to show/hide)
I'm also certain that there must be a more elegant recursive approach, but I just couldn't get there.


Part two was a doddle - just a minor change to the 'calculate flat string' function.

Code here has a metric shedload of diagnostic print statements that I am not going to remove  ;)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 19 December, 2020, 03:31:01 am
For day 18 my first attempt tried to have recursion for both brackets and for dealing with left to right precedence but it all got a bit mixed up, and didn't get the precedence correct for operators after brackets. It was a bit frustrating that it was fine for shorter lines in my puzzle input, but fell over with the longer ones.

My working attempt used recursion on the brackets. The function found if there were any brackets, and if so, found the highest level of brackets, and then found the first instance of that level. The function would then call itself twice, in the form f( [part before bracket] . f( [part inside bracket] . [part after bracket]).

I just seemed to make lots of mistakes like not calculating [part before bracket] or [part after bracket] correctly, especially when one was zero length.

My code also had lots of diagnostic print statements, although I only used them on single lines of the puzzle input.

Title: Re: Advent of Code
Post by: grams on 19 December, 2020, 10:26:05 am
My spreadsheets finds the last opening bracket in the string and finds the first closing bracket after it. That's guaranteed to never contain any other brackets. Process the calculation inside, substitute it in the string with the answer and do it all again. No recursion required.

For part 2 only processing the calculation changed. I checked if the string contained a mix of additions and multiplications. If not, I used the formulae from part 1. If yes, I processed only the additions and gave the unfinished calculation as the result string, still with brackets. The multiplications would be processed on the next iteration of processing brackets. The latter is largely a limitation of doing it with a spreadsheet.

Day 19 part 1:
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2020, 12:59:25 pm
Day 19, late to start it as I had family stuff to do in the morning.

Expected my initial semi-naive algorithm to require rework to speed it up or prevent it wasting time going down dead ends but it gave me the right answer for part 1 in under a second.

Also lucky that the way I'd implemented it meant that part 2 was a doddle. According to the stats I got the second star just 75 seconds after the first. All I did was tweak my input accordingly and the right answer for part 2 popped out straight away.
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2020, 05:09:22 pm
I think Day 19 (and maybe Day 18) has seen a big slow down in people completing.

This could be for several reasons:-
* There's a natural daily drop-off of people completing each day
* Many people have started their holidays at this point (my last working day for this year was yesterday for example)
* Natural weekend slowdown

But the biggest reason, I'd suggest, is that day 18 and Day 19 are the first problems that weren't just (IMHO) "simple" programming problems. By this I mean "programming" in terms of knowing what to tell the computer to do in order to solve the problem, i.e. procedural programming.

Whereas day 18 and 19 it's not so obvious what the procedure for solving the problem actually is. It's not a case of "for each point in 3D/4D space calculate the number of neighbours and iterate" or "parse the list of passwords and test them against these rules".
Title: Re: Advent of Code
Post by: Pickled Onion on 19 December, 2020, 05:38:51 pm
Excuse my French, but Holy Hell day 18 (part 1) was a fucking BASTARD.

I could not get my head round parsing the brackets, and then calculating in parsed order.

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 19 December, 2020, 06:07:42 pm
Had a catch up after 3 days off. Need to go back to multi dimensional life as my cunning several dimensions all in one integer is not quite  working.
Title: Re: Advent of Code
Post by: Davef on 19 December, 2020, 06:52:11 pm
I did day18 part 1 with no library calls and minimal c with recursion

(click to show/hide)

Part 2 I went a bit wild and used a c++ string class. Feeling a bit dirty.

(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 19 December, 2020, 08:11:32 pm
Day 19:
(click to show/hide)
Title: Re: Advent of Code
Post by: tonycollinet on 19 December, 2020, 10:56:58 pm
I have to confess, 19p2 has me beat.
Title: Re: Advent of Code
Post by: grams on 19 December, 2020, 11:19:20 pm
I have to confess, 19p2 has me beat.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2020, 11:19:42 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2020, 11:31:57 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 20 December, 2020, 12:05:02 am
I'm struggling on day 19. After some effort I got an algorithm to run that produces 2^21 rules, each of 24 characters in length. The length isn't set in the algorithm, the 24 is what comes out of the data.

None of those match the messages.

I've run through the first option for each rule set and it seems to work out to the first rule that my algorithm produces.
Title: Re: Advent of Code
Post by: Diver300 on 20 December, 2020, 12:36:55 am
I'm struggling on day 19. After some effort I got an algorithm to run that produces 2^21 rules, each of 24 characters in length. The length isn't set in the algorithm, the 24 is what comes out of the data.

None of those match the messages.

I've run through the first option for each rule set and it seems to work out to the first rule that my algorithm produces.
I've just realised my counting of the matches with the messages was wrong. I've done the first part.
Title: Re: Advent of Code
Post by: tonycollinet on 20 December, 2020, 09:58:05 am
I've reached the point where the time to solve the puzzles is longer than the available time I have each day. I'm going to carry on, but no longer attempt to keep up. Falling of the back of the peloton as it were :D
Title: Re: Advent of Code
Post by: grams on 20 December, 2020, 12:07:10 pm
Day 20 part 1:
(click to show/hide)
Title: Re: Advent of Code
Post by: Croft on 20 December, 2020, 01:18:39 pm
Day 20 part 1:
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2020, 04:05:54 pm
2020 day 20. That was fun. I was in and out doing various bits so my time was rather fragmented.

Probably took me 90 minutes or so whilst actually sat at a computer, but that was spread out over ~8h or so, and some of those other 6.5h not at a computer were spent thinking about various bits so it would have taken me more than 90 minutes if I sat down to do it in one go (or maybe I would have gained some time not being so distracted or having to mentally get back into it, anyway, who knows).

Spotted the trick for part 1 and did that quite quickly, obviously part 2 renders that trick not so useful, but it does help with how you need to go about the major chunk of part 2.

Annoying as I had an off by one error in part 2 that meant I got the correct answer for the example but not for my input (always fun when that happens). Also annoying that I had to go out this afternoon for a long walk and only fixed it when back (within 2 minutes!), so it could have been finished 3h earlier.

Interesting problem. Was good to break it down into little chunks and solve each of those (with some testing!) and see it all assemble together to give the answer.

[EDIT] I don't look at the leaderboards until I've got both stars so I never really know whether it's a hard problem or whether I'm just missing something obvious. It's my best placing on part 2 so far this year (3141) which taking into account the large amount of time away from the computer, is good going.
Title: Re: Advent of Code
Post by: Ben T on 20 December, 2020, 04:10:18 pm
Found day 19 part 2 quite hard but have done it now.

(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 20 December, 2020, 06:30:23 pm
Day 20 parts 1 and 2:
https://docs.google.com/spreadsheets/d/1pMovEAF1L-UlmCy6rSLCFxMGXzA6VrhzESYRUmPPTQY/edit?usp=sharing

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2020, 08:35:05 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 20 December, 2020, 10:45:12 pm
I thought the second part of today’s was a bit of a slog. Certainly no solution I could see in a few lines of code though I could see what I had to do -  plenty of opportunity for errors.
Title: Re: Advent of Code
Post by: Davef on 21 December, 2020, 09:49:30 am
Day 21 part 2 seemed rather trivial. Perhaps I had over-solved part 1.
Title: Re: Advent of Code
Post by: Croft on 21 December, 2020, 10:05:36 am
(click to show/hide)
Title: Advent of Code
Post by: Davef on 21 December, 2020, 10:15:05 am
(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 21 December, 2020, 12:45:19 pm
Day 21 part 2 seemed rather trivial. Perhaps I had over-solved part 1.

I can't see how part 1 can be solved without going most of the way to solving part 2.
(click to show/hide)
Title: Re: Advent of Code
Post by: grams on 21 December, 2020, 02:42:38 pm
Day 21:
https://docs.google.com/spreadsheets/d/1jEu0iCON4JgT1V5ee8U4zAsdBD3f9Ly33wvktBDqNfQ/edit?usp=sharing

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2020, 07:49:41 pm
Day 20 alternative input: https://gist.github.com/alexgreenbank/3a5dcb1a2854321558509247b1ed78e4
Title: Re: Advent of Code
Post by: grams on 21 December, 2020, 11:49:21 pm
Day 20 alternative input: https://gist.github.com/alexgreenbank/3a5dcb1a2854321558509247b1ed78e4

Needs more sea monsters.
https://docs.google.com/spreadsheets/d/1dhOAv1rMzblj7Y6POpbM1DPKnj3eypgsz0fC5JPrXas/edit#gid=901221645

Title: Advent of Code
Post by: Davef on 22 December, 2020, 02:24:32 pm
Day 20 alternative input: https://gist.github.com/alexgreenbank/3a5dcb1a2854321558509247b1ed78e4
Lost on me as my solution didn’t actually rotate or stitch together the data but just kept the original data along with a list of transformations. With hindsight this was a mistake because although efficient once working it was hellish to debug. It also means I can could not visualise your data without writing some more code.
Title: Re: Advent of Code
Post by: Davef on 22 December, 2020, 02:25:57 pm
Day 22 done. Back to fine tuning my day 17 part 2 multidimensional life.
Title: Re: Advent of Code
Post by: grams on 22 December, 2020, 02:35:10 pm
Day 22 part 1 was nice and straightforward and satisfying. Part 2 just makes my eyes glaze over.
Title: Re: Advent of Code
Post by: Greenbank on 22 December, 2020, 02:37:21 pm
I purposely put in just one (although the other bits of rough sea are placed at random so it another could easily appear by random) in order to be underwhelming for people who aren't printing out the final map.

Writing something to fake the whole input is an interesting exercise. One thing I didn't think about is that not only do the edges of adjacent tiles need to match but the 4 tiles in an inner corner all need to have the same symbol ( . or # ) at that corner, which means there's some careful selection of edge "numbers" that need to be done. Ho hum.
Title: Re: Advent of Code
Post by: Greenbank on 22 December, 2020, 02:39:14 pm
Day 22 part 1 was nice and straightforward and satisfying. Part 2 just makes my eyes glaze over.

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 22 December, 2020, 02:51:42 pm
I purposely put in just one (although the other bits of rough sea are placed at random so it another could easily appear by random) in order to be underwhelming for people who aren't printing out the final map.

Writing something to fake the whole input is an interesting exercise. One thing I didn't think about is that not only do the edges of adjacent tiles need to match but the 4 tiles in an inner corner all need to have the same symbol ( . or # ) at that corner, which means there's some careful selection of edge "numbers" that need to be done. Ho hum.
To make a puzzle you just start at the top left with a couple of random 10 bit numbers and then work across from there, setting the first bit of the next to be the last bit of the previous and making sure you don’t reuse a number or it’s reverse

That sets the edges for all the tiles. Then throw them up in the air and see how they land.
Title: Re: Advent of Code
Post by: Davef on 22 December, 2020, 04:19:55 pm
Day 22 part 1 was nice and straightforward and satisfying. Part 2 just makes my eyes glaze over.
To see what was going on, for printing purposes I replaced the 50 odd numbers with letters A-ZA-z and ran part 1 again.

If I had a bigger screen I would have used the proper names of the tanks from top trumps.

This led to a better understanding of how to store the data and work efficiently. Then a few optimisations such as caching previous results and looking for simple cases (if there is no recursion you can see straightaway which player will win) and I left it to run on my grindingly slow laptop. It took 20 minutes which is probably 5 minutes on a decent pc. I still feel I am missing something.
Title: Re: Advent of Code
Post by: Pickled Onion on 22 December, 2020, 04:24:18 pm
Day 22 part 1 was nice and straightforward and satisfying. Part 2 just makes my eyes glaze over.

It definitely took me longer to understand the instructions for part 2 than to implement it, given a tidy implementation of part 1.

Day 20 was too much code for very little satisfaction. It looks like a lot of people just couldn't be bothered as I just got round to it today and still < 10,000
Title: Re: Advent of Code
Post by: Greenbank on 22 December, 2020, 09:29:52 pm
If I had a bigger screen I would have used the proper names of the tanks from top trumps.

With my usual settings (10 point Ubuntu Mono font) I can have a 546x131 char terminal window open on this monitor and, yes, it's completely readable without needing any scaling.
Title: Re: Advent of Code
Post by: grams on 22 December, 2020, 09:47:07 pm
Day 22 here, sort of:
https://docs.google.com/spreadsheets/d/1hMM1Uort-P4v3FoS3QETp7VmuIbxFlj6gUOzQknQLW8/edit?usp=sharing

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 23 December, 2020, 02:50:38 pm
Day 23 is now chugging away in the background and will take a few hours despite my fine tuning.

There is obviously a better way but I suspect the computer will find the answer before I come up with a better way of doing it.
Title: Re: Advent of Code
Post by: Greenbank on 23 December, 2020, 04:00:14 pm
Day 23 runs in a second for me. The really naive solution in perl I knocked up for part 1 was never going to perform well enough for part 2 so I did it properly in C.

(click to show/hide)

3 stars to go (day 25 part 2 is usually just having the other 49 stars).
Title: Re: Advent of Code
Post by: Davef on 24 December, 2020, 09:12:11 am
Day 24 was nice and easy.
Title: Re: Advent of Code
Post by: Greenbank on 24 December, 2020, 10:58:36 am
(click to show/hide)
Title: Advent of Code
Post by: Davef on 24 December, 2020, 12:28:42 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 24 December, 2020, 04:19:34 pm
Day 22 part 1 was nice and straightforward and satisfying. Part 2 just makes my eyes glaze over.
To see what was going on, for printing purposes I replaced the 50 odd numbers with letters A-ZA-z and ran part 1 again.

If I had a bigger screen I would have used the proper names of the tanks from top trumps.

This led to a better understanding of how to store the data and work efficiently. Then a few optimisations such as caching previous results and looking for simple cases (if there is no recursion you can see straightaway which player will win) and I left it to run on my grindingly slow laptop. It took 20 minutes which is probably 5 minutes on a decent pc. I still feel I am missing something.

not seeing what the optimisation is.
Are you actually getting any cache hits?
I've implemented a cache but not getting any hits. I've checked the equality comparison and made it so that it mirrors, i.e. if player 1 won with a hand that player 2's now got, that it returns player 2 winning. But still grinding away with no cache hits.


Title: Re: Advent of Code
Post by: Diver300 on 24 December, 2020, 06:43:17 pm
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 24 December, 2020, 07:12:17 pm
Day 22 part 1 was nice and straightforward and satisfying. Part 2 just makes my eyes glaze over.
To see what was going on, for printing purposes I replaced the 50 odd numbers with letters A-ZA-z and ran part 1 again.

If I had a bigger screen I would have used the proper names of the tanks from top trumps.

This led to a better understanding of how to store the data and work efficiently. Then a few optimisations such as caching previous results and looking for simple cases (if there is no recursion you can see straightaway which player will win) and I left it to run on my grindingly slow laptop. It took 20 minutes which is probably 5 minutes on a decent pc. I still feel I am missing something.

not seeing what the optimisation is.
Are you actually getting any cache hits?
I've implemented a cache but not getting any hits. I've checked the equality comparison and made it so that it mirrors, i.e. if player 1 won with a hand that player 2's now got, that it returns player 2 winning. But still grinding away with no cache hits.
I get a lot of cache hits but I suppose it could vary with  input could vary but it seems unlikely.
The other optimisation is based on the top trump killer card theorem I just made up. There are scenarios where you can see who will win without actually playing. The other optimisation was how to store the data so that each iteration was very efficient.
Title: Re: Advent of Code
Post by: Davef on 24 December, 2020, 07:41:19 pm
(click to show/hide)

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 24 December, 2020, 09:14:31 pm
Day 22 part 1 was nice and straightforward and satisfying. Part 2 just makes my eyes glaze over.
To see what was going on, for printing purposes I replaced the 50 odd numbers with letters A-ZA-z and ran part 1 again.

If I had a bigger screen I would have used the proper names of the tanks from top trumps.

This led to a better understanding of how to store the data and work efficiently. Then a few optimisations such as caching previous results and looking for simple cases (if there is no recursion you can see straightaway which player will win) and I left it to run on my grindingly slow laptop. It took 20 minutes which is probably 5 minutes on a decent pc. I still feel I am missing something.

not seeing what the optimisation is.
Are you actually getting any cache hits?
I've implemented a cache but not getting any hits. I've checked the equality comparison and made it so that it mirrors, i.e. if player 1 won with a hand that player 2's now got, that it returns player 2 winning. But still grinding away with no cache hits.
I get a lot of cache hits but I suppose it could vary with  input could vary but it seems unlikely.
The other optimisation is based on the top trump killer card theorem I just made up. There are scenarios where you can see who will win without actually playing. The other optimisation was how to store the data so that each iteration was very efficient.

Not sure what optimisations are required if you implement it as it says. Mine completes in ~5 seconds even with a relatively naive perl implementation. The only caching I do is to prevent it repeating a hand-state as per the instructions, and that's just per game.

My input meant I processed somewhere under 20,000 games and 2.1 million rounds in total.

Early on I forgot to truncate the decks for the sub-games and that meant it had no chance of returning before the heat death of the universe. Sure you aren't doing the same?
Title: Re: Advent of Code
Post by: freeflow on 25 December, 2020, 09:55:49 am
Day 25.  I get an answer which passes the test case and meets all the criteria but its not the correct answer!!


(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 25 December, 2020, 10:07:29 am
Not sure what optimisations are required if you implement it as it says. Mine completes in ~5 seconds even with a relatively naive perl implementation. The only caching I do is to prevent it repeating a hand-state as per the instructions, and that's just per game.

My input meant I processed somewhere under 20,000 games and 2.1 million rounds in total.

Early on I forgot to truncate the decks for the sub-games and that meant it had no chance of returning before the heat death of the universe. Sure you aren't doing the same?

initially, yes, but have changed it to truncate now and doesn't seem any faster.
It seems to get more 'repeats' per 1,000 games than when it didn't truncate.
It's actually a lot slower per 1,000 games but I was hoping that it would mean there would be fewer to go through in total.
My only thought is it could be the list copying in order to keep the state after a sub game as it was when the subgame started that's slowing it down every time.
Title: Re: Advent of Code
Post by: Greenbank on 25 December, 2020, 11:53:31 am
Day 25.  I get an answer which passes the test case and meets all the criteria but its not the correct answer!!


(click to show/hide)

Yes, 2020 day 25 took more time reading and re-reading than it did actually writing the code.

(click to show/hide)
Title: Re: Advent of Code
Post by: Davef on 25 December, 2020, 04:12:03 pm
Not sure what optimisations are required if you implement it as it says. Mine completes in ~5 seconds even with a relatively naive perl implementation. The only caching I do is to prevent it repeating a hand-state as per the instructions, and that's just per game.

My input meant I processed somewhere under 20,000 games and 2.1 million rounds in total.

Early on I forgot to truncate the decks for the sub-games and that meant it had no chance of returning before the heat death of the universe. Sure you aren't doing the same?

initially, yes, but have changed it to truncate now and doesn't seem any faster.
It seems to get more 'repeats' per 1,000 games than when it didn't truncate.
It's actually a lot slower per 1,000 games but I was hoping that it would mean there would be fewer to go through in total.
My only thought is it could be the list copying in order to keep the state after a sub game as it was when the subgame started that's slowing it down every time.
My list copying is minimal as I have each players hand as string. The game state is the two strings concatenated with an * in between.

For efficiency each player is actually slightly more than a string - it also has a number of characters to ignore off the beginning which makes for less work but that is thrown away when I save.

I actually misunderstood the instructions about repeated states in a game and had implemented it globally before I reread and added it locally too.
Title: Re: Advent of Code
Post by: Davef on 25 December, 2020, 04:18:44 pm
Day 25.  I get an answer which passes the test case and meets all the criteria but its not the correct answer!!


(click to show/hide)
If you look at the Wikipedia articule on modular arithmetic https://en.wikipedia.org/wiki/Modular_arithmetic there is an efficient c routine for raising a to the power of b.  I still had a copy from last year. That said it would would be relatively quick without it.

Today was my best ranking - in the 2000s because I was on early morning turkey duty.

I also woke up knowing the correct way to do day 23. Problem solving whilst asleep is not something I have done since an undergraduate decades ago.
Title: Re: Advent of Code
Post by: Davef on 25 December, 2020, 09:24:45 pm
Not sure what optimisations are required if you implement it as it says. Mine completes in ~5 seconds even with a relatively naive perl implementation. The only caching I do is to prevent it repeating a hand-state as per the instructions, and that's just per game.

My input meant I processed somewhere under 20,000 games and 2.1 million rounds in total.

Early on I forgot to truncate the decks for the sub-games and that meant it had no chance of returning before the heat death of the universe. Sure you aren't doing the same?

initially, yes, but have changed it to truncate now and doesn't seem any faster.
It seems to get more 'repeats' per 1,000 games than when it didn't truncate.
It's actually a lot slower per 1,000 games but I was hoping that it would mean there would be fewer to go through in total.
My only thought is it could be the list copying in order to keep the state after a sub game as it was when the subgame started that's slowing it down every time.
I did have another optimisation that gave an answer in fractions of a second. Unfortunately the wrong answer. It is has been bothering me why it didn’t work and I just realised so I now have a solution that only takes a few seconds.
Title: Re: Advent of Code
Post by: Croft on 26 December, 2020, 08:07:12 am
(click to show/hide)
Title: Re: Advent of Code
Post by: Ben T on 26 December, 2020, 10:29:59 am
Not sure what optimisations are required if you implement it as it says. Mine completes in ~5 seconds even with a relatively naive perl implementation. The only caching I do is to prevent it repeating a hand-state as per the instructions, and that's just per game.

My input meant I processed somewhere under 20,000 games and 2.1 million rounds in total.

Early on I forgot to truncate the decks for the sub-games and that meant it had no chance of returning before the heat death of the universe. Sure you aren't doing the same?

initially, yes, but have changed it to truncate now and doesn't seem any faster.
It seems to get more 'repeats' per 1,000 games than when it didn't truncate.
It's actually a lot slower per 1,000 games but I was hoping that it would mean there would be fewer to go through in total.
My only thought is it could be the list copying in order to keep the state after a sub game as it was when the subgame started that's slowing it down every time.
I did have another optimisation that gave an answer in fractions of a second. Unfortunately the wrong answer. It is has been bothering me why it didn’t work and I just realised so I now have a solution that only takes a few seconds.

hmm, weird. Rewrote it in c++ and it gets the correct answer in under a second, with about 14,000 games. No idea what the previous program was doing.
Title: Re: Advent of Code
Post by: Davef on 26 December, 2020, 10:51:39 am
Not sure what optimisations are required if you implement it as it says. Mine completes in ~5 seconds even with a relatively naive perl implementation. The only caching I do is to prevent it repeating a hand-state as per the instructions, and that's just per game.

My input meant I processed somewhere under 20,000 games and 2.1 million rounds in total.

Early on I forgot to truncate the decks for the sub-games and that meant it had no chance of returning before the heat death of the universe. Sure you aren't doing the same?

initially, yes, but have changed it to truncate now and doesn't seem any faster.
It seems to get more 'repeats' per 1,000 games than when it didn't truncate.
It's actually a lot slower per 1,000 games but I was hoping that it would mean there would be fewer to go through in total.
My only thought is it could be the list copying in order to keep the state after a sub game as it was when the subgame started that's slowing it down every time.
I did have another optimisation that gave an answer in fractions of a second. Unfortunately the wrong answer. It is has been bothering me why it didn’t work and I just realised so I now have a solution that only takes a few seconds.

hmm, weird. Rewrote it in c++ and it gets the correct answer in under a second, with about 14,000 games. No idea what the previous program was doing.
Your computer is faster than my old laptop.
Title: Advent of Code
Post by: Davef on 26 December, 2020, 10:55:17 am
My day 23 part b cups speedy solution minimal version which after initialisation is technically one line of c (no curly brackets). It s about as fast as it can be too


(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 26 December, 2020, 04:21:14 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 26 December, 2020, 07:42:22 pm
Done. Not helped by the fact that the dot net debugger crashes on the Apple M1 chip when stepping off a break point. Had to go back to old school debugging by print statements.

Now to go back to 2019 - I stopped at day 15. This year's seems tamer than previous years, or perhaps it's just easier with practice.
Title: Re: Advent of Code
Post by: Ben T on 27 December, 2020, 09:43:28 pm
For day 23 part 2 my program produces the right numbers for the example input 389125467 => (934001 x 159792 = 149245887792)
but wrong for my actual input.
Bloody annoying.
Definitely not overflown as I've converted to 64 bit numbers before making the product.
Struggling to see how it would be right for the example but wrong for my actual.
Would anyone who's got it right mind posting their input and the two numbers clockwise from 1 please and the product?
Runs in a second or two so easy for me to check

Title: Advent of Code
Post by: Davef on 27 December, 2020, 10:03:05 pm
For day 23 part 2 my program produces the right numbers for the example input 389125467 => (934001 x 159792 = 149245887792)
but wrong for my actual input.
Bloody annoying.
Definitely not overflown as I've converted to 64 bit numbers before making the product.
Struggling to see how it would be right for the example but wrong for my actual.
Would anyone who's got it right mind posting their input and the two numbers clockwise from 1 please and the product?
Runs in a second or two so easy for me to check
Your puzzle answer was 412990492266.

Both parts of this puzzle are complete! They provide two gold stars: **

At this point, all that is left is for you to admire your Advent calendar.

Your puzzle input was 963275481.


You could also test your input against my code posted a few posts above #1103

The only bit that needed 64 bit was the final multiply
Title: Re: Advent of Code
Post by: Ben T on 28 December, 2020, 09:41:41 am
For day 23 part 2 my program produces the right numbers for the example input 389125467 => (934001 x 159792 = 149245887792)
but wrong for my actual input.
Bloody annoying.
Definitely not overflown as I've converted to 64 bit numbers before making the product.
Struggling to see how it would be right for the example but wrong for my actual.
Would anyone who's got it right mind posting their input and the two numbers clockwise from 1 please and the product?
Runs in a second or two so easy for me to check
Your puzzle answer was 412990492266.

Both parts of this puzzle are complete! They provide two gold stars: **

At this point, all that is left is for you to admire your Advent calendar.

Your puzzle input was 963275481.


You could also test your input against my code posted a few posts above #1103

The only bit that needed 64 bit was the final multiply
Weird. My code gets the right answer for your input.

But still claims to be wrong for my own. Oh well, I'll give your code a compile and see what it gets...
Title: Re: Advent of Code
Post by: Ben T on 28 December, 2020, 12:11:32 pm
Your puzzle answer was 412990492266.

Both parts of this puzzle are complete! They provide two gold stars: **

At this point, all that is left is for you to admire your Advent calendar.

Your puzzle input was 963275481.


You could also test your input against my code posted a few posts above #1103

The only bit that needed 64 bit was the final multiply
Weird. My code gets the right answer for your input.

But still claims to be wrong for my own. Oh well, I'll give your code a compile and see what it gets...
[/quote]
Got it now, thanks davef - was a bug in setting up the initial data.
Was using a linked list and wasn't setting up the initial data correctly, so if the input was 315679824, I was setting e.g. 2.next = 4, and 4.prev = 2, and setting 4's next to 10.... but forgot to set 10's prev to 4.
Might try and create a generic linked list class, as the code is a bit of a mess and a pita to debug.
Title: Re: Advent of Code
Post by: Ben T on 28 December, 2020, 12:16:23 pm
Quote
Your puzzle answer was 412990492266.

Both parts of this puzzle are complete! They provide two gold stars: **

At this point, all that is left is for you to admire your Advent calendar.

Your puzzle input was 963275481.


You could also test your input against my code posted a few posts above #1103

The only bit that needed 64 bit was the final multiply
Weird. My code gets the right answer for your input.

But still claims to be wrong for my own. Oh well, I'll give your code a compile and see what it gets...
Got it now, thanks davef - was a bug in setting up the initial data.
Was using a linked list and wasn't setting up the initial data correctly, so if the input was 315679824, I was setting e.g. 2.next = 4, and 4.prev = 2, and setting 4's next to 10.... but forgot to set 10's prev to 4.
Might try and create a generic linked list class, as the code is a bit of a mess and a pita to debug.

My somewhat more verbose than your code:
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 28 December, 2020, 05:52:16 pm
Implemented day 25 properly and got the time down to 1189usec for my input.

It finds the answer for the example input in 102usec.

(Note usec not msec. 1189usec is ~1.2msec.)
Title: Re: Advent of Code
Post by: Davef on 28 December, 2020, 06:27:59 pm
Implemented day 25 properly and got the time down to 1189usec for my input.

It finds the answer for the example input in 102usec.

(Note usec not msec. 1189usec is ~1.2msec.)
It is a flawed security system if it can be broken by some arithmetic !
Title: Re: Advent of Code
Post by: Pickled Onion on 28 December, 2020, 07:55:08 pm
(day 15 2019)

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)

Bah! Mapped out the route to the Oxygen by finding the walls and marking any dead-ends on backtrack. This gave all the map that was needed and the route back to origin was then the only one left.

Now for part two I need the whole map!  :facepalm:
Title: Re: Advent of Code
Post by: Greenbank on 28 December, 2020, 09:25:08 pm
Implemented day 25 properly and got the time down to 1189usec for my input.

It finds the answer for the example input in 102usec.

(Note usec not msec. 1189usec is ~1.2msec.)
It is a flawed security system if it can be broken by some arithmetic !

And I hadn't bothered optimising it. Down to 240usec now.

It's not just arithmetic, it's searching the full search space to solve a^e = x mod m (i.e. finding e for a given a, x and m). It just does it in a more efficient way with a lot fewer calculations.

(In this example 7^e = x mod 20201227)

The security system is a little better if you use much bigger primes. 20201227 is a tad on the small size.

If I give you even a 256-bit prime such as 90903494037702082433862493857994179414185677901950849383197625766750833066817 then it's not so quick or easy.
Title: Advent of Code
Post by: Davef on 29 December, 2020, 09:28:47 am
Here is my day 25. I think it is quite efficient both in terms of performance and typing and is surprisingly readable. With the exception of the sea monster I have them all down to a handful of lines of code. Just fine tuning my 4d life.

(click to show/hide)

Or if you were happy to take a punt on which key was easier to find you could remove f and g but if one was much easier than the other it could be much slower

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 01 January, 2021, 05:27:29 pm
Can't see it mentioned anywhere but there's Project Euler too, for anyone wanting to continue with problems throughout the year.

I've made a thread for it here: https://yacf.co.uk/forum/index.php?topic=117960.0 so not to clutter up this one (which we can save for AoC).
Title: Re: Advent of Code
Post by: Pickled Onion on 01 January, 2021, 06:27:25 pm
Can't see it mentioned anywhere but there's Project Euler too, for anyone wanting to continue with problems throughout the year.

I've made a thread for it here: https://yacf.co.uk/forum/index.php?topic=117960.0 so not to clutter up this one (which we can save for AoC).

Thanks, but I think I'm going to be busy going over the previous years' ones I gave up on at the time. :-)
Title: Re: Advent of Code
Post by: Pickled Onion on 02 January, 2021, 09:06:51 pm
Day 17 (2019). Another example of READ THE TEXT, then READ IT AGAIN.

The "obvious" route, of going straight across each intersection, might have led to a final set of instructions that could not be compressed to fit the input instruction rules.

Having to then go back and make the first part of part 2 output every possible permutation until one that could be compressed adequately would have been less fun.

A transcription error meant I missed the obvious route (and didn't look for spoilers). So I implemented the "every permutation" with linked lists and recursion. It was a rather laborious, but popped out the answer very quickly.
Title: Re: Advent of Code
Post by: Croft on 30 November, 2021, 06:59:15 pm
It's that time of year again. Anyone doin'?

https://adventofcode.com/

Private leaderboard code that YACF people have been using for a few years now: 48462-ea506236
Title: Re: Advent of Code
Post by: Pingu on 02 December, 2021, 11:31:00 pm
First two days weren't too hard. But then I probably think that every year  :P
Title: Re: Advent of Code
Post by: perpetual dan on 04 December, 2021, 04:59:34 pm
We did a bit of this as learning with interns at work. I seem to have done four days now, luring me in :)
Title: Re: Advent of Code
Post by: Diver300 on 06 December, 2021, 05:33:27 am
Day 6
(click to show/hide)
Title: Re: Advent of Code
Post by: perpetual dan on 07 December, 2021, 08:08:55 pm
Day 6
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 08 December, 2021, 10:28:50 am
Day 6
(click to show/hide)

(click to show/hide)
(click to show/hide)
Title: Re: Advent of Code
Post by: perpetual dan on 08 December, 2021, 10:41:53 am
Day 6
(click to show/hide)

(click to show/hide)
(click to show/hide)

My day job tends to call on that kind of optimization, so i had a similar predisposition :)

In contrast, my solution for today's feels quite clunky. Though coding before coffee might be an issue.
Title: Re: Advent of Code
Post by: Diver300 on 08 December, 2021, 01:10:56 pm
Day 6
(click to show/hide)

(click to show/hide)
(click to show/hide)

My day job tends to call on that kind of optimization, so i had a similar predisposition :)

In contrast, my solution for today's feels quite clunky. Though coding before coffee might be an issue.
Day 8
Even though today's was a bit clunky, the only solution that I saw didn't involve going round anything more than a handful of times.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pingu on 08 December, 2021, 03:49:47 pm
Day 6
(click to show/hide)

(click to show/hide)
(click to show/hide)

My day job tends to call on that kind of optimization, so i had a similar predisposition :)

In contrast, my solution for today's feels quite clunky. Though coding before coffee might be an issue.

(click to show/hide)
  :P
Title: Re: Advent of Code
Post by: Diver300 on 12 December, 2021, 09:31:45 am
Day 12
Part 1
(click to show/hide)
Part 2
(click to show/hide)
Title: Re: Advent of Code
Post by: perpetual dan on 12 December, 2021, 10:38:36 pm
Day 12 I got the first bit done ok, then had stuff to do.

Part two broke my previous (learning a new library) approach. Starting again with something simpler got me there.

Deliberate loops in a routing algorithm as part of the spec was quite upsetting though.
Title: Re: Advent of Code
Post by: Diver300 on 14 December, 2021, 08:17:53 am
Day 14
(click to show/hide)
Title: Re: Advent of Code
Post by: perpetual dan on 14 December, 2021, 11:55:20 am
Day 14
(click to show/hide)

I took a couple of dead ends before getting it working in reasonable time today, but I still got my best part two position so far without any alarm clock shenanigans.

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 15 December, 2021, 07:03:30 am
Day 15
My code works for the demo, parts 1 and 2, and for my puzzle input part 1, and it appears to work for my puzzle input in part 2, but it gives the wrong answer. I am a bit stuck now.

Edit. Found the problem.
(click to show/hide)
Title: Re: Advent of Code
Post by: perpetual dan on 15 December, 2021, 01:41:08 pm
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 25 December, 2021, 08:13:36 pm
Day 23 was solved with (effectively) pencil and paper.

I did use a computer to spot my stupid adding up mistake.
Title: Re: Advent of Code
Post by: Morat on 22 November, 2022, 10:15:15 am
gentle nudge?
Title: Re: Advent of Code
Post by: Diver300 on 30 November, 2022, 11:38:34 pm
The countdown has started.
Title: Re: Advent of Code
Post by: freeflow on 01 December, 2022, 08:00:47 am
I've been doing advent of code in VBA for the past few years, but I've now upgraded to twinbasic.  Over the years I've developed a library to help eliminate a lot of the VBA boilerplate code needed to solve AoC problems.  So this morning I was delighted (and astonished) when my library worked well in solving the day 1 problem.
(click to show/hide)






Title: Re: Advent of Code
Post by: Pickled Onion on 03 December, 2022, 07:50:06 pm
I had to look up TwinBasic, and found:

Quote
twinBASIC is an exciting new project that aims to provide a full replacement IDE and compiler for VB6

For the love of $Deity WHY??
Title: Re: Advent of Code
Post by: Pickled Onion on 10 December, 2022, 06:20:48 pm
Well day 9 pt 2 got me. The test data got the right answer, and printing out the visited points exactly matched the example, but the final answer was wrong. Only comparing the intermediates showed that I'd misunderstood the rules.

Bah! This is not the first one this year where the tests have passed for the wrong implementation.
Title: Re: Advent of Code
Post by: Diver300 on 10 December, 2022, 08:56:30 pm
Well day 9 pt 2 got me. The test data got the right answer, and printing out the visited points exactly matched the example, but the final answer was wrong. Only comparing the intermediates showed that I'd misunderstood the rules.

Bah! This is not the first one this year where the tests have passed for the wrong implementation.
I had the same.

I got program to draw out the path of the last knot in the rope, and realised that my first attempt had gaps in the path.
Title: Re: Advent of Code
Post by: freeflow on 10 December, 2022, 11:01:02 pm
One of the joys of advent of code is teaching folks about how assumptions are made.  The problems need very careful reading to ensure you have eliminated stuff that has been included unnecessarily and stuff which is implicit - usually hidden in plain view in the details of the examples.  God knows how people who don't have English as a first language cope, or maybe its easier as things are read properly rather than quickly scanned for 'salient' points.
Title: Re: Advent of Code
Post by: Diver300 on 11 December, 2022, 08:26:12 am
Day 11 needed a trick so that the solution didn't become unmanageable for a normal computer.
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 15 December, 2022, 09:08:21 am
For Day 15, the scale is too large for a brute-force solution.
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 18 December, 2022, 08:51:45 pm
Day 16, part 2.
The code that got the right answer for me needed to try 8,142,958,394 possibilities and took something like an hour to run.
The same code run on the example only needed 37,623 possibilities and runs almost instantly.
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 23 December, 2022, 12:12:45 pm
Day 22: Monkey Map Part 2
The statistics show that quite a low proportion of the solutions of the first part got converted into solutions of the second part.

The YACF private leaderboard has 5 solutions to the first part and only 3 to the second part. There are only 4 first part only solutions for the whole of the private leaderboard, and two of those are for Day 22.
(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 01 December, 2023, 08:35:50 am
Advent of code 2023 has started.

Day 1
(click to show/hide)
Title: Re: Advent of Code
Post by: R_nger on 01 December, 2023, 06:52:07 pm
Advent of code 2023 has started.

Day 1
(click to show/hide)

That’s plain greedy  ;)
Title: Re: Advent of Code
Post by: Pickled Onion on 02 December, 2023, 10:58:48 am
That was a bit sneaky for a day 1. Depending on your approach it would have been quite easy to pass a test on the sample but get the wrong answer on the puzzle.

I see quite a few people in the private leaderboard haven't bothered completing part 2 yet.
Title: Re: Advent of Code
Post by: Diver300 on 02 December, 2023, 12:53:53 pm
That was a bit sneaky for a day 1. Depending on your approach it would have been quite easy to pass a test on the sample but get the wrong answer on the puzzle.
Only for part 2, but yes, the sample was no help at all for the difference between part 2 and part 1

I see quite a few people in the private leaderboard haven't bothered completing part 2 yet.
Part 2 needs to detect several characters to get a match, while part one only needs to detect a single character.

I was pleasantly surprised when my additions for part 2 worked first time (after the errors that wouldn't compile had been sorted)
Title: Re: Advent of Code
Post by: jwo on 02 December, 2023, 07:10:32 pm
Only for part 2, but yes, the sample was no help at all for the difference between part 2 and part 1

Except that some of the words in the sample did give a clue about the main gotcha with part 2, even if it didn't actually have an effect when processing the sample.
Title: Re: Advent of Code
Post by: vorsprung on 02 December, 2023, 09:30:10 pm
Advent of code 2023 has started.

Day 1
(click to show/hide)

and once again i can't be arsed with it
Title: Re: Advent of Code
Post by: Diver300 on 05 December, 2023, 06:53:42 am
Day 5
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 05 December, 2023, 10:42:43 pm
Not wanting to wait 15 mins, I spent an hour writing a recursive split which spat out the answer in 15 seconds.

Thinking I might be descending the same tree multiple times, I added a cache but it only knocked off a second. There is probably a better way, but it seems OK for < 100 lines of C#.
Title: Re: Advent of Code
Post by: Diver300 on 05 December, 2023, 11:37:26 pm
I decided that there had to be an elegant solution, and what I have now written, in far more than 15 minutes, runs in less than a second. It's not recursive.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 06 December, 2023, 08:21:24 pm
Yes, spotted the range thing later.

Day 6 was a bit easy

(click to show/hide)
Title: Re: Advent of Code
Post by: jwo on 06 December, 2023, 09:59:39 pm
Day 6:

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 06 December, 2023, 10:12:41 pm
Yes, spotted the range thing later.

Day 6 was a bit easy

(click to show/hide)
jwo posted while I was writing this.
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 07 December, 2023, 10:51:33 am
Symmetric rather than Normal. So you only need to find the lower bound.
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2023, 12:30:18 pm
Pickled O: I'm not really familiar with C#. What does Select(x=> x.Ways()) do?

It's Linq - Select takes an enumeration of races, and for each one asks it how many ways can that race be won, returning an enumeration of those. Aggregate takes an enumeration of numbers and applies the function on that number (y) and the previous result (x) with the seed (1) used as x for the first operation.

I'm seeing how far I can go writing all solutions in Linq. Eg, day 1 was quite neatly

    public long Part1()
    {
        return Lines.ElfinToNumber().Sum();
    }
    public long Part2()
    {
        return Lines.WordsToDigits().ElfinToNumber().Sum();
    }
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2023, 05:22:06 pm
And day 7 reads nicely with Linq

(click to show/hide)

It was fun writing the comparer.
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2023, 08:15:32 pm
Day 8, a bit of a cheat because I wrote GetSteps as normal function but the resulting Linq is still pleasing

(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 09 December, 2023, 10:30:12 pm
Day 9, that was interesting, I've never used Zip before

(click to show/hide)
Title: Re: Advent of Code
Post by: Diver300 on 10 December, 2023, 05:12:11 pm
Day 10 pt 2 started to be interesting.
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2023, 07:08:08 pm
Day 10 part 2:-

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 10 December, 2023, 07:16:45 pm
Day 5 part 2:-
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 10 December, 2023, 07:38:03 pm
Day 10 part 2:-

(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: jwo on 10 December, 2023, 11:14:28 pm
Day 10 part 2:

(click to show/hide)
Title: Re: Advent of Code
Post by: jwo on 13 December, 2023, 07:02:18 pm
Day 13

I enjoyed this one. Not so much in getting an answer, but in doing so efficiently.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 13 December, 2023, 08:42:59 pm
Day 13

(click to show/hide)
Title: Re: Advent of Code
Post by: jwo on 13 December, 2023, 10:19:21 pm
Day 13

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 18 December, 2023, 12:31:26 pm
Day 18

(click to show/hide)

Total time for 2023 so far (up to and including day 18) is 0.378s, so still a few left to optimise (days 17, 16, and 14 take the longest).
Title: Re: Advent of Code
Post by: jwo on 18 December, 2023, 10:37:56 pm
Day 18

Total time for 2023 so far (up to and including day 18) is 0.378s, so still a few left to optimise (days 17, 16, and 14 take the longest).

Impressive. Are you still writing them in C?

I've just totalled mine (JavaScript) up to and including Day 18. I come out at 1.3 seconds total, with those same slow days being over 80% of that time.

Day 18 was my favourite so far.
(click to show/hide)

(click to show/hide)
Title: Re: Advent of Code
Post by: vorsprung on 19 December, 2023, 09:58:21 am
Day 96
(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2023, 10:29:33 am
I don't know how long I've spent on AoC over the years but all of the time isn't wasted (it's not all 100% productive/useful either though). I'd probably guess it's at least 40h each year.

Like jwo (and Ross and mTrak) I've got all of the stars (so far, for all years) and that represents a significant amount of time that has been put into it, but I'd count this as professional development - plus the fact that I enjoy solving these kinds of puzzles.

I'm using it as a challange but mostly to get more comfortable in a new language (Go). I did all of the previous years in a mixture of shell, C and predominantly perl. Now most of my professional coding is in Go and so that's what I'm doing 2023 in. In my Copious Free Time (TM) I'm also going back and redoing all of the previous years in Go (have about 90 days left to do). This helps me understand how I would implement certain things in this language, notably:
* Numbers > 264
* Number theory (modmul, modexp, lcm, gcd, crt, ...)
* Recursion, tail recursion
* Parsing, regexp, sorting
* Memoization and Dynamic Programming
* Sparse grids using maps, 2D, 3D, 4D+
* BFS/DFS
* Dijkstra/A* and using structures like a heap queue to implement an efficient priority queue
* Trees (binary, n-ary, red/black, etc)
etc
Title: Re: Advent of Code
Post by: jwo on 19 December, 2023, 01:15:10 pm
Wot Greenbank sed.

For me, over the years I've used AoC to improve my skills in Java, Elm, JavaScript and C++ as well as general data structures and algorithm competence. I also use it with students (from first year undergraduates to PhDs) to help them develop their algorithmic thinking, reasoning and communication. I didn't do a Comp Sci or Maths degree so AoC has been useful learning tool for me (and mostly fun).

I know Eric (the puzzle setter) creates these to help people learn, and some of the puzzles are very elegantly and subtly designed with that in mind. Clearly it's not for everyone, but for some (of us), a fun and rewarding activity.
Title: Re: Advent of Code
Post by: davelodwig on 19 December, 2023, 03:20:53 pm
I spend all day writing code and solving problems.

As much as I try to do AoC I just can't get the energy up to do it in the evenings after work.
Title: Re: Advent of Code
Post by: Greenbank on 19 December, 2023, 03:34:00 pm
I do it in the morning before work usually. My daughter leaves for school around 7.15 and so I've got ~2 hours before I start work. Usually I'd either go for a swim/bike/run in this time, or just start work early and then have a longer lunch or knock off early, but in December it's generally AoC time.

For the trickier days doing AoC may bleed over into lunchtime or the evening, but I find that subconscious thought (while I'm doing my day job) helps get me to the solution without taking too much time sat actively staring at it. Reading elsewhere (the AoC subreddit mostly) it seems I'm lucky that I'm able to put an AoC problem down once I need to focus on something else (e.g. what I get paid for) and it doesn't bother me to do so.

The weekends (or holidays) I just have to find the time whenever outside family life.

Going back and redoing all of the previous years in Go is becoming a bit of a slog, especially now that I've picked off most of the easy ones from each year, but the plan is to tackle 1-3 days at a time in the new year and I'll get through them all in a few months. Already having a solution (albeit in C/perl/?) helps. Also going back and looking at my old code is a useful exercise to see how long it takes me to understand it and whether there are any useful comments/etc.
Title: Re: Advent of Code
Post by: Greenbank on 20 December, 2023, 03:31:56 pm
Spoiler day 20

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2023, 11:11:57 am
Spoiler Day 21 part 2

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 21 December, 2023, 10:15:20 pm
2023 Day 21 Part 2 mild spoiler from the AoC Creator

(click to show/hide)
Title: Re: Advent of Code
Post by: vorsprung on 22 December, 2023, 11:51:59 am
a mixture of shell, C and predominantly perl. Now most of my professional coding is in Go

Same here
Title: Re: Advent of Code
Post by: vorsprung on 22 December, 2023, 11:55:57 am
Wot Greenbank sed.

For me, over the years I've used AoC to improve my skills in Java, Elm, JavaScript and C++ as well as general data structures and algorithm competence. I also use it with students (from first year undergraduates to PhDs) to help them develop their algorithmic thinking, reasoning and communication. I didn't do a Comp Sci or Maths degree so AoC has been useful learning tool for me (and mostly fun).

I don't have any students.  At the moment I am only mentoring one person, maybe I should teach them how to program properly.  Hmmm
Title: Re: Advent of Code
Post by: jwo on 23 December, 2023, 11:32:20 pm
Day 23

A little easier than the last few days, but struggled to get computing Part 2 to anything faster than around 10 seconds.

(click to show/hide)
Title: Re: Advent of Code
Post by: Greenbank on 27 December, 2023, 02:09:51 pm
Got there in the end as I was busy/pissed most of 24th/25th/26th.

Have to redo/optimise days 22, 23, 24, 25. Plus revisit a few days (12, 14, 16, 17, 20) that are taking a bit more than they should but it can go on the backlog for now until my brain is ready for them.
Title: Re: Advent of Code
Post by: Pickled Onion on 01 January, 2024, 08:19:44 pm
Had a bit of a break, so only on day 19.

Bah. And Grr.

Spent ages working out what would happen if the ranges on different paths overlapped, and what if a path had a disjoint range, then a bit of time coding up the range flattening... Only to find that it had been crafted so that no ranges overlapped and the simple sum of combinations for each route gave the answer.

My final code cut simply down to
(click to show/hide)
Title: Re: Advent of Code
Post by: Pickled Onion on 01 January, 2024, 08:55:41 pm
a mixture of shell, C and predominantly perl. Now most of my professional coding is in Go

Same here

I'd done* many of the previous years in Perl. A lot of the problems seemed to be geared towards languages like Perl and Python. One year I tried to solve them in regular expressions, which worked for the first several days at least.

I've learnt a huge amount by solving them in C# LINQ this year. I'll be giving a talk on LINQ Best Practice in a couple of weeks to the internal C# group, 100+ developers. It's become apparent that 90% of them are "doing it wrong", and most of the other 10% are simply following received wisdom (including me up to now). There's a paucity of good guidance or documentation on what is one of the sharpest tools in the C# box. In fact it's a lot like Perl in that it's easy to write something that works, but you need a deeper understanding to write something that Works Well and is clear/maintainable.


* not finished though