EcutDavid / advent-of-code-2018

My solutions for adventofcode.com/2018

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Advent of Code 2018

My solutions for adventofcode.com/2018

My Solutions

Day Notes
1 For the problem 2, creating a hash table for the F already being created, whenever there is a new one collide with existing one, done.
2 For the problem 2, A brute force O(n ^ 2 * len(word)) solution that for each line, check all the line after it, whether the "diff" counter is equal to 1.
3 Because the "claims" all have small width and height, simply create a two-dimensional array, initialize all the slot to 0, and increment the slot based on the claim, the answer can be found.
4 Sort the input lines alphabetically, the result would be time increasing order, the answer can be found by analysing the intersections.
5 Using a doubly linked list to sort all the items, loop them until there is a loop has no collision, whenever there is a collision, drop two nodes from the list.
7 A typical topological sort problem, had fun in simulating the workers.
8 We can parse the tree recursively from the input, then, walk the tree to find the solution.
9 A great use case for the double linked list.
10 A fun question, need generate the "text" and watch console to identify what's the text.
11 Solved this problem with brute force, must be solutions that much faster there.
12 "Solved" the second problem by yet again, like day-10, finding patterns.
14 Can be solved by brute force, just keep doing what the question asks us to do until the answer appears.
15 A fun breadth-first graph search question, very easy to miss conditions and edge cases, a super nice graph question!
16 Need carefully simulate the 16 ASM operations, can use hashmaps to generate the relationship between id(the first number) and operation, due to the input is small, didn't try to make the algorithm run faster.
18 For the problem 2, instead of brute force to simulate the 1e9 "rounds", should take "snapshot" of each board, once there is two snapshots which already appeared before, the problem can be solved.
19 This is a day-16 follow up question, problem 1 can be solved with the solution from day-16, problem 2 is very tricky, had decoded the program into a high-level code(or just natural language), after that, we can understand what the program is doing, and optimize the program's time complexity.
20 Parsing a graph from the input, then, DFS to walk through the map, the hard part of parsing the input, used a recursive solution to solve that part. Wrote a more detailed explanation in this blog.
21 This is a day-19 follow up question, need to parse the asm code then find the trick there, to solve the problem.
22 From problem 2, need to generate a map that is bigger than (0, 0) - (targetX - targetY), and then, run Bellman–Ford or Dijkstra's algorithm to get the shortest path to the target.
24 A pretty straightforward challenge can use binary search for the second challenge to spend less time on validations.
25 Create a hash table which indicates what're reachable points for any giving point, then BFS/DFS(choose B or D does not matter) all the points, each tree generated by the BFS/DFS represents a group, the answer would be the count of groups.

About

My solutions for adventofcode.com/2018

License:MIT License


Languages

Language:Go 100.0%