diff --git a/challenges/2022/25-fullOfHotAir/README.md b/challenges/2022/25-fullOfHotAir/README.md new file mode 100644 index 0000000..9872080 --- /dev/null +++ b/challenges/2022/25-fullOfHotAir/README.md @@ -0,0 +1 @@ +# [Day 25: Full Of Hot Air](https://adventofcode.com/2022/day/25) diff --git a/challenges/2022/25-fullOfHotAir/benchmark.json b/challenges/2022/25-fullOfHotAir/benchmark.json new file mode 100644 index 0000000..c4a24a7 --- /dev/null +++ b/challenges/2022/25-fullOfHotAir/benchmark.json @@ -0,0 +1,15 @@ +{ + "day": 25, + "dir": "challenges/2022/25-fullOfHotAir", + "implementations": { + "Python": { + "part.1.avg": 0.001312760591506958, + "part.1.max": 0.003961801528930664, + "part.1.min": 0.0003647804260253906, + "part.2.avg": 0.0000055599212646484376, + "part.2.max": 0.000046253204345703125, + "part.2.min": 0.000001430511474609375 + } + }, + "numRuns": 1000 +} \ No newline at end of file diff --git a/challenges/2022/25-fullOfHotAir/info.json b/challenges/2022/25-fullOfHotAir/info.json new file mode 100644 index 0000000..2202515 --- /dev/null +++ b/challenges/2022/25-fullOfHotAir/info.json @@ -0,0 +1,26 @@ +{ + "inputFile": "input.txt", + "testCases": { + "one": [ + { + "input": "1=-0-2\n12111\n2=0=\n21\n2=01\n111\n20012\n112\n1=-1=\n1-12\n12\n1=\n122\n", + "expected": "2=-1=0" + }, + {"input": "1", "expected": "1"}, + {"input": "2", "expected": "2"}, + {"input": "1=", "expected": "1="}, + {"input": "1-", "expected": "1-"}, + {"input": "10", "expected": "10"}, + {"input": "11", "expected": "11"}, + {"input": "12", "expected": "12"}, + {"input": "2=", "expected": "2="}, + {"input": "2-", "expected": "2-"}, + {"input": "20", "expected": "20"}, + {"input": "1=0", "expected": "1=0"}, + {"input": "1-0", "expected": "1-0"}, + {"input": "1=11-2", "expected": "1=11-2"}, + {"input": "1-0---0", "expected": "1-0---0"}, + {"input": "1121-1110-1=0", "expected": "1121-1110-1=0"} + ] + } +} \ No newline at end of file diff --git a/challenges/2022/25-fullOfHotAir/py/__init__.py b/challenges/2022/25-fullOfHotAir/py/__init__.py new file mode 100644 index 0000000..7c6dd38 --- /dev/null +++ b/challenges/2022/25-fullOfHotAir/py/__init__.py @@ -0,0 +1,52 @@ +from typing import * +from aocpy import BaseChallenge + + +SNAFU_DIGITS = { + "2": 2, + "1": 1, + "0": 0, + "-": -1, + "=": -2, +} + +REGULAR_DIGITS = {SNAFU_DIGITS[k]: k for k in SNAFU_DIGITS} + + +def parse(instr: str) -> List[str]: + return instr.strip().splitlines() + + +def decode_snafu(snafu: str) -> int: + acc = 0 + for i, char in enumerate(reversed(snafu)): + acc += SNAFU_DIGITS[char] * pow(5, i) + return acc + + +def encode_snafu(n: int) -> str: + acc = [] + while n != 0: + rem = n % 5 + acc.append(rem) + n = n // 5 + + for i in range(len(acc)): + if acc[i] > 2: + acc[i] = acc[i] - 5 + if i + 1 < len(acc): + acc[i + 1] = acc[i + 1] + 1 + else: + acc.append(1) + + return "".join(map(lambda x: REGULAR_DIGITS[x], reversed(acc))) + + +class Challenge(BaseChallenge): + @staticmethod + def one(instr: str) -> str: + return encode_snafu(sum(map(decode_snafu, parse(instr)))) + + @staticmethod + def two(instr: str) -> str: + return "Merry Christmas!" diff --git a/challenges/2022/README.md b/challenges/2022/README.md index acddd6f..89e1f06 100644 --- a/challenges/2022/README.md +++ b/challenges/2022/README.md @@ -39,4 +39,5 @@ The red dotted line denotes 15 seconds. | 21 - Monkey Math | ★ ★ | [Python](21-monkeyMath/py/__init__.py) | Trees of math with a fairly satisfying solution :D | | 22 - Monkey Map | ★ ★ | [Python](22-monkeyMap/py/__init__.py) | Please never ever make me trace a path around a 3D shape in two dimensions ever again | | 23 - Unstable Diffusion | ★ ★ | [Python](23-unstableDiffusion/py/__init__.py) | I <3 Cellular automata | -| 24 - Blizzard Basin | ★ ★ | [Python](24-blizzardBasin/py/__init__.py) | BFS of a rapidly changing grid of things | \ No newline at end of file +| 24 - Blizzard Basin | ★ ★ | [Python](24-blizzardBasin/py/__init__.py) | BFS of a rapidly changing grid of things | +| 25 - Full of Hot Air | ★ ★ | [Python](25-fullOfHotAir/py/__init__.py) | Converting into different bases, but weird | \ No newline at end of file diff --git a/challenges/2022/running-times.png b/challenges/2022/running-times.png index 754af4a..22672b1 100644 Binary files a/challenges/2022/running-times.png and b/challenges/2022/running-times.png differ