Author Topic: Advent of Code  (Read 113866 times)

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

tonycollinet

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

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

Davef

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

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

tonycollinet

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

tonycollinet

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

Davef

Advent of Code
« Reply #932 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)

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

Arellcat

  • Velonautte
Re: Advent of Code
« Reply #934 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.
Quote from: Morningsider
I like that you think any of your conveyances might qualify as "a disguise".

Davef

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

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

Re: Advent of Code
« Reply #937 on: 12 December, 2020, 01:28:50 pm »

Davef

Advent of Code
« Reply #938 on: 12 December, 2020, 02:37:02 pm »
(click to show/hide)

Ben T

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

tonycollinet

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

tonycollinet

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

Ben T

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

Davef

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

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

Ben T

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

Davef

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

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

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

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.

tonycollinet

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