diff --git a/challenges/2021/25-seaCucumber/README.md b/challenges/2021/25-seaCucumber/README.md new file mode 100644 index 0000000..c610098 --- /dev/null +++ b/challenges/2021/25-seaCucumber/README.md @@ -0,0 +1,2 @@ +# [Day 25: Sea Cucumber](https://adventofcode.com/2021/day/25) + diff --git a/challenges/2021/25-seaCucumber/benchmark.json b/challenges/2021/25-seaCucumber/benchmark.json new file mode 100644 index 0000000..81a1ac4 --- /dev/null +++ b/challenges/2021/25-seaCucumber/benchmark.json @@ -0,0 +1,15 @@ +{ + "day": 25, + "dir": "challenges/2021/25-seaCucumber", + "implementations": { + "Python": { + "part.1.avg": 1.2896365237236023, + "part.1.max": 1.4006781578063965, + "part.1.min": 1.2583773136138916, + "part.2.avg": 0.000003247261047363281, + "part.2.max": 0.000013828277587890625, + "part.2.min": 0.0000016689300537109375 + } + }, + "numRuns": 100 +} \ No newline at end of file diff --git a/challenges/2021/25-seaCucumber/info.json b/challenges/2021/25-seaCucumber/info.json new file mode 100644 index 0000000..84e32fb --- /dev/null +++ b/challenges/2021/25-seaCucumber/info.json @@ -0,0 +1,15 @@ +{ + "inputFile": "input.txt", + "testCases": { + "one": [ + { + "input": "v...>>.vv>\n.vv>>.vv..\n>>.>v>...v\n>>v>>.>.v.\nv>v.vv.v..\n>.>>..v...\n.vv..>.>v.\nv.v..>>v.v\n....v..v.>", + "expected": "58" + } + ], + "two": [] + }, + "incorrect": { + "one": ["406", "312"] + } +} \ No newline at end of file diff --git a/challenges/2021/25-seaCucumber/py/__init__.py b/challenges/2021/25-seaCucumber/py/__init__.py new file mode 100644 index 0000000..f4114bf --- /dev/null +++ b/challenges/2021/25-seaCucumber/py/__init__.py @@ -0,0 +1,94 @@ +from typing import Any, List, Tuple, Dict +from aocpy import BaseChallenge + + +CUCUMBER_EAST = ">" +CUCUMBER_SOUTH = "v" +EMPTY = "." + + +Point = Tuple[int, int] +SeaBed = Dict[Point, str] + + +def parse(instr: str) -> SeaBed: + lines = instr.strip().splitlines() + o: SeaBed = {} + for y, line in enumerate(lines): + for x, char in enumerate(line): + o[(x, y)] = char + return o + + +def iterate_once(sea_bed: SeaBed) -> bool: + # returns true if moves were made + + moves_made = False + + changes: SeaBed = {} + + def get_point_state(p: Point) -> str: + # if p in changes: + # return changes[p] + return + + # eastbound + for point in sea_bed: + point_content = sea_bed[point] + + if point_content != CUCUMBER_EAST: + continue + + x, y = point + + next_point = (x + 1, y) + if next_point not in sea_bed: + next_point = (0, y) + + if sea_bed[next_point] == EMPTY: + moves_made = True + changes[next_point] = point_content + changes[point] = EMPTY + + for point in changes: + sea_bed[point] = changes[point] + + changes = {} + + # southbound + for point in sea_bed: + point_content = sea_bed[point] + + if point_content != CUCUMBER_SOUTH: + continue + + x, y = point + + next_point = (x, y + 1) + if next_point not in sea_bed: + next_point = (x, 0) + + if sea_bed[next_point] == EMPTY: + moves_made = True + changes[next_point] = point_content + changes[point] = EMPTY + + for point in changes: + sea_bed[point] = changes[point] + + return moves_made + + +class Challenge(BaseChallenge): + + @staticmethod + def one(instr: str) -> int: + sea_bed = parse(instr) + i = 1 + while iterate_once(sea_bed): + i += 1 + return i + + @staticmethod + def two(instr: str) -> int: + return -1 diff --git a/challenges/2021/README.md b/challenges/2021/README.md index 09702dc..b94433d 100644 --- a/challenges/2021/README.md +++ b/challenges/2021/README.md @@ -34,6 +34,10 @@ Solutions to the [2021 Advent of Code](https://adventofcode.com/2021). | 20 - Trench Map \* | ★ ★ | [Python](20-trenchMap/py), [Nim](20-trenchMap/nim) | Took a moment to realise that the infinite grid alternates between lit and unlit, and even then I had to look at someone else's solution to realise it. | | 21 - Dirac Dice | ★ ☆ | [Python](21-diracDice/py) | Couldn't be bothered with part two - I've got too much going on at the moment to spend a lot of time thinking about it. | | 22 - Reactor Reboot | ★ ★ | [Python, OpenSCAD and Blender](22-reactorReboot/) | I did not expect to end up using 3D CAD software to complete AoC... | +| 23 - Amphipod | Unattempted | | | +| 24 - Arithmetic Logic Unit | Unattempted | | | +| 25 - Sea Cucumber | ★ ☆ | [Python](25-seaCucumber/py) | Missing some stars :( | + diff --git a/challenges/2021/running-times.png b/challenges/2021/running-times.png index c363c1e..c9d436f 100644 Binary files a/challenges/2021/running-times.png and b/challenges/2021/running-times.png differ