Author Topic: Advent of Code  (Read 114012 times)

tonycollinet

  • No Longer a western province of Númenor
Re: Advent of Code
« Reply #900 on: 09 December, 2020, 08:56:44 am »
Key learning point for day 9, as in most tests:

Read the fecking question  ::-) ::-)

Re: Advent of Code
« Reply #901 on: 09 December, 2020, 05:36:11 pm »
Had the time to redo my day 9 properly.

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

Re: Advent of Code
« Reply #902 on: 10 December, 2020, 07:13:34 am »
Day 10 was quite interesting.
(click to show/hide)
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Advent of Code
« Reply #903 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.
"Yes please" said Squirrel "biscuits are our favourite things."

Davef

Re: Advent of Code
« Reply #904 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.

Re: Advent of Code
« Reply #905 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...
"Yes please" said Squirrel "biscuits are our favourite things."

Ben T

Re: Advent of Code
« Reply #906 on: 10 December, 2020, 10:43:22 am »
(click to show/hide)

(click to show/hide)

Re: Advent of Code
« Reply #907 on: 10 December, 2020, 10:50:44 am »
(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #908 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.

Re: Advent of Code
« Reply #909 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)
"Yes please" said Squirrel "biscuits are our favourite things."

tonycollinet

  • No Longer a western province of Númenor
Re: Advent of Code
« Reply #910 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)

Davef

Re: Advent of Code
« Reply #911 on: 10 December, 2020, 02:10:40 pm »
How do you do this spoiler malarkey ?

tonycollinet

  • No Longer a western province of Númenor
Re: Advent of Code
« Reply #912 on: 10 December, 2020, 02:12:00 pm »
Click the Sp button next to the
Quote
quote
button.

Davef

Advent of Code
« Reply #913 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.

Ben T

Re: Advent of Code
« Reply #914 on: 10 December, 2020, 02:47:00 pm »
How do you do this spoiler malarkey ?
[spoiler]the code[/spoiler]

Davef

Re: Advent of Code
« Reply #915 on: 10 December, 2020, 02:47:47 pm »
How do you do this spoiler malarkey ?
[spoiler]the code[/spoiler]
Thanks. Done now. See above.

Re: Advent of Code
« Reply #916 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 )
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Davef

Re: Advent of Code
« Reply #917 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.

Davef

Re: Advent of Code
« Reply #918 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)

Re: Advent of Code
« Reply #919 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.
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Davef

Re: Advent of Code
« Reply #920 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”

Re: Advent of Code
« Reply #921 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]
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #922 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.
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #923 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)

Davef

Re: Advent of Code
« Reply #924 on: 11 December, 2020, 01:40:31 pm »
Perhaps it was a tribute the great John Conway who sadly died earlier this year.