Coder Social home page Coder Social logo

advent_of_code_18's Introduction

advent_of_code_18

https://adventofcode.com/2018

Results (December 2018)

alt text

Day 15 (revisited in 2021)

  • Turns out my original algorithm was sound, the mistake for part 2 was to use binary search. It is possible to get no deaths for, say, elf damage rate 13, but to have deaths for all the numbers lower and higher like 14, 15, 16, etc. This is because the positions and movements differ depending on the damage rate. E.g. for a high damage the elf might move towards a group of goblins sooner than if elf had a lower damage rate, so would get extra rounds of multiple damage from the group.
  • Note, I rewrote the whole thing because I incorrectly thought the original was broken - the new one is much faster at least :)

Day 18 (revisited in 2021)

  • After ~600 minutes the patterns start repeating, so it is possible to skip ahead for massive time savings!

Day 20 (revisited in 2021)

  • I must have not read this properly originally, as I thought it was more complicated than it was. Basically its just using a stack where "(" is push on, "|" is peek and ")" is pop.
  • Then it is a case of keeping track of which room you are in and the distance to get to it. If you revisit a room then update the distance if the new distance is lower.
  • Just "reducing" the regex gave the correct answer to part 1, but it might be a fluke, and it certainly doesn't help with Part 2

Day 22 (revisited in 2021)

  • First attempt is BFS shortest path, takes a long long time though...
  • Small change to use a heap ordered by path length, x and then y rather than a simple queue => ~1 second!

Day 23 (revisited in 2021)

  • Struggled with a few ideas, then discussed with my wife and we came up with a sort of binary search. Failed to implement it successfully, so looked at the discussion on Reddit. Basically ended up copying this one: https://github.com/fhinkel/AdventOfCode2018/blob/master/day23.js
  • This method would fail if, say, one had 10 non-overlapping bots in one grid and 9 overlapping bots in another grid because it would choose the grid with 10 as the best solution for the next iteration.
  • The solution to this would be to not throw away the other grid but put all grids in a queue/heap which is sorted by number of bots (high to low), then by grid size (high to low) and, finally, by distance from the origin. Then all likely candidates will eventually make it to the front of the queue.
  • I'm not planning to do this ;)

TODO?

  • Day 13 is a bit slow (~25 seconds with PyPy)
  • Day 19 work out what is going on

advent_of_code_18's People

Contributors

mattclarke avatar mjclarke01 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.