2022-25 - Merry Christmas!
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
15953f4425
commit
c1f985ddb0
6 changed files with 96 additions and 1 deletions
1
challenges/2022/25-fullOfHotAir/README.md
Normal file
1
challenges/2022/25-fullOfHotAir/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# [Day 25: Full Of Hot Air](https://adventofcode.com/2022/day/25)
|
15
challenges/2022/25-fullOfHotAir/benchmark.json
Normal file
15
challenges/2022/25-fullOfHotAir/benchmark.json
Normal 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
|
||||
}
|
26
challenges/2022/25-fullOfHotAir/info.json
Normal file
26
challenges/2022/25-fullOfHotAir/info.json
Normal 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"}
|
||||
]
|
||||
}
|
||||
}
|
52
challenges/2022/25-fullOfHotAir/py/__init__.py
Normal file
52
challenges/2022/25-fullOfHotAir/py/__init__.py
Normal 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!"
|
|
@ -40,3 +40,4 @@ The red dotted line denotes 15 seconds.
|
|||
| 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 |
|
||||
| 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 |
Loading…
Add table
Add a link
Reference in a new issue