2022-25 - Merry Christmas!

Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
akp 2022-12-25 11:07:54 +00:00
parent 15953f4425
commit c1f985ddb0
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
6 changed files with 96 additions and 1 deletions

View file

@ -0,0 +1 @@
# [Day 25: Full Of Hot Air](https://adventofcode.com/2022/day/25)

View file

@ -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
}

View file

@ -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"}
]
}
}

View file

@ -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!"

View file

@ -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 | | 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 | | 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 | | 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 | | 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 |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Before After
Before After