Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
akp 2022-12-20 17:49:46 +00:00
parent 8e9a71ada2
commit 320b990b05
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
6 changed files with 111 additions and 1 deletions

View file

@ -0,0 +1 @@
# [Day 20: Grove Positioning System](https://adventofcode.com/2022/day/20)

View file

@ -0,0 +1,15 @@
{
"day": 20,
"dir": "challenges/2022/20-grovePositioningSystem",
"implementations": {
"Python": {
"part.1.avg": 0.6482098897298177,
"part.1.max": 0.6944289207458496,
"part.1.min": 0.5697693824768066,
"part.2.avg": 12.018423795700073,
"part.2.max": 12.624868154525757,
"part.2.min": 11.30324387550354
}
},
"numRuns": 3
}

View file

@ -0,0 +1,17 @@
{
"inputFile": "input.txt",
"testCases": {
"one": [
{
"input": "1\n2\n-3\n3\n-2\n0\n4\n",
"expected": "3"
}
],
"two": [
{
"input": "1\n2\n-3\n3\n-2\n0\n4\n",
"expected": "1623178306"
}
]
}
}

View file

@ -0,0 +1,76 @@
from typing import *
from aocpy import BaseChallenge
from dataclasses import dataclass
@dataclass
class PositionedInteger:
value: int
position: int
def parse(instr: str) -> List[PositionedInteger]:
return [
PositionedInteger(int(x), i) for i, x in enumerate(instr.strip().splitlines())
]
def calc_new_ordinate(o: int, max_ord: int) -> int:
if o == 0:
o = max_ord
else:
o = o % max_ord
return o
def mix(inp: List[PositionedInteger]):
max_ord = len(inp) - 1
for i in range(len(inp)):
pos = 0
n: Optional[PositionedInteger] = None
while True:
if inp[pos].position == i:
n = inp[pos]
break
pos += 1
if n.value == 0:
continue
new_pos = calc_new_ordinate(pos + n.value, max_ord)
_ = inp.pop(pos)
inp.insert(new_pos, n)
def calc_answer(inp: List[PositionedInteger]) -> int:
sigma = 0
for i in range(len(inp)):
if inp[i].value == 0:
break
for n in [i + 1000, i + 2000, i + 3000]:
sigma += inp[n % len(inp)].value
return sigma
class Challenge(BaseChallenge):
@staticmethod
def one(instr: str) -> int:
inp = parse(instr)
mix(inp)
return calc_answer(inp)
@staticmethod
def two(instr: str) -> int:
inp = parse(instr)
for n in inp:
n.value *= 811589153
for _ in range(10):
mix(inp)
return calc_answer(inp)

View file

@ -34,4 +34,5 @@ The red dotted line denotes 15 seconds.
| 16 - Proboscidea Volcanium | ★ ★ | [Python](16-proboscideaVolcanium/py/__init__.py) | Nasty combinatorics |
| 17 - Pyroclastic Flow | ★ ★ | [Python](17-pyroclasticFlow/py/__init__.py) | Detecting cycles in a large amount of knock-off Tetris. |
| 18 - Boiling Boulders | ★ ★ | [Python](18-boilingBoulders/py/__init__.py) | Finding the surface area of a shape specified by a list of unit cubes. |
| 19 - Not Enough Minerals | ★ ★ | [Python](19-notEnoughMinerals/py/__init__.py) | Finding the most effective sequence of operations to complete a specific task. |
| 19 - Not Enough Minerals | ★ ★ | [Python](19-notEnoughMinerals/py/__init__.py) | Finding the most effective sequence of operations to complete a specific task. |
| 20 - Grove Positioning System | ★ ★ | [Python](20-grovePositioningSystem/py/__init__.py) | My hell is lined with circular sequences. |

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Before After
Before After