Author Topic: Advent of Code  (Read 112350 times)

Ben T

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

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #476 on: 12 December, 2017, 09:32:08 am »
Today was straightforward.
(click to show/hide)
"By creating we think. By living we learn" - Patrick Geddes

Oaky

  • ACME Fire Safety Officer
  • Audax Club Mid-Essex
    • MEMWNS Map
Re: Advent of Code
« Reply #477 on: 12 December, 2017, 01:57:06 pm »
Today was straightforward.
(click to show/hide)

(click to show/hide)
You are in a maze of twisty flat droves, all alike.

85.4 miles from Marsh Gibbon

Audax Club Mid-Essex Fire Safety Officer
http://acme.bike

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

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #479 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)
"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: Advent of Code
« Reply #480 on: 13 December, 2017, 10:07:13 am »

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

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #482 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)
"By creating we think. By living we learn" - Patrick Geddes

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

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

Re: Advent of Code
« Reply #485 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.
Quote from: tiermat
that's not science, it's semantics.

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

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #487 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)
"By creating we think. By living we learn" - Patrick Geddes

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

Ben T

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

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

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: Advent of Code
« Reply #491 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.

"By creating we think. By living we learn" - Patrick Geddes

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

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

Re: Advent of Code
« Reply #494 on: 14 December, 2017, 12:24:18 pm »
Day 14 relies on a code written for day 10.

(click to show/hide)
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Advent of Code
« Reply #495 on: 14 December, 2017, 12:55:18 pm »
(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #496 on: 15 December, 2017, 10:34:38 am »
Pretty simple today (day 15), no surprises.
"Yes please" said Squirrel "biscuits are our favourite things."

Oaky

  • ACME Fire Safety Officer
  • Audax Club Mid-Essex
    • MEMWNS Map
Re: Advent of Code
« Reply #497 on: 15 December, 2017, 04:50:24 pm »
(click to show/hide)
You are in a maze of twisty flat droves, all alike.

85.4 miles from Marsh Gibbon

Audax Club Mid-Essex Fire Safety Officer
http://acme.bike

Re: Advent of Code
« Reply #498 on: 15 December, 2017, 04:52:49 pm »
Ooh. Do 4 colours suffice?
"Yes please" said Squirrel "biscuits are our favourite things."

Oaky

  • ACME Fire Safety Officer
  • Audax Club Mid-Essex
    • MEMWNS Map
Re: Advent of Code
« Reply #499 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.
You are in a maze of twisty flat droves, all alike.

85.4 miles from Marsh Gibbon

Audax Club Mid-Essex Fire Safety Officer
http://acme.bike