Compare commits
129 commits
30c1608c7c
...
da90cd8472
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | da90cd8472 | ||
Bruno BELANYI | 8e0ec0b962 | ||
Bruno BELANYI | cb0348d87c | ||
Bruno BELANYI | 55af2695f5 | ||
Bruno BELANYI | a7d74dcae6 | ||
Bruno BELANYI | 17f62f1052 | ||
Bruno BELANYI | afec744618 | ||
Bruno BELANYI | a21b197240 | ||
Bruno BELANYI | 96db7c6d02 | ||
Bruno BELANYI | caf14a71b6 | ||
Bruno BELANYI | 2418405955 | ||
Bruno BELANYI | 20ee194643 | ||
Bruno BELANYI | d4c9aa4c5e | ||
Bruno BELANYI | 820794cc80 | ||
Bruno BELANYI | 19b48862ce | ||
Bruno BELANYI | dddd70813a | ||
Bruno BELANYI | 84ac5bbb71 | ||
Bruno BELANYI | 7851f1158f | ||
Bruno BELANYI | be4a02ce44 | ||
Bruno BELANYI | e8a8d36ac9 | ||
Bruno BELANYI | 0be38033f4 | ||
Bruno BELANYI | ed18966413 | ||
Bruno BELANYI | 20784cb2ca | ||
Bruno BELANYI | 150bebc492 | ||
Bruno BELANYI | cd747e69e6 | ||
Bruno BELANYI | 96980ecb19 | ||
Bruno BELANYI | df664d9fca | ||
Bruno BELANYI | ab15ce121f | ||
Bruno BELANYI | 22e59128fb | ||
Bruno BELANYI | aee3b2f333 | ||
Bruno BELANYI | 1d1936f5e7 | ||
Bruno BELANYI | 2d4a21dc9a | ||
Bruno BELANYI | 34d72e9729 | ||
Bruno BELANYI | 932e5a40f7 | ||
Bruno BELANYI | 8c2a2ed438 | ||
Bruno BELANYI | 6dcd2bcf69 | ||
Bruno BELANYI | ef6e30cb6c | ||
Bruno BELANYI | d36fb3473d | ||
Bruno BELANYI | 80a4297e93 | ||
Bruno BELANYI | a529394eb4 | ||
Bruno BELANYI | 6501cb9cf5 | ||
Bruno BELANYI | 7e162a4e7a | ||
Bruno BELANYI | 1831dc4b8f | ||
Bruno BELANYI | ef2957970a | ||
Bruno BELANYI | 832159237f | ||
Bruno BELANYI | c1aaae7946 | ||
Bruno BELANYI | 2de3573cfd | ||
Bruno BELANYI | a1c2123291 | ||
Bruno BELANYI | f97a35248d | ||
Bruno BELANYI | 78f159598d | ||
Bruno BELANYI | bf2c65036f | ||
Bruno BELANYI | bf81ef41f8 | ||
Bruno BELANYI | 617a003a51 | ||
Bruno BELANYI | 08ce15d6c0 | ||
Bruno BELANYI | 52fba3b92f | ||
Bruno BELANYI | 05670f39c0 | ||
Bruno BELANYI | 0cd15bb346 | ||
Bruno BELANYI | 060ba38597 | ||
Bruno BELANYI | 4b71dee7c4 | ||
Bruno BELANYI | e9cab0c0bf | ||
Bruno BELANYI | acc175e4a6 | ||
Bruno BELANYI | c318b9970c | ||
Bruno BELANYI | d3abeae02a | ||
Bruno BELANYI | 5fb874f00b | ||
Bruno BELANYI | 9bc536f6ec | ||
Bruno BELANYI | f67de590ce | ||
Bruno BELANYI | f3456d2ca9 | ||
Bruno BELANYI | e127a77443 | ||
Bruno BELANYI | 5da7942d78 | ||
Bruno BELANYI | 074226098f | ||
Bruno BELANYI | d7e74e60f1 | ||
Bruno BELANYI | 5a39d2babe | ||
Bruno BELANYI | 17138bfc8f | ||
Bruno BELANYI | 0ed6d5eb43 | ||
Bruno BELANYI | d3a1040f60 | ||
Bruno BELANYI | acc9ef472c | ||
Bruno BELANYI | 146b3becf9 | ||
Bruno BELANYI | 7d268d0d4f | ||
Bruno BELANYI | a226768e08 | ||
Bruno BELANYI | 1c64a8f18b | ||
Bruno BELANYI | 79ad4a26b5 | ||
Bruno BELANYI | 032223781d | ||
Bruno BELANYI | 233caf8b11 | ||
Bruno BELANYI | 18d95d8665 | ||
Bruno BELANYI | 390eb447cc | ||
Bruno BELANYI | b25f2908d5 | ||
Bruno BELANYI | 4cf562410a | ||
Bruno BELANYI | 26e3bd0006 | ||
Bruno BELANYI | 005501546f | ||
Bruno BELANYI | dd8a4569d2 | ||
Bruno BELANYI | 4121ef0880 | ||
Bruno BELANYI | 9c6b5bf887 | ||
Bruno BELANYI | 93dfa3ab8c | ||
Bruno BELANYI | 4125c20fb7 | ||
Bruno BELANYI | 878b0a10d3 | ||
Bruno BELANYI | e812fd424a | ||
Bruno BELANYI | d868e9f5a9 | ||
Bruno BELANYI | 8733c82b46 | ||
Bruno BELANYI | 533fce5d69 | ||
Bruno BELANYI | 5929fd5f07 | ||
Bruno BELANYI | 1014d1546b | ||
Bruno BELANYI | 5f9288aa5f | ||
Bruno BELANYI | 0d175c824f | ||
Bruno BELANYI | 776577c118 | ||
Bruno BELANYI | a304a38046 | ||
Bruno BELANYI | 17a4286307 | ||
Bruno BELANYI | 6d30ed5992 | ||
Bruno BELANYI | 30a7a7da33 | ||
Bruno BELANYI | 82f57ddea5 | ||
Bruno BELANYI | dad9912dd2 | ||
Bruno BELANYI | 07223f9d30 | ||
Bruno BELANYI | 254093a24d | ||
Bruno BELANYI | ffe7fa42d5 | ||
Bruno BELANYI | 035b8b5a0f | ||
Bruno BELANYI | 704cf451cb | ||
Bruno BELANYI | c1c5abc0a4 | ||
Bruno BELANYI | 78954b23e5 | ||
Bruno BELANYI | e4699300b0 | ||
Bruno BELANYI | 3fc73336a4 | ||
Bruno BELANYI | ac39fe2abb | ||
Bruno BELANYI | 1b8f5bc5e0 | ||
Bruno BELANYI | ed9ba2c14a | ||
Bruno BELANYI | d3445b2ef1 | ||
Bruno BELANYI | 2b15ae7552 | ||
Bruno BELANYI | 213575d822 | ||
Bruno BELANYI | 030f45af6c | ||
Bruno BELANYI | 3a19846717 | ||
Bruno BELANYI | 94dffe573c | ||
Bruno BELANYI | 20d47b0048 |
7
.envrc
Normal file
7
.envrc
Normal file
|
@ -0,0 +1,7 @@
|
|||
use_flake() {
|
||||
watch_file flake.nix
|
||||
watch_file flake.lock
|
||||
eval "$(nix print-dev-env)"
|
||||
}
|
||||
|
||||
use flake
|
213
2019/d13/ex1/ex1.py
Executable file
213
2019/d13/ex1/ex1.py
Executable file
|
@ -0,0 +1,213 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from enum import IntEnum
|
||||
from typing import Dict, Iterable, List, NamedTuple, Tuple, TypeVar
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self): # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
game = Computer(memory)
|
||||
game.run_no_output_interrupt()
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
def grouped(l: Iterable[T], n: int) -> Iterable[Tuple[T, ...]]:
|
||||
return zip(*[iter(l)] * n)
|
||||
|
||||
print(sum(1 for __, __, tile in grouped(game.output_list, 3) if tile == 2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
249
2019/d13/ex2/ex2.py
Executable file
249
2019/d13/ex2/ex2.py
Executable file
|
@ -0,0 +1,249 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from enum import IntEnum
|
||||
from typing import Dict, Iterable, List, NamedTuple, Tuple, TypeVar
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self): # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
class Tile(IntEnum):
|
||||
EMPTY = 0
|
||||
WALL = 1
|
||||
BLOCK = 2
|
||||
PADDLE = 3
|
||||
BALL = 4
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
memory[0] = 2 # Play for free
|
||||
game = Computer(memory)
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
def grouped(l: Iterable[T], n: int) -> Iterable[Tuple[T, ...]]:
|
||||
return zip(*[iter(l)] * n)
|
||||
|
||||
paddle_pos = None
|
||||
ball_pos = None
|
||||
score = None
|
||||
output_num = 0
|
||||
while not game.is_halted:
|
||||
try:
|
||||
game.run()
|
||||
except OutputInterrupt:
|
||||
output_num += 1
|
||||
if output_num < 3: # Not processable yet
|
||||
continue
|
||||
x, y = game.output_list[0:2]
|
||||
if x == -1 and y == 0: # Score display
|
||||
score = game.output_list[2]
|
||||
else:
|
||||
tile_type = Tile(game.output_list[2])
|
||||
if tile_type == Tile.PADDLE:
|
||||
paddle_pos = x
|
||||
elif tile_type == Tile.BALL:
|
||||
ball_pos = x
|
||||
game.output_list.clear() # Remove processed tiles
|
||||
output_num = 0 # Reset count for next output
|
||||
except InputInterrupt:
|
||||
assert paddle_pos is not None and ball_pos is not None # Sanity check
|
||||
offset = ball_pos - paddle_pos
|
||||
game.input_list.append(0 if offset == 0 else offset // abs(offset))
|
||||
|
||||
assert score is not None # Sanity check
|
||||
print(score)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d13/ex2/input
Normal file
1
2019/d13/ex2/input
Normal file
File diff suppressed because one or more lines are too long
89
2019/d14/ex1/ex1.py
Executable file
89
2019/d14/ex1/ex1.py
Executable file
|
@ -0,0 +1,89 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from math import ceil
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
@dataclass
|
||||
class Ingredient:
|
||||
name: str
|
||||
quantity: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReactionEquation:
|
||||
quantity: int
|
||||
inputs: List[Ingredient]
|
||||
|
||||
|
||||
Reactions = Dict[str, ReactionEquation]
|
||||
|
||||
|
||||
def solve_for(n: int, reactions: Reactions) -> int:
|
||||
ore_needed = 0
|
||||
wanted = [("FUEL", n)]
|
||||
excess: Dict[str, int] = {}
|
||||
|
||||
def provide_ingredient(name: str, wanted_quantity: int) -> None:
|
||||
nonlocal ore_needed
|
||||
nonlocal excess
|
||||
nonlocal wanted
|
||||
|
||||
if name == "ORE":
|
||||
ore_needed += wanted_quantity # There's no recipy for this one
|
||||
return
|
||||
|
||||
if name in excess:
|
||||
# Take from excess
|
||||
if excess[name] > wanted_quantity:
|
||||
excess[name] -= wanted_quantity
|
||||
return # Nothing left to do
|
||||
wanted_quantity -= excess[name]
|
||||
del excess[name] # Took everything
|
||||
|
||||
if wanted_quantity == 0: # In case we provided just enough by excess
|
||||
return
|
||||
|
||||
equation = reactions[name]
|
||||
reaction_num = ceil(wanted_quantity / equation.quantity)
|
||||
|
||||
for ingredient in equation.inputs:
|
||||
needed_quantity = ingredient.quantity * reaction_num
|
||||
provide_ingredient(ingredient.name, needed_quantity)
|
||||
|
||||
produced_quantity = equation.quantity * reaction_num
|
||||
excess_quantity = produced_quantity - wanted_quantity
|
||||
if excess_quantity > 0:
|
||||
if name in excess:
|
||||
excess[name] += excess_quantity
|
||||
else:
|
||||
excess[name] = excess_quantity
|
||||
|
||||
while len(wanted) != 0:
|
||||
provide_ingredient(*(wanted.pop()))
|
||||
|
||||
return ore_needed
|
||||
|
||||
|
||||
def main() -> None:
|
||||
reactions: Reactions = {}
|
||||
|
||||
def parse_react(l: str) -> None:
|
||||
def parse_ingredient(i: str) -> Ingredient:
|
||||
quantity, name = i.strip().split(" ")
|
||||
return Ingredient(name, int(quantity))
|
||||
|
||||
input_list, output_str = l.split("=>")
|
||||
inputs = [i for i in map(parse_ingredient, input_list.split(", "))]
|
||||
output = parse_ingredient(output_str)
|
||||
reactions[output.name] = ReactionEquation(output.quantity, inputs)
|
||||
|
||||
for line in sys.stdin.readlines():
|
||||
parse_react(line)
|
||||
print(solve_for(1, reactions))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
59
2019/d14/ex1/input
Normal file
59
2019/d14/ex1/input
Normal file
|
@ -0,0 +1,59 @@
|
|||
10 LSZLT, 29 XQJK => 4 BMRQJ
|
||||
22 HCKS => 1 GQKCZ
|
||||
1 HCKS, 8 WZWRV, 18 HVZR => 7 BGFR
|
||||
1 LSZLT, 1 WRKJ, 3 LJFP, 3 RNLPB, 1 NZGK, 3 LDSV, 5 RJDN, 8 HGFGC => 3 QZTXD
|
||||
1 BRSGQ, 1 XGLF, 1 ZHSK, 20 LSZLT, 16 WFCPT, 3 KTWV, 1 QRJC => 4 XPKX
|
||||
1 DCLR, 6 RNLPB => 5 HCKS
|
||||
1 HFHFV => 3 SHLMF
|
||||
2 LTMZQ, 21 FGCXN => 6 QKFKV
|
||||
3 BGFR => 7 WRKJ
|
||||
3 KHSB => 2 XQJL
|
||||
3 SHLMF => 2 LPLG
|
||||
12 SVHWT, 20 BXPSZ => 9 NBMF
|
||||
2 FGCXN, 32 DCSVN => 8 TBDWZ
|
||||
1 KHSB, 3 HGFGC => 6 WZWRV
|
||||
27 WFCPT, 4 KTWV, 14 BRSGQ, 1 MFNK, 1 WRKJ, 2 NZGK, 24 FBFLK => 5 TRLCK
|
||||
2 SVHWT => 3 QRJC
|
||||
1 MNVR, 1 FKBMW => 2 FGCXN
|
||||
4 GJXW => 9 JXFS
|
||||
3 XQJK => 5 WNJM
|
||||
1 WZVWZ, 1 XQJL => 9 SHKJV
|
||||
2 DCSVN => 4 HDVC
|
||||
2 GJXW => 2 RNLPB
|
||||
1 QKFKV, 1 PBRWB => 5 WTZQ
|
||||
14 QKFKV => 6 RDFTD
|
||||
166 ORE => 1 QDSXV
|
||||
2 DCSVN => 5 BXPSZ
|
||||
113 ORE => 6 LTMZQ
|
||||
13 MNVR => 7 RJDN
|
||||
2 NZGK, 9 XQJK, 18 WRKJ => 9 KTWV
|
||||
1 NZGK => 8 XQJK
|
||||
6 RZCGN, 6 HDVC, 1 DLKR => 9 DSLXW
|
||||
18 HVZR => 8 LJFP
|
||||
7 XQJL => 1 NPDS
|
||||
15 DLKR, 1 DSLXW, 26 MJFVP => 3 FBFLK
|
||||
125 ORE => 9 MNVR
|
||||
3 RJDN => 4 HFHFV
|
||||
1 TBDWZ, 1 DCLR => 2 HVZR
|
||||
2 SHKJV => 5 GJXW
|
||||
7 LTMZQ, 1 QDSXV, 1 FKBMW => 3 DCSVN
|
||||
9 LPLG, 11 JXFS => 3 BRSGQ
|
||||
5 JXFS, 1 ZHSK, 25 XGLF => 4 MFNK
|
||||
5 PBRWB => 2 SVHWT
|
||||
15 SHKJV => 5 XGLF
|
||||
1 XQJL, 2 NPDS => 4 DLKR
|
||||
39 JXFS => 5 KSHF
|
||||
6 GJXW, 1 FBFLK => 7 HGFGC
|
||||
3 JXFS => 1 LSZLT
|
||||
3 NBMF, 1 BMRQJ => 2 LDSV
|
||||
1 JXFS, 25 GJXW, 10 HGFGC => 4 NZGK
|
||||
8 QZTXD, 26 KSHF, 60 WNJM, 6 GJXW, 9 TRLCK, 20 XPKX, 21 FGCXN, 57 GQKCZ, 6 WRKJ => 1 FUEL
|
||||
4 SVHWT, 1 RZCGN => 3 ZHSK
|
||||
1 BXPSZ => 7 DCLR
|
||||
8 RDFTD, 1 SHKJV, 1 HFHFV => 6 MJFVP
|
||||
1 LTMZQ => 9 KHSB
|
||||
5 WTZQ, 4 HGFGC, 4 HCKS => 9 WFCPT
|
||||
184 ORE => 4 FKBMW
|
||||
4 XQJL => 3 WZVWZ
|
||||
12 QDSXV => 9 RZCGN
|
||||
1 FBFLK, 7 HVZR => 9 PBRWB
|
106
2019/d14/ex2/ex2.py
Executable file
106
2019/d14/ex2/ex2.py
Executable file
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from math import ceil
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
@dataclass
|
||||
class Ingredient:
|
||||
name: str
|
||||
quantity: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReactionEquation:
|
||||
quantity: int
|
||||
inputs: List[Ingredient]
|
||||
|
||||
|
||||
Reactions = Dict[str, ReactionEquation]
|
||||
|
||||
|
||||
def solve_for(n: int, reactions: Reactions) -> int:
|
||||
ore_needed = 0
|
||||
wanted = [("FUEL", n)]
|
||||
excess: Dict[str, int] = {}
|
||||
|
||||
def provide_ingredient(name: str, wanted_quantity: int) -> None:
|
||||
nonlocal ore_needed
|
||||
nonlocal excess
|
||||
nonlocal wanted
|
||||
|
||||
if name == "ORE":
|
||||
ore_needed += wanted_quantity # There's no recipy for this one
|
||||
return
|
||||
|
||||
if name in excess:
|
||||
# Take from excess
|
||||
if excess[name] > wanted_quantity:
|
||||
excess[name] -= wanted_quantity
|
||||
return # Nothing left to do
|
||||
wanted_quantity -= excess[name]
|
||||
del excess[name] # Took everything
|
||||
|
||||
if wanted_quantity == 0: # In case we provided just enough by excess
|
||||
return
|
||||
|
||||
equation = reactions[name]
|
||||
reaction_num = ceil(wanted_quantity / equation.quantity)
|
||||
|
||||
for ingredient in equation.inputs:
|
||||
needed_quantity = ingredient.quantity * reaction_num
|
||||
provide_ingredient(ingredient.name, needed_quantity)
|
||||
|
||||
produced_quantity = equation.quantity * reaction_num
|
||||
excess_quantity = produced_quantity - wanted_quantity
|
||||
if excess_quantity > 0:
|
||||
if name in excess:
|
||||
excess[name] += excess_quantity
|
||||
else:
|
||||
excess[name] = excess_quantity
|
||||
|
||||
while len(wanted) != 0:
|
||||
provide_ingredient(*(wanted.pop()))
|
||||
|
||||
return ore_needed
|
||||
|
||||
|
||||
def main() -> None:
|
||||
reactions: Reactions = {}
|
||||
|
||||
def parse_react(l: str) -> None:
|
||||
def parse_ingredient(i: str) -> Ingredient:
|
||||
quantity, name = i.strip().split(" ")
|
||||
return Ingredient(name, int(quantity))
|
||||
|
||||
input_list, output_str = l.split("=>")
|
||||
inputs = [i for i in map(parse_ingredient, input_list.split(", "))]
|
||||
output = parse_ingredient(output_str)
|
||||
reactions[output.name] = ReactionEquation(output.quantity, inputs)
|
||||
|
||||
for line in sys.stdin.readlines():
|
||||
parse_react(line)
|
||||
|
||||
for_one = solve_for(1, reactions)
|
||||
target = 1000000000000
|
||||
# Educated guesses about minimum and maximum fuel needed to use 'target' ORE
|
||||
min_fuel_needed = target // for_one
|
||||
max_fuel_needed = 2 * min_fuel_needed
|
||||
while min_fuel_needed < max_fuel_needed:
|
||||
# We already know that minimum value is valid, offset it by one for the search
|
||||
mid = ceil((min_fuel_needed + max_fuel_needed) / 2)
|
||||
mid_res = solve_for(mid, reactions)
|
||||
if mid_res > target:
|
||||
# Exclude the maximum that was already searched
|
||||
max_fuel_needed = mid - 1
|
||||
else:
|
||||
# Keep the valid minimum value
|
||||
min_fuel_needed = mid
|
||||
|
||||
print(max_fuel_needed)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
59
2019/d14/ex2/input
Normal file
59
2019/d14/ex2/input
Normal file
|
@ -0,0 +1,59 @@
|
|||
10 LSZLT, 29 XQJK => 4 BMRQJ
|
||||
22 HCKS => 1 GQKCZ
|
||||
1 HCKS, 8 WZWRV, 18 HVZR => 7 BGFR
|
||||
1 LSZLT, 1 WRKJ, 3 LJFP, 3 RNLPB, 1 NZGK, 3 LDSV, 5 RJDN, 8 HGFGC => 3 QZTXD
|
||||
1 BRSGQ, 1 XGLF, 1 ZHSK, 20 LSZLT, 16 WFCPT, 3 KTWV, 1 QRJC => 4 XPKX
|
||||
1 DCLR, 6 RNLPB => 5 HCKS
|
||||
1 HFHFV => 3 SHLMF
|
||||
2 LTMZQ, 21 FGCXN => 6 QKFKV
|
||||
3 BGFR => 7 WRKJ
|
||||
3 KHSB => 2 XQJL
|
||||
3 SHLMF => 2 LPLG
|
||||
12 SVHWT, 20 BXPSZ => 9 NBMF
|
||||
2 FGCXN, 32 DCSVN => 8 TBDWZ
|
||||
1 KHSB, 3 HGFGC => 6 WZWRV
|
||||
27 WFCPT, 4 KTWV, 14 BRSGQ, 1 MFNK, 1 WRKJ, 2 NZGK, 24 FBFLK => 5 TRLCK
|
||||
2 SVHWT => 3 QRJC
|
||||
1 MNVR, 1 FKBMW => 2 FGCXN
|
||||
4 GJXW => 9 JXFS
|
||||
3 XQJK => 5 WNJM
|
||||
1 WZVWZ, 1 XQJL => 9 SHKJV
|
||||
2 DCSVN => 4 HDVC
|
||||
2 GJXW => 2 RNLPB
|
||||
1 QKFKV, 1 PBRWB => 5 WTZQ
|
||||
14 QKFKV => 6 RDFTD
|
||||
166 ORE => 1 QDSXV
|
||||
2 DCSVN => 5 BXPSZ
|
||||
113 ORE => 6 LTMZQ
|
||||
13 MNVR => 7 RJDN
|
||||
2 NZGK, 9 XQJK, 18 WRKJ => 9 KTWV
|
||||
1 NZGK => 8 XQJK
|
||||
6 RZCGN, 6 HDVC, 1 DLKR => 9 DSLXW
|
||||
18 HVZR => 8 LJFP
|
||||
7 XQJL => 1 NPDS
|
||||
15 DLKR, 1 DSLXW, 26 MJFVP => 3 FBFLK
|
||||
125 ORE => 9 MNVR
|
||||
3 RJDN => 4 HFHFV
|
||||
1 TBDWZ, 1 DCLR => 2 HVZR
|
||||
2 SHKJV => 5 GJXW
|
||||
7 LTMZQ, 1 QDSXV, 1 FKBMW => 3 DCSVN
|
||||
9 LPLG, 11 JXFS => 3 BRSGQ
|
||||
5 JXFS, 1 ZHSK, 25 XGLF => 4 MFNK
|
||||
5 PBRWB => 2 SVHWT
|
||||
15 SHKJV => 5 XGLF
|
||||
1 XQJL, 2 NPDS => 4 DLKR
|
||||
39 JXFS => 5 KSHF
|
||||
6 GJXW, 1 FBFLK => 7 HGFGC
|
||||
3 JXFS => 1 LSZLT
|
||||
3 NBMF, 1 BMRQJ => 2 LDSV
|
||||
1 JXFS, 25 GJXW, 10 HGFGC => 4 NZGK
|
||||
8 QZTXD, 26 KSHF, 60 WNJM, 6 GJXW, 9 TRLCK, 20 XPKX, 21 FGCXN, 57 GQKCZ, 6 WRKJ => 1 FUEL
|
||||
4 SVHWT, 1 RZCGN => 3 ZHSK
|
||||
1 BXPSZ => 7 DCLR
|
||||
8 RDFTD, 1 SHKJV, 1 HFHFV => 6 MJFVP
|
||||
1 LTMZQ => 9 KHSB
|
||||
5 WTZQ, 4 HGFGC, 4 HCKS => 9 WFCPT
|
||||
184 ORE => 4 FKBMW
|
||||
4 XQJL => 3 WZVWZ
|
||||
12 QDSXV => 9 RZCGN
|
||||
1 FBFLK, 7 HVZR => 9 PBRWB
|
315
2019/d15/ex1/ex1.py
Executable file
315
2019/d15/ex1/ex1.py
Executable file
|
@ -0,0 +1,315 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import heapq
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum, IntEnum, auto
|
||||
from typing import List, NamedTuple, Optional, Set
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self): # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
class Movement(IntEnum):
|
||||
NORTH = 1
|
||||
SOUTH = 2
|
||||
WEST = 3
|
||||
EAST = 4
|
||||
|
||||
|
||||
class StatusCode(IntEnum):
|
||||
BLOCKED = 0
|
||||
SUCCESS = 1
|
||||
ON_TANK = 2
|
||||
|
||||
|
||||
class BlockType(Enum):
|
||||
WALL = auto()
|
||||
HALLWAY = auto()
|
||||
OXYGEN_TANK = auto()
|
||||
|
||||
|
||||
class Coordinate(NamedTuple):
|
||||
x: int
|
||||
y: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class GraphNode:
|
||||
memory_state: Optional[List[int]] # Only walls have no need for the memory state
|
||||
block_type: BlockType
|
||||
parent: Optional[Coordinate] # Only the root of the exploration has no parent
|
||||
|
||||
|
||||
def coord_plus_dir(c: Coordinate, d: Movement) -> Coordinate:
|
||||
offset = {
|
||||
Movement.NORTH: Coordinate(0, 1),
|
||||
Movement.SOUTH: Coordinate(0, -1),
|
||||
Movement.WEST: Coordinate(-1, 0),
|
||||
Movement.EAST: Coordinate(1, 0),
|
||||
}
|
||||
return Coordinate(*(a + b for (a, b) in zip(c, offset[d])))
|
||||
|
||||
|
||||
def move_to_opposite(d: Movement) -> Movement:
|
||||
if d == Movement.NORTH:
|
||||
return Movement.SOUTH
|
||||
elif d == Movement.SOUTH:
|
||||
return Movement.NORTH
|
||||
elif d == Movement.WEST:
|
||||
return Movement.EAST
|
||||
else:
|
||||
return Movement.WEST
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
droid = Computer(memory)
|
||||
block_map = {Coordinate(0, 0): BlockType.HALLWAY}
|
||||
|
||||
def dfs(p: Coordinate, direction: Movement) -> None:
|
||||
end_coord = coord_plus_dir(p, direction)
|
||||
if end_coord in block_map:
|
||||
return # Nothing to do
|
||||
|
||||
droid.input_list.append(int(direction))
|
||||
try:
|
||||
droid.run()
|
||||
except OutputInterrupt:
|
||||
status = StatusCode(droid.output_list.pop(0))
|
||||
if status == StatusCode.BLOCKED:
|
||||
block_map[end_coord] = BlockType.WALL
|
||||
return # Don't need to backtrack
|
||||
block_map[end_coord] = (
|
||||
BlockType.OXYGEN_TANK
|
||||
if status == StatusCode.ON_TANK
|
||||
else BlockType.HALLWAY
|
||||
)
|
||||
for d in Movement:
|
||||
dfs(end_coord, d)
|
||||
droid.input_list.append(int(move_to_opposite(direction)))
|
||||
try:
|
||||
droid.run()
|
||||
except OutputInterrupt:
|
||||
droid.output_list.pop(0)
|
||||
|
||||
for direction in Movement:
|
||||
dfs(Coordinate(0, 0), direction)
|
||||
assert len(droid.input_list) == 0 and len(droid.output_list) == 0 # Sanity check
|
||||
|
||||
block_map = {p: t for p, t in block_map.items() if t != BlockType.WALL}
|
||||
oxygen_gen = (
|
||||
pos for pos, block in block_map.items() if block == BlockType.OXYGEN_TANK
|
||||
)
|
||||
oxygen_pos = next(oxygen_gen)
|
||||
assert next(oxygen_gen, None) is None # Sanity check
|
||||
|
||||
seen: Set[Coordinate] = set()
|
||||
to_visit = [(0, oxygen_pos)]
|
||||
|
||||
def find_shortest() -> int:
|
||||
while True:
|
||||
dist, pos = heapq.heappop(to_visit)
|
||||
if pos == Coordinate(0, 0):
|
||||
return dist
|
||||
if pos in seen:
|
||||
continue
|
||||
if pos not in block_map:
|
||||
continue
|
||||
seen.add(pos)
|
||||
for d in Movement:
|
||||
new_pos = coord_plus_dir(pos, d)
|
||||
heapq.heappush(to_visit, (dist + 1, new_pos))
|
||||
|
||||
print(find_shortest())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d15/ex1/input
Normal file
1
2019/d15/ex1/input
Normal file
|
@ -0,0 +1 @@
|
|||
3,1033,1008,1033,1,1032,1005,1032,31,1008,1033,2,1032,1005,1032,58,1008,1033,3,1032,1005,1032,81,1008,1033,4,1032,1005,1032,104,99,101,0,1034,1039,1001,1036,0,1041,1001,1035,-1,1040,1008,1038,0,1043,102,-1,1043,1032,1,1037,1032,1042,1105,1,124,1002,1034,1,1039,1001,1036,0,1041,1001,1035,1,1040,1008,1038,0,1043,1,1037,1038,1042,1106,0,124,1001,1034,-1,1039,1008,1036,0,1041,101,0,1035,1040,1001,1038,0,1043,1002,1037,1,1042,1105,1,124,1001,1034,1,1039,1008,1036,0,1041,1002,1035,1,1040,101,0,1038,1043,1001,1037,0,1042,1006,1039,217,1006,1040,217,1008,1039,40,1032,1005,1032,217,1008,1040,40,1032,1005,1032,217,1008,1039,33,1032,1006,1032,165,1008,1040,33,1032,1006,1032,165,1101,2,0,1044,1106,0,224,2,1041,1043,1032,1006,1032,179,1101,0,1,1044,1106,0,224,1,1041,1043,1032,1006,1032,217,1,1042,1043,1032,1001,1032,-1,1032,1002,1032,39,1032,1,1032,1039,1032,101,-1,1032,1032,101,252,1032,211,1007,0,68,1044,1106,0,224,1101,0,0,1044,1105,1,224,1006,1044,247,1002,1039,1,1034,102,1,1040,1035,1001,1041,0,1036,1002,1043,1,1038,1001,1042,0,1037,4,1044,1105,1,0,67,55,37,80,63,12,30,78,95,7,20,63,83,54,86,58,97,11,84,24,11,77,42,78,22,54,89,52,44,28,93,30,81,60,58,78,87,60,54,59,78,96,17,82,74,85,66,41,89,96,54,40,82,17,22,89,65,96,71,55,81,34,90,11,85,44,58,83,79,93,30,76,62,80,16,73,20,43,40,73,69,39,39,15,93,39,99,8,74,33,97,84,24,50,91,5,71,34,81,76,22,98,50,93,80,36,76,16,76,43,19,71,63,41,21,99,40,75,55,27,82,80,83,54,66,75,61,86,14,10,74,38,92,31,49,97,20,98,15,71,59,96,53,86,35,60,6,73,71,59,79,10,84,69,23,82,14,7,76,99,45,19,96,92,14,63,55,71,46,71,34,74,73,22,95,89,10,24,59,69,17,42,96,12,92,94,66,1,69,91,36,90,94,13,17,33,46,20,89,90,24,12,94,92,83,42,73,43,70,83,55,17,92,66,23,74,99,1,92,82,54,71,96,1,22,78,74,94,66,78,40,87,13,87,73,74,89,26,26,70,42,79,3,9,84,72,55,98,56,27,73,74,57,85,66,76,88,55,58,30,97,40,71,76,6,10,55,71,43,36,99,46,59,34,37,84,61,85,90,62,98,18,39,46,84,23,70,93,9,71,5,71,94,5,59,40,71,26,90,12,45,57,74,5,92,86,32,99,20,92,82,22,44,88,29,41,89,7,86,81,72,76,9,94,94,3,8,94,71,12,93,6,82,91,91,20,86,86,38,85,95,42,86,85,19,57,90,17,85,6,84,17,81,42,77,63,26,59,9,24,85,22,31,35,93,64,90,4,16,91,67,83,23,43,63,75,3,88,93,52,14,84,85,36,95,12,51,79,54,1,16,72,1,76,79,88,63,95,77,6,91,86,23,92,54,91,51,82,45,14,98,89,74,47,52,82,80,65,74,44,58,90,14,98,42,91,6,50,88,29,81,96,25,1,97,62,62,73,61,48,82,76,93,98,49,14,74,6,97,30,47,73,77,8,89,10,17,65,21,74,95,43,83,89,72,96,27,59,20,58,80,10,70,86,42,92,26,50,98,85,3,62,20,93,86,78,19,78,91,23,90,37,71,66,97,97,95,86,40,46,79,70,37,14,98,51,91,81,4,9,77,93,19,53,70,87,40,11,95,25,93,90,17,98,39,76,92,55,57,93,39,76,13,99,58,92,26,88,80,65,34,71,62,72,17,64,38,97,85,32,4,88,69,82,51,63,61,71,77,33,90,59,74,49,76,8,76,93,55,36,71,84,7,67,47,3,85,98,9,99,32,8,79,18,28,55,77,10,30,79,77,4,1,99,82,66,90,41,64,22,82,33,20,87,24,29,80,53,72,27,17,85,84,70,16,94,11,81,92,48,85,61,47,83,21,45,92,92,38,61,75,98,52,73,80,29,82,94,29,85,61,69,59,35,84,86,60,98,63,83,69,39,10,15,64,18,85,88,63,97,95,56,13,43,75,93,13,34,85,57,37,96,39,65,60,73,73,82,11,81,80,38,88,76,23,88,19,70,2,93,46,28,79,92,91,18,6,92,96,50,77,56,45,77,36,64,83,91,64,75,48,72,71,17,69,40,82,7,6,92,70,25,23,72,9,23,84,16,17,75,76,70,60,61,99,86,21,27,85,63,80,81,55,87,93,97,53,78,53,97,14,97,49,85,65,91,72,72,5,93,34,81,10,85,86,81,19,87,61,84,11,99,96,94,8,78,13,84,9,70,0,0,21,21,1,10,1,0,0,0,0,0,0
|
318
2019/d15/ex2/ex2.py
Executable file
318
2019/d15/ex2/ex2.py
Executable file
|
@ -0,0 +1,318 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import heapq
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum, IntEnum, auto
|
||||
from typing import List, NamedTuple, Optional, Set
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self): # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
class Movement(IntEnum):
|
||||
NORTH = 1
|
||||
SOUTH = 2
|
||||
WEST = 3
|
||||
EAST = 4
|
||||
|
||||
|
||||
class StatusCode(IntEnum):
|
||||
BLOCKED = 0
|
||||
SUCCESS = 1
|
||||
ON_TANK = 2
|
||||
|
||||
|
||||
class BlockType(Enum):
|
||||
WALL = auto()
|
||||
HALLWAY = auto()
|
||||
OXYGEN_TANK = auto()
|
||||
|
||||
|
||||
class Coordinate(NamedTuple):
|
||||
x: int
|
||||
y: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class GraphNode:
|
||||
memory_state: Optional[List[int]] # Only walls have no need for the memory state
|
||||
block_type: BlockType
|
||||
parent: Optional[Coordinate] # Only the root of the exploration has no parent
|
||||
|
||||
|
||||
def coord_plus_dir(c: Coordinate, d: Movement) -> Coordinate:
|
||||
offset = {
|
||||
Movement.NORTH: Coordinate(0, 1),
|
||||
Movement.SOUTH: Coordinate(0, -1),
|
||||
Movement.WEST: Coordinate(-1, 0),
|
||||
Movement.EAST: Coordinate(1, 0),
|
||||
}
|
||||
return Coordinate(*(a + b for (a, b) in zip(c, offset[d])))
|
||||
|
||||
|
||||
def move_to_opposite(d: Movement) -> Movement:
|
||||
if d == Movement.NORTH:
|
||||
return Movement.SOUTH
|
||||
elif d == Movement.SOUTH:
|
||||
return Movement.NORTH
|
||||
elif d == Movement.WEST:
|
||||
return Movement.EAST
|
||||
else:
|
||||
return Movement.WEST
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
droid = Computer(memory)
|
||||
block_map = {Coordinate(0, 0): BlockType.HALLWAY}
|
||||
|
||||
def dfs(p: Coordinate, direction: Movement) -> None:
|
||||
end_coord = coord_plus_dir(p, direction)
|
||||
if end_coord in block_map:
|
||||
return # Nothing to do
|
||||
|
||||
droid.input_list.append(int(direction))
|
||||
try:
|
||||
droid.run()
|
||||
except OutputInterrupt:
|
||||
status = StatusCode(droid.output_list.pop(0))
|
||||
if status == StatusCode.BLOCKED:
|
||||
block_map[end_coord] = BlockType.WALL
|
||||
return # Don't need to backtrack
|
||||
block_map[end_coord] = (
|
||||
BlockType.OXYGEN_TANK
|
||||
if status == StatusCode.ON_TANK
|
||||
else BlockType.HALLWAY
|
||||
)
|
||||
for d in Movement:
|
||||
dfs(end_coord, d)
|
||||
droid.input_list.append(int(move_to_opposite(direction)))
|
||||
try:
|
||||
droid.run()
|
||||
except OutputInterrupt:
|
||||
droid.output_list.pop(0)
|
||||
|
||||
for direction in Movement:
|
||||
dfs(Coordinate(0, 0), direction)
|
||||
assert len(droid.input_list) == 0 and len(droid.output_list) == 0 # Sanity check
|
||||
|
||||
block_map = {p: t for p, t in block_map.items() if t != BlockType.WALL}
|
||||
oxygen_gen = (
|
||||
pos for pos, block in block_map.items() if block == BlockType.OXYGEN_TANK
|
||||
)
|
||||
oxygen_pos = next(oxygen_gen)
|
||||
assert next(oxygen_gen, None) is None # Sanity check
|
||||
|
||||
seen: Set[Coordinate] = set()
|
||||
to_visit = [(0, oxygen_pos)]
|
||||
|
||||
max_dist = 0
|
||||
|
||||
def fill_oxygen() -> None:
|
||||
nonlocal max_dist
|
||||
while len(to_visit) != 0:
|
||||
dist, pos = heapq.heappop(to_visit)
|
||||
if pos in seen:
|
||||
continue
|
||||
if pos not in block_map:
|
||||
continue
|
||||
seen.add(pos)
|
||||
max_dist = max(max_dist, dist)
|
||||
for d in Movement:
|
||||
new_pos = coord_plus_dir(pos, d)
|
||||
heapq.heappush(to_visit, (dist + 1, new_pos))
|
||||
|
||||
fill_oxygen()
|
||||
print(max_dist)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d15/ex2/input
Normal file
1
2019/d15/ex2/input
Normal file
|
@ -0,0 +1 @@
|
|||
3,1033,1008,1033,1,1032,1005,1032,31,1008,1033,2,1032,1005,1032,58,1008,1033,3,1032,1005,1032,81,1008,1033,4,1032,1005,1032,104,99,101,0,1034,1039,1001,1036,0,1041,1001,1035,-1,1040,1008,1038,0,1043,102,-1,1043,1032,1,1037,1032,1042,1105,1,124,1002,1034,1,1039,1001,1036,0,1041,1001,1035,1,1040,1008,1038,0,1043,1,1037,1038,1042,1106,0,124,1001,1034,-1,1039,1008,1036,0,1041,101,0,1035,1040,1001,1038,0,1043,1002,1037,1,1042,1105,1,124,1001,1034,1,1039,1008,1036,0,1041,1002,1035,1,1040,101,0,1038,1043,1001,1037,0,1042,1006,1039,217,1006,1040,217,1008,1039,40,1032,1005,1032,217,1008,1040,40,1032,1005,1032,217,1008,1039,33,1032,1006,1032,165,1008,1040,33,1032,1006,1032,165,1101,2,0,1044,1106,0,224,2,1041,1043,1032,1006,1032,179,1101,0,1,1044,1106,0,224,1,1041,1043,1032,1006,1032,217,1,1042,1043,1032,1001,1032,-1,1032,1002,1032,39,1032,1,1032,1039,1032,101,-1,1032,1032,101,252,1032,211,1007,0,68,1044,1106,0,224,1101,0,0,1044,1105,1,224,1006,1044,247,1002,1039,1,1034,102,1,1040,1035,1001,1041,0,1036,1002,1043,1,1038,1001,1042,0,1037,4,1044,1105,1,0,67,55,37,80,63,12,30,78,95,7,20,63,83,54,86,58,97,11,84,24,11,77,42,78,22,54,89,52,44,28,93,30,81,60,58,78,87,60,54,59,78,96,17,82,74,85,66,41,89,96,54,40,82,17,22,89,65,96,71,55,81,34,90,11,85,44,58,83,79,93,30,76,62,80,16,73,20,43,40,73,69,39,39,15,93,39,99,8,74,33,97,84,24,50,91,5,71,34,81,76,22,98,50,93,80,36,76,16,76,43,19,71,63,41,21,99,40,75,55,27,82,80,83,54,66,75,61,86,14,10,74,38,92,31,49,97,20,98,15,71,59,96,53,86,35,60,6,73,71,59,79,10,84,69,23,82,14,7,76,99,45,19,96,92,14,63,55,71,46,71,34,74,73,22,95,89,10,24,59,69,17,42,96,12,92,94,66,1,69,91,36,90,94,13,17,33,46,20,89,90,24,12,94,92,83,42,73,43,70,83,55,17,92,66,23,74,99,1,92,82,54,71,96,1,22,78,74,94,66,78,40,87,13,87,73,74,89,26,26,70,42,79,3,9,84,72,55,98,56,27,73,74,57,85,66,76,88,55,58,30,97,40,71,76,6,10,55,71,43,36,99,46,59,34,37,84,61,85,90,62,98,18,39,46,84,23,70,93,9,71,5,71,94,5,59,40,71,26,90,12,45,57,74,5,92,86,32,99,20,92,82,22,44,88,29,41,89,7,86,81,72,76,9,94,94,3,8,94,71,12,93,6,82,91,91,20,86,86,38,85,95,42,86,85,19,57,90,17,85,6,84,17,81,42,77,63,26,59,9,24,85,22,31,35,93,64,90,4,16,91,67,83,23,43,63,75,3,88,93,52,14,84,85,36,95,12,51,79,54,1,16,72,1,76,79,88,63,95,77,6,91,86,23,92,54,91,51,82,45,14,98,89,74,47,52,82,80,65,74,44,58,90,14,98,42,91,6,50,88,29,81,96,25,1,97,62,62,73,61,48,82,76,93,98,49,14,74,6,97,30,47,73,77,8,89,10,17,65,21,74,95,43,83,89,72,96,27,59,20,58,80,10,70,86,42,92,26,50,98,85,3,62,20,93,86,78,19,78,91,23,90,37,71,66,97,97,95,86,40,46,79,70,37,14,98,51,91,81,4,9,77,93,19,53,70,87,40,11,95,25,93,90,17,98,39,76,92,55,57,93,39,76,13,99,58,92,26,88,80,65,34,71,62,72,17,64,38,97,85,32,4,88,69,82,51,63,61,71,77,33,90,59,74,49,76,8,76,93,55,36,71,84,7,67,47,3,85,98,9,99,32,8,79,18,28,55,77,10,30,79,77,4,1,99,82,66,90,41,64,22,82,33,20,87,24,29,80,53,72,27,17,85,84,70,16,94,11,81,92,48,85,61,47,83,21,45,92,92,38,61,75,98,52,73,80,29,82,94,29,85,61,69,59,35,84,86,60,98,63,83,69,39,10,15,64,18,85,88,63,97,95,56,13,43,75,93,13,34,85,57,37,96,39,65,60,73,73,82,11,81,80,38,88,76,23,88,19,70,2,93,46,28,79,92,91,18,6,92,96,50,77,56,45,77,36,64,83,91,64,75,48,72,71,17,69,40,82,7,6,92,70,25,23,72,9,23,84,16,17,75,76,70,60,61,99,86,21,27,85,63,80,81,55,87,93,97,53,78,53,97,14,97,49,85,65,91,72,72,5,93,34,81,10,85,86,81,19,87,61,84,11,99,96,94,8,78,13,84,9,70,0,0,21,21,1,10,1,0,0,0,0,0,0
|
29
2019/d16/ex1/ex1.py
Executable file
29
2019/d16/ex1/ex1.py
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from functools import reduce
|
||||
from itertools import chain, cycle
|
||||
from typing import Iterable, List
|
||||
|
||||
|
||||
def sequencer(pattern: List[int], n: int) -> Iterable[int]:
|
||||
gen = cycle(list(chain(*([a] * n for a in pattern))))
|
||||
next(gen) # Skip the first one
|
||||
yield from gen
|
||||
|
||||
|
||||
def main() -> None:
|
||||
signal = [int(d) for d in sys.stdin.read().strip()]
|
||||
base_pattern = [0, 1, 0, -1]
|
||||
|
||||
for __ in range(100):
|
||||
signal = [
|
||||
abs(sum(a * b for a, b in zip(signal, sequencer(base_pattern, i + 1)))) % 10
|
||||
for i in range(len(signal))
|
||||
]
|
||||
|
||||
print(reduce(lambda a, b: a * 10 + b, signal[0:8]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d16/ex1/input
Normal file
1
2019/d16/ex1/input
Normal file
|
@ -0,0 +1 @@
|
|||
59793513516782374825915243993822865203688298721919339628274587775705006728427921751430533510981343323758576985437451867752936052153192753660463974146842169169504066730474876587016668826124639010922391218906707376662919204980583671961374243713362170277231101686574078221791965458164785925384486127508173239563372833776841606271237694768938831709136453354321708319835083666223956618272981294631469954624760620412170069396383335680428214399523030064601263676270903213996956414287336234682903859823675958155009987384202594409175930384736760416642456784909043049471828143167853096088824339425988907292558707480725410676823614387254696304038713756368483311
|
29
2019/d16/ex2/ex2.py
Executable file
29
2019/d16/ex2/ex2.py
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from functools import reduce
|
||||
from itertools import chain, cycle
|
||||
from typing import Iterable, List
|
||||
|
||||
|
||||
def main() -> None:
|
||||
rep = 10000
|
||||
signal = [int(d) for d in sys.stdin.read().strip()] * rep
|
||||
offset = reduce(lambda a, b: a * 10 + b, signal[0:7])
|
||||
|
||||
assert offset >= len(signal) / 2 # Sanity check
|
||||
# The trick is that the second half is only affected by itself (triangular matrix):
|
||||
# For i > len(signal) / 2, new_signal[i] = sum(signal, i, len(signal))
|
||||
# Therefore, we're only interested in numbers that start at the offset
|
||||
signal = signal[offset:] # Only take the end we need
|
||||
|
||||
for __ in range(100):
|
||||
for i in range(len(signal) - 1, 0, -1): # Do the sum from the end
|
||||
signal[i - 1] += signal[i]
|
||||
signal[i - 1] = signal[i - 1] % 10
|
||||
|
||||
print(reduce(lambda a, b: a * 10 + b, signal[:8]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d16/ex2/input
Normal file
1
2019/d16/ex2/input
Normal file
|
@ -0,0 +1 @@
|
|||
59793513516782374825915243993822865203688298721919339628274587775705006728427921751430533510981343323758576985437451867752936052153192753660463974146842169169504066730474876587016668826124639010922391218906707376662919204980583671961374243713362170277231101686574078221791965458164785925384486127508173239563372833776841606271237694768938831709136453354321708319835083666223956618272981294631469954624760620412170069396383335680428214399523030064601263676270903213996956414287336234682903859823675958155009987384202594409175930384736760416642456784909043049471828143167853096088824339425988907292558707480725410676823614387254696304038713756368483311
|
223
2019/d17/ex1/ex1.py
Executable file
223
2019/d17/ex1/ex1.py
Executable file
|
@ -0,0 +1,223 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from enum import IntEnum
|
||||
from typing import List, NamedTuple
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self): # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
camera = Computer(memory)
|
||||
|
||||
camera.run_no_output_interrupt()
|
||||
|
||||
view = "".join(chr(c) for c in camera.output_list)
|
||||
mapped_view = [[c for c in line] for line in view.split("\n") if line != ""]
|
||||
|
||||
def is_intersection(x: int, y: int) -> bool:
|
||||
neighbors_and_point = ((x, y), (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1))
|
||||
return all(mapped_view[a][b] not in (".", "X") for a, b in neighbors_and_point)
|
||||
|
||||
tot = 0
|
||||
for x in range(1, len(mapped_view) - 1):
|
||||
for y in range(1, len(mapped_view[0]) - 1): # No need to look at the borders
|
||||
if is_intersection(x, y):
|
||||
tot += x * y
|
||||
|
||||
print(tot)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d17/ex1/input
Normal file
1
2019/d17/ex1/input
Normal file
|
@ -0,0 +1 @@
|
|||
1,330,331,332,109,2952,1101,1182,0,16,1101,1467,0,24,102,1,0,570,1006,570,36,1002,571,1,0,1001,570,-1,570,1001,24,1,24,1106,0,18,1008,571,0,571,1001,16,1,16,1008,16,1467,570,1006,570,14,21101,0,58,0,1105,1,786,1006,332,62,99,21102,1,333,1,21101,73,0,0,1106,0,579,1101,0,0,572,1101,0,0,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,101,0,574,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21101,340,0,1,1105,1,177,21101,477,0,1,1106,0,177,21101,514,0,1,21101,0,176,0,1105,1,579,99,21102,1,184,0,1106,0,579,4,574,104,10,99,1007,573,22,570,1006,570,165,101,0,572,1182,21101,375,0,1,21101,211,0,0,1106,0,579,21101,1182,11,1,21101,222,0,0,1105,1,979,21101,0,388,1,21102,233,1,0,1106,0,579,21101,1182,22,1,21101,0,244,0,1106,0,979,21101,401,0,1,21102,1,255,0,1106,0,579,21101,1182,33,1,21101,266,0,0,1105,1,979,21101,414,0,1,21102,1,277,0,1106,0,579,3,575,1008,575,89,570,1008,575,121,575,1,575,570,575,3,574,1008,574,10,570,1006,570,291,104,10,21101,1182,0,1,21101,313,0,0,1105,1,622,1005,575,327,1101,0,1,575,21102,327,1,0,1106,0,786,4,438,99,0,1,1,6,77,97,105,110,58,10,33,10,69,120,112,101,99,116,101,100,32,102,117,110,99,116,105,111,110,32,110,97,109,101,32,98,117,116,32,103,111,116,58,32,0,12,70,117,110,99,116,105,111,110,32,65,58,10,12,70,117,110,99,116,105,111,110,32,66,58,10,12,70,117,110,99,116,105,111,110,32,67,58,10,23,67,111,110,116,105,110,117,111,117,115,32,118,105,100,101,111,32,102,101,101,100,63,10,0,37,10,69,120,112,101,99,116,101,100,32,82,44,32,76,44,32,111,114,32,100,105,115,116,97,110,99,101,32,98,117,116,32,103,111,116,58,32,36,10,69,120,112,101,99,116,101,100,32,99,111,109,109,97,32,111,114,32,110,101,119,108,105,110,101,32,98,117,116,32,103,111,116,58,32,43,10,68,101,102,105,110,105,116,105,111,110,115,32,109,97,121,32,98,101,32,97,116,32,109,111,115,116,32,50,48,32,99,104,97,114,97,99,116,101,114,115,33,10,94,62,118,60,0,1,0,-1,-1,0,1,0,0,0,0,0,0,1,20,14,0,109,4,2102,1,-3,586,21001,0,0,-1,22101,1,-3,-3,21102,1,0,-2,2208,-2,-1,570,1005,570,617,2201,-3,-2,609,4,0,21201,-2,1,-2,1105,1,597,109,-4,2105,1,0,109,5,2101,0,-4,629,21001,0,0,-2,22101,1,-4,-4,21101,0,0,-3,2208,-3,-2,570,1005,570,781,2201,-4,-3,652,21002,0,1,-1,1208,-1,-4,570,1005,570,709,1208,-1,-5,570,1005,570,734,1207,-1,0,570,1005,570,759,1206,-1,774,1001,578,562,684,1,0,576,576,1001,578,566,692,1,0,577,577,21101,702,0,0,1105,1,786,21201,-1,-1,-1,1106,0,676,1001,578,1,578,1008,578,4,570,1006,570,724,1001,578,-4,578,21101,0,731,0,1105,1,786,1106,0,774,1001,578,-1,578,1008,578,-1,570,1006,570,749,1001,578,4,578,21102,1,756,0,1105,1,786,1105,1,774,21202,-1,-11,1,22101,1182,1,1,21101,0,774,0,1105,1,622,21201,-3,1,-3,1106,0,640,109,-5,2106,0,0,109,7,1005,575,802,20102,1,576,-6,20101,0,577,-5,1106,0,814,21101,0,0,-1,21102,1,0,-5,21101,0,0,-6,20208,-6,576,-2,208,-5,577,570,22002,570,-2,-2,21202,-5,45,-3,22201,-6,-3,-3,22101,1467,-3,-3,1202,-3,1,843,1005,0,863,21202,-2,42,-4,22101,46,-4,-4,1206,-2,924,21102,1,1,-1,1106,0,924,1205,-2,873,21101,0,35,-4,1105,1,924,1201,-3,0,878,1008,0,1,570,1006,570,916,1001,374,1,374,1201,-3,0,895,1102,1,2,0,1201,-3,0,902,1001,438,0,438,2202,-6,-5,570,1,570,374,570,1,570,438,438,1001,578,558,921,21001,0,0,-4,1006,575,959,204,-4,22101,1,-6,-6,1208,-6,45,570,1006,570,814,104,10,22101,1,-5,-5,1208,-5,33,570,1006,570,810,104,10,1206,-1,974,99,1206,-1,974,1101,0,1,575,21101,973,0,0,1106,0,786,99,109,-7,2105,1,0,109,6,21101,0,0,-4,21102,1,0,-3,203,-2,22101,1,-3,-3,21208,-2,82,-1,1205,-1,1030,21208,-2,76,-1,1205,-1,1037,21207,-2,48,-1,1205,-1,1124,22107,57,-2,-1,1205,-1,1124,21201,-2,-48,-2,1106,0,1041,21102,-4,1,-2,1106,0,1041,21102,1,-5,-2,21201,-4,1,-4,21207,-4,11,-1,1206,-1,1138,2201,-5,-4,1059,1202,-2,1,0,203,-2,22101,1,-3,-3,21207,-2,48,-1,1205,-1,1107,22107,57,-2,-1,1205,-1,1107,21201,-2,-48,-2,2201,-5,-4,1090,20102,10,0,-1,22201,-2,-1,-2,2201,-5,-4,1103,1201,-2,0,0,1106,0,1060,21208,-2,10,-1,1205,-1,1162,21208,-2,44,-1,1206,-1,1131,1105,1,989,21101,0,439,1,1105,1,1150,21102,477,1,1,1106,0,1150,21102,1,514,1,21102,1149,1,0,1106,0,579,99,21102,1157,1,0,1105,1,579,204,-2,104,10,99,21207,-3,22,-1,1206,-1,1138,1202,-5,1,1176,2102,1,-4,0,109,-6,2105,1,0,10,11,34,1,9,1,34,1,9,1,7,9,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,9,1,13,3,1,26,1,9,1,3,1,3,1,20,11,5,1,1,9,18,1,5,1,3,1,5,1,1,1,1,1,3,1,1,1,18,1,5,1,3,1,5,1,1,1,1,1,3,1,1,1,18,1,5,1,3,1,5,1,1,1,1,1,3,1,1,1,18,1,5,1,1,9,1,1,1,1,3,9,12,1,5,1,3,1,7,1,1,1,5,1,5,1,10,9,3,1,1,9,5,1,5,1,10,1,1,1,9,1,1,1,5,1,7,1,5,14,9,9,7,1,5,2,9,1,13,1,13,1,5,2,7,9,7,1,13,1,5,2,7,1,1,1,5,1,7,1,19,2,7,1,1,1,5,1,7,1,19,2,7,1,1,1,5,1,7,1,19,2,7,1,1,13,1,1,7,14,7,1,7,1,5,1,1,1,7,1,12,1,7,1,7,1,5,1,1,1,7,1,12,1,7,1,7,1,5,1,1,1,7,1,12,9,7,9,7,1,34,1,9,1,34,1,9,1,34,1,9,1,34,11,12
|
350
2019/d17/ex2/ex2.py
Executable file
350
2019/d17/ex2/ex2.py
Executable file
|
@ -0,0 +1,350 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum, IntEnum, auto
|
||||
from typing import List, NamedTuple
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self): # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
class Position(NamedTuple):
|
||||
x: int
|
||||
y: int
|
||||
|
||||
|
||||
class Direction(Enum):
|
||||
NORTH = auto()
|
||||
WEST = auto()
|
||||
SOUTH = auto()
|
||||
EAST = auto()
|
||||
|
||||
|
||||
DIRECTIONS = [d for d in Direction]
|
||||
ARROW_DIRECTION = {
|
||||
"^": Direction.NORTH,
|
||||
"v": Direction.SOUTH,
|
||||
"<": Direction.WEST,
|
||||
">": Direction.EAST,
|
||||
}
|
||||
DIRECTION_OFFSET = {
|
||||
Direction.NORTH: (-1, 0),
|
||||
Direction.SOUTH: (1, 0),
|
||||
Direction.WEST: (0, -1),
|
||||
Direction.EAST: (0, 1),
|
||||
}
|
||||
|
||||
|
||||
def turn(d: Direction, turn: str) -> Direction:
|
||||
def turn_left() -> Direction:
|
||||
return DIRECTIONS[(DIRECTIONS.index(d) + 1) % len(DIRECTIONS)]
|
||||
|
||||
def turn_right() -> Direction:
|
||||
return DIRECTIONS[DIRECTIONS.index(d) - 1]
|
||||
|
||||
if turn == "L":
|
||||
return turn_left()
|
||||
elif turn == "R":
|
||||
return turn_right()
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def find_arrow(mapped_view: List[List[str]]) -> Position:
|
||||
for x in range(len(mapped_view)):
|
||||
for y in range(len(mapped_view[0])):
|
||||
if mapped_view[x][y] in ARROW_DIRECTION:
|
||||
return Position(x, y)
|
||||
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def get_path(mapped_view: List[List[str]]) -> List[str]:
|
||||
pos = find_arrow(mapped_view)
|
||||
|
||||
def pos_is_valid(p: Position) -> bool:
|
||||
return 0 <= p.x < len(mapped_view) and 0 <= p.y < len(mapped_view[0])
|
||||
|
||||
def pos_is_scaffold(p: Position) -> bool:
|
||||
return pos_is_valid(p) and mapped_view[p.x][p.y] != "."
|
||||
|
||||
direction = ARROW_DIRECTION[mapped_view[pos.x][pos.y]]
|
||||
ans: List[str] = []
|
||||
|
||||
def advance_until_stopped(turn_string: str) -> bool:
|
||||
nonlocal pos
|
||||
nonlocal direction
|
||||
d = turn(direction, turn_string)
|
||||
offset = DIRECTION_OFFSET[d]
|
||||
neighbor = Position(*(a + b for a, b in zip(pos, offset)))
|
||||
tot = 0
|
||||
while pos_is_scaffold(neighbor):
|
||||
tot += 1
|
||||
mapped_view[pos.x][pos.y] = "@"
|
||||
pos = neighbor
|
||||
neighbor = Position(*(a + b for a, b in zip(pos, offset)))
|
||||
|
||||
if tot == 0:
|
||||
return False
|
||||
direction = d
|
||||
ans.append(turn_string)
|
||||
ans.append(str(tot))
|
||||
return True
|
||||
|
||||
has_no_neighbors = False
|
||||
while not has_no_neighbors:
|
||||
for turn_string in ("L", "R"):
|
||||
if advance_until_stopped(turn_string):
|
||||
break
|
||||
else:
|
||||
has_no_neighbors = True
|
||||
return ans
|
||||
|
||||
|
||||
def sequitur_algorithm(path: str) -> None:
|
||||
# FIXME: seems like a good candidate for compression
|
||||
pass
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
camera = Computer(deepcopy(memory))
|
||||
|
||||
camera.run_no_output_interrupt()
|
||||
|
||||
view = "".join(chr(c) for c in camera.output_list)
|
||||
mapped_view = [[c for c in line] for line in view.split("\n") if line != ""]
|
||||
|
||||
path = get_path(mapped_view)
|
||||
print(path)
|
||||
|
||||
# I didn't want to write the compression algorithm when I could just use Vim
|
||||
# The answere is A,B,B,A,C,A,A,C,B,C
|
||||
# A: R,8,L,12,R,8
|
||||
# B: R,12,L,8,R,10
|
||||
# C: R,8,L,8,L,8,R,8,R,10
|
||||
|
||||
ans = "A,B,B,A,C,A,A,C,B,C"
|
||||
A = "R,8,L,12,R,8"
|
||||
B = "R,12,L,8,R,10"
|
||||
C = "R,8,L,8,L,8,R,8,R,10"
|
||||
|
||||
assert len(ans) <= 20 # Sanity check
|
||||
assert len(A) <= 20 # Sanity check
|
||||
assert len(B) <= 20 # Sanity check
|
||||
assert len(C) <= 20 # Sanity check
|
||||
|
||||
memory[0] = 2 # Wake up the robot
|
||||
robot = Computer(memory)
|
||||
|
||||
for c in ans:
|
||||
robot.input_list.append(ord(c))
|
||||
robot.input_list.append(ord("\n"))
|
||||
for c in A:
|
||||
robot.input_list.append(ord(c))
|
||||
robot.input_list.append(ord("\n"))
|
||||
for c in B:
|
||||
robot.input_list.append(ord(c))
|
||||
robot.input_list.append(ord("\n"))
|
||||
for c in C:
|
||||
robot.input_list.append(ord(c))
|
||||
robot.input_list.append(ord("\n"))
|
||||
|
||||
for c in "n\n": # Do not output the video feed
|
||||
robot.input_list.append(ord(c))
|
||||
|
||||
robot.run_no_output_interrupt()
|
||||
print(robot.output_list.pop())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d17/ex2/input
Normal file
1
2019/d17/ex2/input
Normal file
|
@ -0,0 +1 @@
|
|||
1,330,331,332,109,2952,1101,1182,0,16,1101,1467,0,24,102,1,0,570,1006,570,36,1002,571,1,0,1001,570,-1,570,1001,24,1,24,1106,0,18,1008,571,0,571,1001,16,1,16,1008,16,1467,570,1006,570,14,21101,0,58,0,1105,1,786,1006,332,62,99,21102,1,333,1,21101,73,0,0,1106,0,579,1101,0,0,572,1101,0,0,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,101,0,574,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21101,340,0,1,1105,1,177,21101,477,0,1,1106,0,177,21101,514,0,1,21101,0,176,0,1105,1,579,99,21102,1,184,0,1106,0,579,4,574,104,10,99,1007,573,22,570,1006,570,165,101,0,572,1182,21101,375,0,1,21101,211,0,0,1106,0,579,21101,1182,11,1,21101,222,0,0,1105,1,979,21101,0,388,1,21102,233,1,0,1106,0,579,21101,1182,22,1,21101,0,244,0,1106,0,979,21101,401,0,1,21102,1,255,0,1106,0,579,21101,1182,33,1,21101,266,0,0,1105,1,979,21101,414,0,1,21102,1,277,0,1106,0,579,3,575,1008,575,89,570,1008,575,121,575,1,575,570,575,3,574,1008,574,10,570,1006,570,291,104,10,21101,1182,0,1,21101,313,0,0,1105,1,622,1005,575,327,1101,0,1,575,21102,327,1,0,1106,0,786,4,438,99,0,1,1,6,77,97,105,110,58,10,33,10,69,120,112,101,99,116,101,100,32,102,117,110,99,116,105,111,110,32,110,97,109,101,32,98,117,116,32,103,111,116,58,32,0,12,70,117,110,99,116,105,111,110,32,65,58,10,12,70,117,110,99,116,105,111,110,32,66,58,10,12,70,117,110,99,116,105,111,110,32,67,58,10,23,67,111,110,116,105,110,117,111,117,115,32,118,105,100,101,111,32,102,101,101,100,63,10,0,37,10,69,120,112,101,99,116,101,100,32,82,44,32,76,44,32,111,114,32,100,105,115,116,97,110,99,101,32,98,117,116,32,103,111,116,58,32,36,10,69,120,112,101,99,116,101,100,32,99,111,109,109,97,32,111,114,32,110,101,119,108,105,110,101,32,98,117,116,32,103,111,116,58,32,43,10,68,101,102,105,110,105,116,105,111,110,115,32,109,97,121,32,98,101,32,97,116,32,109,111,115,116,32,50,48,32,99,104,97,114,97,99,116,101,114,115,33,10,94,62,118,60,0,1,0,-1,-1,0,1,0,0,0,0,0,0,1,20,14,0,109,4,2102,1,-3,586,21001,0,0,-1,22101,1,-3,-3,21102,1,0,-2,2208,-2,-1,570,1005,570,617,2201,-3,-2,609,4,0,21201,-2,1,-2,1105,1,597,109,-4,2105,1,0,109,5,2101,0,-4,629,21001,0,0,-2,22101,1,-4,-4,21101,0,0,-3,2208,-3,-2,570,1005,570,781,2201,-4,-3,652,21002,0,1,-1,1208,-1,-4,570,1005,570,709,1208,-1,-5,570,1005,570,734,1207,-1,0,570,1005,570,759,1206,-1,774,1001,578,562,684,1,0,576,576,1001,578,566,692,1,0,577,577,21101,702,0,0,1105,1,786,21201,-1,-1,-1,1106,0,676,1001,578,1,578,1008,578,4,570,1006,570,724,1001,578,-4,578,21101,0,731,0,1105,1,786,1106,0,774,1001,578,-1,578,1008,578,-1,570,1006,570,749,1001,578,4,578,21102,1,756,0,1105,1,786,1105,1,774,21202,-1,-11,1,22101,1182,1,1,21101,0,774,0,1105,1,622,21201,-3,1,-3,1106,0,640,109,-5,2106,0,0,109,7,1005,575,802,20102,1,576,-6,20101,0,577,-5,1106,0,814,21101,0,0,-1,21102,1,0,-5,21101,0,0,-6,20208,-6,576,-2,208,-5,577,570,22002,570,-2,-2,21202,-5,45,-3,22201,-6,-3,-3,22101,1467,-3,-3,1202,-3,1,843,1005,0,863,21202,-2,42,-4,22101,46,-4,-4,1206,-2,924,21102,1,1,-1,1106,0,924,1205,-2,873,21101,0,35,-4,1105,1,924,1201,-3,0,878,1008,0,1,570,1006,570,916,1001,374,1,374,1201,-3,0,895,1102,1,2,0,1201,-3,0,902,1001,438,0,438,2202,-6,-5,570,1,570,374,570,1,570,438,438,1001,578,558,921,21001,0,0,-4,1006,575,959,204,-4,22101,1,-6,-6,1208,-6,45,570,1006,570,814,104,10,22101,1,-5,-5,1208,-5,33,570,1006,570,810,104,10,1206,-1,974,99,1206,-1,974,1101,0,1,575,21101,973,0,0,1106,0,786,99,109,-7,2105,1,0,109,6,21101,0,0,-4,21102,1,0,-3,203,-2,22101,1,-3,-3,21208,-2,82,-1,1205,-1,1030,21208,-2,76,-1,1205,-1,1037,21207,-2,48,-1,1205,-1,1124,22107,57,-2,-1,1205,-1,1124,21201,-2,-48,-2,1106,0,1041,21102,-4,1,-2,1106,0,1041,21102,1,-5,-2,21201,-4,1,-4,21207,-4,11,-1,1206,-1,1138,2201,-5,-4,1059,1202,-2,1,0,203,-2,22101,1,-3,-3,21207,-2,48,-1,1205,-1,1107,22107,57,-2,-1,1205,-1,1107,21201,-2,-48,-2,2201,-5,-4,1090,20102,10,0,-1,22201,-2,-1,-2,2201,-5,-4,1103,1201,-2,0,0,1106,0,1060,21208,-2,10,-1,1205,-1,1162,21208,-2,44,-1,1206,-1,1131,1105,1,989,21101,0,439,1,1105,1,1150,21102,477,1,1,1106,0,1150,21102,1,514,1,21102,1149,1,0,1106,0,579,99,21102,1157,1,0,1105,1,579,204,-2,104,10,99,21207,-3,22,-1,1206,-1,1138,1202,-5,1,1176,2102,1,-4,0,109,-6,2105,1,0,10,11,34,1,9,1,34,1,9,1,7,9,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,1,9,1,7,1,7,1,18,9,1,13,3,1,26,1,9,1,3,1,3,1,20,11,5,1,1,9,18,1,5,1,3,1,5,1,1,1,1,1,3,1,1,1,18,1,5,1,3,1,5,1,1,1,1,1,3,1,1,1,18,1,5,1,3,1,5,1,1,1,1,1,3,1,1,1,18,1,5,1,1,9,1,1,1,1,3,9,12,1,5,1,3,1,7,1,1,1,5,1,5,1,10,9,3,1,1,9,5,1,5,1,10,1,1,1,9,1,1,1,5,1,7,1,5,14,9,9,7,1,5,2,9,1,13,1,13,1,5,2,7,9,7,1,13,1,5,2,7,1,1,1,5,1,7,1,19,2,7,1,1,1,5,1,7,1,19,2,7,1,1,1,5,1,7,1,19,2,7,1,1,13,1,1,7,14,7,1,7,1,5,1,1,1,7,1,12,1,7,1,7,1,5,1,1,1,7,1,12,1,7,1,7,1,5,1,1,1,7,1,12,9,7,9,7,1,34,1,9,1,34,1,9,1,34,1,9,1,34,11,12
|
129
2019/d18/ex1/ex1.py
Executable file
129
2019/d18/ex1/ex1.py
Executable file
|
@ -0,0 +1,129 @@
|
|||
#!/usr/bin/env python
|
||||
import heapq
|
||||
import sys
|
||||
from collections import defaultdict, deque
|
||||
from dataclasses import dataclass
|
||||
from functools import lru_cache
|
||||
from math import inf
|
||||
from typing import (DefaultDict, Deque, Dict, FrozenSet, Iterator, List, Tuple,
|
||||
Union)
|
||||
|
||||
RawGrid = List[str]
|
||||
GraphInfo = List[Tuple[str, int]]
|
||||
Graph = Dict[str, GraphInfo]
|
||||
|
||||
|
||||
@dataclass(eq=True, frozen=True) # Hash-able
|
||||
class Position:
|
||||
x: int
|
||||
y: int
|
||||
|
||||
|
||||
def neighbours(grid: RawGrid, pos: Position) -> Iterator[Position]:
|
||||
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||
new_pos = Position(pos.x + dx, pos.y + dy)
|
||||
if not (0 <= new_pos.x < len(grid) and 0 <= new_pos.y < len(grid[0])):
|
||||
continue
|
||||
if grid[new_pos.x][new_pos.y] == "#":
|
||||
continue
|
||||
yield new_pos
|
||||
|
||||
|
||||
def find_adjacent(grid: RawGrid, pos: Position) -> GraphInfo:
|
||||
queue: Deque[Tuple[Position, int]] = deque()
|
||||
visited = {pos}
|
||||
adjacent: GraphInfo = []
|
||||
|
||||
for n in neighbours(grid, pos):
|
||||
queue.append((n, 1)) # Distance is 1
|
||||
|
||||
while queue:
|
||||
n, d = queue.popleft()
|
||||
if n in visited:
|
||||
continue
|
||||
visited |= {n}
|
||||
cell = grid[n.x][n.y]
|
||||
|
||||
if cell not in "#.@": # We don't care about those
|
||||
adjacent.append((cell, d))
|
||||
continue # Do not go through doors and keys
|
||||
|
||||
for neighbour in neighbours(grid, n):
|
||||
queue.append((neighbour, d + 1))
|
||||
|
||||
return adjacent
|
||||
|
||||
|
||||
def build_graph(grid: RawGrid) -> Graph:
|
||||
graph = {}
|
||||
|
||||
for x, row in enumerate(grid):
|
||||
for y, cell in enumerate(row):
|
||||
if cell not in "#.":
|
||||
graph[cell] = find_adjacent(grid, Position(x, y))
|
||||
|
||||
return graph
|
||||
|
||||
|
||||
def solve(G: Graph, start: str) -> int:
|
||||
@lru_cache(2 ** 20)
|
||||
def reachable_keys(src: str, found: FrozenSet[str]) -> List[Tuple[str, int]]:
|
||||
queue = []
|
||||
distance: DefaultDict[str, Union[float, int]] = defaultdict(lambda: inf)
|
||||
reachable: List[Tuple[str, int]] = []
|
||||
|
||||
for neighbor, weight in G[src]:
|
||||
queue.append((weight, neighbor)) # Weight first for heap comparisons
|
||||
|
||||
heapq.heapify(queue)
|
||||
|
||||
while queue:
|
||||
dist, node = heapq.heappop(queue)
|
||||
|
||||
# Do key, add it to reachable if not found previously
|
||||
if node.islower() and node not in found:
|
||||
reachable.append((node, dist))
|
||||
continue
|
||||
|
||||
# Do door, if not opened by a key that was found in the search
|
||||
if node.lower() not in found:
|
||||
continue
|
||||
|
||||
# If not a key and not a closed door
|
||||
for neighbor, weight in G[node]:
|
||||
new_dist = dist + weight
|
||||
if new_dist < distance[neighbor]:
|
||||
distance[neighbor] = new_dist
|
||||
heapq.heappush(queue, (new_dist, neighbor))
|
||||
|
||||
return reachable
|
||||
|
||||
@lru_cache(2 ** 20)
|
||||
def min_steps(
|
||||
src: str, keys_to_find: int, found: FrozenSet[str] = frozenset()
|
||||
) -> int:
|
||||
if keys_to_find == 0:
|
||||
return 0
|
||||
|
||||
best = inf
|
||||
|
||||
for key, dist in reachable_keys(src, found):
|
||||
new_keys = found | {key}
|
||||
dist += min_steps(key, keys_to_find - 1, new_keys)
|
||||
|
||||
if dist < best:
|
||||
best = dist
|
||||
|
||||
return int(best) # That way we throw if we kept the infinite float
|
||||
|
||||
total_keys = sum(node.islower() for node in G)
|
||||
return min_steps(start, total_keys)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
G = build_graph(list(line.strip() for line in sys.stdin.readlines()))
|
||||
print(solve(G, "@"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
81
2019/d18/ex1/input
Normal file
81
2019/d18/ex1/input
Normal file
|
@ -0,0 +1,81 @@
|
|||
#################################################################################
|
||||
#.......#...#...#...........#.....#...#.#.....#m......#.......#.....#........u..#
|
||||
#####.#.#.#.#.#.###.#######.###.#.#.#.#.#.###.###.#####.#.###.###.#.###########.#
|
||||
#.....#...#...#.....#.#.....#...#...#...#.#....e#.......#...#.....#.....#.......#
|
||||
#.###################.#.#####.#########.#.#####.###########.###########.#.#######
|
||||
#.#...#...#...........#.#.....#.......#.#.....#.....#.....#...#.......#.#.#.....#
|
||||
#.#S#.###.#.#####.#####.#.###.#.###.###.#####.#####.#.###.###.#.#.#####.#.#.###.#
|
||||
#.#.#...#.#...#.#.......#.#.#.#.#...#...#.D.#.#...#...#.#.#...#.#.#.....#j..#...#
|
||||
#.#.###.#.###.#.#########.#.#.###.###.###.#.#.#.#.#####.#.#.###.###.#########.###
|
||||
#.#...#.#...#...#.#.........#...#.#...#.#.#...#.#.....#...#...#...#.#.#.....#...#
|
||||
#.###.#.###.###.#.#.#########.#.#.#.###.#.#####.#####.#.#####.###.#.#.#.#.#.###.#
|
||||
#...#.#c..#.....#.......#...#.#.#.#.#...#...#.....#.#.#.#.....#...#.#...#.#...#.#
|
||||
#.###.###.#.#############.#.###.#.#.#.#.###.#####.#.#.#.#.#####.###.#.###.###.#.#
|
||||
#.#...#.#.#.........#.....#...#.#.....#.#.#...#.#...#.#...#...#.....#.#...#...K.#
|
||||
#.#.###.#.#########.#.#######.#.#########.###.#.###.#.#####.#.#.#######.#########
|
||||
#.......#.#.......#h..#.....#.#.........#...#.#.....#.......#...#.....#.#...#...#
|
||||
#.#######.#O#####.#######.#.#.#.#######.###.#.#.#######.#######.#.###F#.#.#.#.#.#
|
||||
#.#....y..#...#...#.....#.#.#.#.#.#.....#...#.#.#.....#.#.....#...#.#.#...#.#.#.#
|
||||
###.#####.###.#.###.###.#.###.#.#.#.###.#.#.#.###.###.#.#.###.#####.#.#.###.#.#.#
|
||||
#...#.....#.#.#...#.#.Z.#...#.#.#.#.#...#.#.#.....#.#.#.#.#.#...#.....#...#...#.#
|
||||
#.###.#####.#.###A#.#.###.#.#.#.#.#.#####.#########.#.#.#.#.###.#.#########.###.#
|
||||
#.#.#.#.....#.#.#...#.#...#...#...#.....#.#.........#.#.#.#.#...#.#.......#.#...#
|
||||
#.#.#.#####.#.#.#######.#########.#####.#.#.#####.#.#.#.#.#.#####.#.###.#.###.#.#
|
||||
#.#.#...#...#.#...#.....#.....#.......#.#.#.#.#...#.#.#.#.#.....#.#.#...#.....#.#
|
||||
#.#.###.#.#.#.###.#.#######.#.#####.###.#.#.#.#.#####.#.#.#.#.###.###.#########X#
|
||||
#.#...#...#.#...#.#...#.....#.....#.#...#.....#.#...#.#.#.#.#...#...#.....#.....#
|
||||
#.#W#.#####.###N#.###.#.#.#######.###.#.#######.#.#.#.###.#.###.###.#####.###.###
|
||||
#i#.#.....#.#.#.#...#.#.#.#.....#.....#.#..r..#...#.#...#.#.#.....#.#...#...#.#.#
|
||||
#.#######.#.#.#.#.###.###.#.###########.#.###.#.###.###.#.###.#####.#.#.###.#.#.#
|
||||
#.......#...#.#.#...#...#.#.............#.#.#.#.#.#...#...#...#.....#.#.....#.#.#
|
||||
#.#####.#.###.#.#.#.###.#.#.#############.#.#.#.#.###.#####.###.#####.#######.#.#
|
||||
#.#.#...#.....#.#.#...#..t#...#.#.......#.#.#.#...#.....#.....#...#...#.....#.#.#
|
||||
#.#.#.#######.#.#.###.#######.#.#.#.#####.#.#.#.###.###.#####.###.###.#.###.#.#.#
|
||||
#...#.#...#...#.#...#.....#.#.#...#.....#.#.#.#.#...#.........#.#...#...T.#.#...#
|
||||
###.#.#.#.#.###.###.#.###.#.#.#########.#.#.#.###.###########.#.###.#####.#.###.#
|
||||
#...#...#.#.#...#...#...#...#.......#...#.#.#...#.#.....#...#...#...#...#.#...#.#
|
||||
#.#######.###.###.#####.###########.#.###.#.###.#.#.###.#.#.###.#.###.#.#####.###
|
||||
#.#...#v#...#.#.#.....#.........#...#...#.#.......#...#..l#...#.#.....#.....#.P.#
|
||||
#.#.#.#.###.#.#.#####.#########.#.#####.#.###########.#######.#############.###.#
|
||||
#...#.....#...#...............#.............................#....b..............#
|
||||
#######################################.@.#######################################
|
||||
#...#.#.........#.....#...........#...........#...#.....#.......#...#.....Q.#...#
|
||||
#.#.#.#.#####.###.#.#.#.#####.###.#.###.#.###.#.#.#.###.#.#####.#.#.#.#.###.###.#
|
||||
#.#.#.#.#...#.....#.#.#.#.#...#...#...#.#.#.....#.#...#...#.....#.#.#.#...#.#...#
|
||||
#.#.#.#.#.#.#######.###.#.#.#####.###.#.#.#######.###.#####.#####.#.#.###.#.#.#.#
|
||||
#.#...#.#.#.....#.#.#.B...#.....#.#...#.#.....#.....#.#...#.......#.#.#...#...#.#
|
||||
#.#####.#.#####.#.#.#.#######.#.###.###.#.###.###.###.#.#####.#####.#.#.#######.#
|
||||
#.#...#q#..f#.....#...#.....#.#...#.#...#.#.#...#.#.....#...#.#...#...#.#.....#.#
|
||||
#.#.#.#.#.#.#######.###.###.###.#.#.#.###.#.###.###.#####.#.#.###.#####.#.###.#.#
|
||||
#...#.#.#.#...#...#p..#.#.#...#.#...#...#.....#...#.#.....#.#.....#...#...#...#.#
|
||||
#####.#.#####.#.#.###.#.#.###.#########.#####.###.#.#.#####.#####.###.#####.###.#
|
||||
#.....#.......#.#.#...#.#...#.#.......#.#...#.#.#...#.#...#.....#.....#.#...#.#.#
|
||||
#.###########.#.#.#####.###.#L#.#####R#.#.#.#.#.#####.#.#.#####.#####.#.#.###.#.#
|
||||
#...........#.#.#.......#...#...#...#...#.#.#.....#...#.#.....#...#...#.#...#...#
|
||||
#######.###.#.#.#########.#.#####.#.#######.#####.#.#######.#.###.#.###.###.###.#
|
||||
#.......#...#.#.#.........#.......#.....#...#.....#.#.....#.#...#.#...#...#...#.#
|
||||
#.#######.###.#.#.###.#################.#.###.#####.#.#.#.###.###.###.###.###.#.#
|
||||
#.#.........#.#.#...#.............#.....#.........#.#.#.#.....#...#.#.......#.#.#
|
||||
#.###.#######.#.###########.#####.#.###############.###.#####.#.###.#.#####.#.###
|
||||
#...#.#.......#.#.........#.#...#.#.#...#.......#...#...#.#...#.#.....#...#.#...#
|
||||
#.#G###.#######.#.#######.#.###.#.###.#.#.#####.#.###.###.#.###.#######.#.#####.#
|
||||
#.#...#....x#.#.#.#z#.....#.....#.....#.#.....#...#...#...#.#...#.......#.#...#.#
|
||||
#.###.#####.#.#.#.#.#########.#########.#####.#######.#.###.#####.#######.#.#.#.#
|
||||
#k#.#.....#...#...#.#.....#...#.......#.#...#.#.......#.#...#.....#.#...#...#.#.#
|
||||
#.#.#####.###.#####.#.###.#.###.#####.#.#.#.#.#.#.#####.#.###.#####.#.#.#####.#H#
|
||||
#.#.....#...#.....#.#...#.#.#...#...#...#.#...#.#.#.....#.#...#...#...#...#.#.#.#
|
||||
#.#.###.###.#####.#.###.#.#.#.###.#.###.#.#######.#.###.#.#.###.#.#.###.#Y#.#.#.#
|
||||
#...#...#.#...#...#.....#..o#.#.#.#.....#.#.......#.#...#...#...#...#...#...#..g#
|
||||
#####.###.#.###.#######.#####.#.#.#######.#####.###.###.#############.#####.###.#
|
||||
#...#.#...#.....#.....#.....#.#.#...#...#.......#.....#...#...........#.#...#...#
|
||||
#.#.#.###.#######.###.#######.#.###.#.###########.###.###.#.###########.#.###.###
|
||||
#.#.#.#.....#.#.....#.#.......#...#.#...#...#...#...#.#...#.......#...#.I.#.#...#
|
||||
#.#.#.#.###.#.#.###.#.#.#######.#.#.###.#.###.#.#.###.#.#########.###.#.###.###.#
|
||||
#.#.#.#.#...#s....#.#.#.......#a#.#.....#.#...#.#.#...#.....#.....#...#.....#.#.#
|
||||
#.###M#U###.#####.#.#.###.###.###.#####.#.#.###.#.#.#.#####.#.#####.#V#####.#.#.#
|
||||
#.....#...#...#...#.#...#...#.#...#....n#.#...#d..#.#.#.J.#...#.....#...#..w#.#.#
|
||||
#.#######.###.#####.###.#####.#.###.#####.###.#####.#.#.#.###.#####.#####.###.#.#
|
||||
#.......#.#.#...#...#.#.....#.#...#.#...#...#.#.#...#.#.#.#...#...#...........#.#
|
||||
#######.#.#.###E#.###.#####.#.#.#.#.###.#.###.#.#.#####.#.#####.#.#############.#
|
||||
#.........#.......#.........C.#.#.......#.......#.......#.......#...............#
|
||||
#################################################################################
|
131
2019/d18/ex2/ex2.py
Executable file
131
2019/d18/ex2/ex2.py
Executable file
|
@ -0,0 +1,131 @@
|
|||
#!/usr/bin/env python
|
||||
import heapq
|
||||
import sys
|
||||
from collections import defaultdict, deque
|
||||
from dataclasses import dataclass
|
||||
from functools import lru_cache
|
||||
from math import inf
|
||||
from typing import (DefaultDict, Deque, Dict, FrozenSet, Iterator, List, Tuple,
|
||||
Union)
|
||||
|
||||
RawGrid = List[str]
|
||||
GraphInfo = List[Tuple[str, int]]
|
||||
Graph = Dict[str, GraphInfo]
|
||||
|
||||
|
||||
@dataclass(eq=True, frozen=True) # Hash-able
|
||||
class Position:
|
||||
x: int
|
||||
y: int
|
||||
|
||||
|
||||
def neighbours(grid: RawGrid, pos: Position) -> Iterator[Position]:
|
||||
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
||||
new_pos = Position(pos.x + dx, pos.y + dy)
|
||||
if not (0 <= new_pos.x < len(grid) and 0 <= new_pos.y < len(grid[0])):
|
||||
continue
|
||||
if grid[new_pos.x][new_pos.y] == "#":
|
||||
continue
|
||||
yield new_pos
|
||||
|
||||
|
||||
def find_adjacent(grid: RawGrid, pos: Position) -> GraphInfo:
|
||||
queue: Deque[Tuple[Position, int]] = deque()
|
||||
visited = {pos}
|
||||
adjacent: GraphInfo = []
|
||||
|
||||
for n in neighbours(grid, pos):
|
||||
queue.append((n, 1)) # Distance is 1
|
||||
|
||||
while queue:
|
||||
n, d = queue.popleft()
|
||||
if n in visited:
|
||||
continue
|
||||
visited |= {n}
|
||||
cell = grid[n.x][n.y]
|
||||
|
||||
if cell not in "#.1234": # We don't care about those
|
||||
adjacent.append((cell, d))
|
||||
continue # Do not go through doors and keys
|
||||
|
||||
for neighbour in neighbours(grid, n):
|
||||
queue.append((neighbour, d + 1))
|
||||
|
||||
return adjacent
|
||||
|
||||
|
||||
def build_graph(grid: RawGrid) -> Graph:
|
||||
graph = {}
|
||||
|
||||
for x, row in enumerate(grid):
|
||||
for y, cell in enumerate(row):
|
||||
if cell not in "#.":
|
||||
graph[cell] = find_adjacent(grid, Position(x, y))
|
||||
|
||||
return graph
|
||||
|
||||
|
||||
def solve(G: Graph, start: str) -> int:
|
||||
@lru_cache(2 ** 20)
|
||||
def reachable_keys(src: str, found: FrozenSet[str]) -> GraphInfo:
|
||||
queue = []
|
||||
distance: DefaultDict[str, Union[float, int]] = defaultdict(lambda: inf)
|
||||
reachable: GraphInfo = []
|
||||
|
||||
for neighbor, weight in G[src]:
|
||||
queue.append((weight, neighbor)) # Weight first for heap comparisons
|
||||
|
||||
heapq.heapify(queue)
|
||||
|
||||
while queue:
|
||||
dist, node = heapq.heappop(queue)
|
||||
|
||||
# Do key, add it to reachable if not found previously
|
||||
if node.islower() and node not in found:
|
||||
reachable.append((node, dist))
|
||||
continue
|
||||
|
||||
# Do door, if not opened by a key that was found in the search
|
||||
if node.lower() not in found:
|
||||
continue
|
||||
|
||||
# If not a key and not a closed door
|
||||
for neighbor, weight in G[node]:
|
||||
new_dist = dist + weight
|
||||
if new_dist < distance[neighbor]:
|
||||
distance[neighbor] = new_dist
|
||||
heapq.heappush(queue, (new_dist, neighbor))
|
||||
|
||||
return reachable
|
||||
|
||||
@lru_cache(2 ** 20)
|
||||
def min_steps(
|
||||
sources: str, keys_to_find: int, found: FrozenSet[str] = frozenset()
|
||||
) -> Union[float, int]:
|
||||
if keys_to_find == 0:
|
||||
return 0
|
||||
|
||||
best = inf
|
||||
|
||||
for src in sources:
|
||||
for key, dist in reachable_keys(src, found):
|
||||
new_keys = found | {key}
|
||||
new_sources = sources.replace(src, key)
|
||||
new_dist = dist + min_steps(new_sources, keys_to_find - 1, new_keys)
|
||||
|
||||
if new_dist < best:
|
||||
best = new_dist
|
||||
|
||||
return best
|
||||
|
||||
total_keys = sum(node.islower() for node in G)
|
||||
return int(min_steps(start, total_keys)) # Throw if we kept the infinite float
|
||||
|
||||
|
||||
def main() -> None:
|
||||
G = build_graph(list(line.strip() for line in sys.stdin.readlines()))
|
||||
print(solve(G, "1234"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
81
2019/d18/ex2/input
Normal file
81
2019/d18/ex2/input
Normal file
|
@ -0,0 +1,81 @@
|
|||
#################################################################################
|
||||
#.......#...#...#...........#.....#...#.#.....#m......#.......#.....#........u..#
|
||||
#####.#.#.#.#.#.###.#######.###.#.#.#.#.#.###.###.#####.#.###.###.#.###########.#
|
||||
#.....#...#...#.....#.#.....#...#...#...#.#....e#.......#...#.....#.....#.......#
|
||||
#.###################.#.#####.#########.#.#####.###########.###########.#.#######
|
||||
#.#...#...#...........#.#.....#.......#.#.....#.....#.....#...#.......#.#.#.....#
|
||||
#.#S#.###.#.#####.#####.#.###.#.###.###.#####.#####.#.###.###.#.#.#####.#.#.###.#
|
||||
#.#.#...#.#...#.#.......#.#.#.#.#...#...#.D.#.#...#...#.#.#...#.#.#.....#j..#...#
|
||||
#.#.###.#.###.#.#########.#.#.###.###.###.#.#.#.#.#####.#.#.###.###.#########.###
|
||||
#.#...#.#...#...#.#.........#...#.#...#.#.#...#.#.....#...#...#...#.#.#.....#...#
|
||||
#.###.#.###.###.#.#.#########.#.#.#.###.#.#####.#####.#.#####.###.#.#.#.#.#.###.#
|
||||
#...#.#c..#.....#.......#...#.#.#.#.#...#...#.....#.#.#.#.....#...#.#...#.#...#.#
|
||||
#.###.###.#.#############.#.###.#.#.#.#.###.#####.#.#.#.#.#####.###.#.###.###.#.#
|
||||
#.#...#.#.#.........#.....#...#.#.....#.#.#...#.#...#.#...#...#.....#.#...#...K.#
|
||||
#.#.###.#.#########.#.#######.#.#########.###.#.###.#.#####.#.#.#######.#########
|
||||
#.......#.#.......#h..#.....#.#.........#...#.#.....#.......#...#.....#.#...#...#
|
||||
#.#######.#O#####.#######.#.#.#.#######.###.#.#.#######.#######.#.###F#.#.#.#.#.#
|
||||
#.#....y..#...#...#.....#.#.#.#.#.#.....#...#.#.#.....#.#.....#...#.#.#...#.#.#.#
|
||||
###.#####.###.#.###.###.#.###.#.#.#.###.#.#.#.###.###.#.#.###.#####.#.#.###.#.#.#
|
||||
#...#.....#.#.#...#.#.Z.#...#.#.#.#.#...#.#.#.....#.#.#.#.#.#...#.....#...#...#.#
|
||||
#.###.#####.#.###A#.#.###.#.#.#.#.#.#####.#########.#.#.#.#.###.#.#########.###.#
|
||||
#.#.#.#.....#.#.#...#.#...#...#...#.....#.#.........#.#.#.#.#...#.#.......#.#...#
|
||||
#.#.#.#####.#.#.#######.#########.#####.#.#.#####.#.#.#.#.#.#####.#.###.#.###.#.#
|
||||
#.#.#...#...#.#...#.....#.....#.......#.#.#.#.#...#.#.#.#.#.....#.#.#...#.....#.#
|
||||
#.#.###.#.#.#.###.#.#######.#.#####.###.#.#.#.#.#####.#.#.#.#.###.###.#########X#
|
||||
#.#...#...#.#...#.#...#.....#.....#.#...#.....#.#...#.#.#.#.#...#...#.....#.....#
|
||||
#.#W#.#####.###N#.###.#.#.#######.###.#.#######.#.#.#.###.#.###.###.#####.###.###
|
||||
#i#.#.....#.#.#.#...#.#.#.#.....#.....#.#..r..#...#.#...#.#.#.....#.#...#...#.#.#
|
||||
#.#######.#.#.#.#.###.###.#.###########.#.###.#.###.###.#.###.#####.#.#.###.#.#.#
|
||||
#.......#...#.#.#...#...#.#.............#.#.#.#.#.#...#...#...#.....#.#.....#.#.#
|
||||
#.#####.#.###.#.#.#.###.#.#.#############.#.#.#.#.###.#####.###.#####.#######.#.#
|
||||
#.#.#...#.....#.#.#...#..t#...#.#.......#.#.#.#...#.....#.....#...#...#.....#.#.#
|
||||
#.#.#.#######.#.#.###.#######.#.#.#.#####.#.#.#.###.###.#####.###.###.#.###.#.#.#
|
||||
#...#.#...#...#.#...#.....#.#.#...#.....#.#.#.#.#...#.........#.#...#...T.#.#...#
|
||||
###.#.#.#.#.###.###.#.###.#.#.#########.#.#.#.###.###########.#.###.#####.#.###.#
|
||||
#...#...#.#.#...#...#...#...#.......#...#.#.#...#.#.....#...#...#...#...#.#...#.#
|
||||
#.#######.###.###.#####.###########.#.###.#.###.#.#.###.#.#.###.#.###.#.#####.###
|
||||
#.#...#v#...#.#.#.....#.........#...#...#.#.......#...#..l#...#.#.....#.....#.P.#
|
||||
#.#.#.#.###.#.#.#####.#########.#.#####.#.###########.#######.#############.###.#
|
||||
#...#.....#...#...............#........1#2..................#....b..............#
|
||||
########################################@.#######################################
|
||||
#...#.#.........#.....#...........#....3#4....#...#.....#.......#...#.....Q.#...#
|
||||
#.#.#.#.#####.###.#.#.#.#####.###.#.###.#.###.#.#.#.###.#.#####.#.#.#.#.###.###.#
|
||||
#.#.#.#.#...#.....#.#.#.#.#...#...#...#.#.#.....#.#...#...#.....#.#.#.#...#.#...#
|
||||
#.#.#.#.#.#.#######.###.#.#.#####.###.#.#.#######.###.#####.#####.#.#.###.#.#.#.#
|
||||
#.#...#.#.#.....#.#.#.B...#.....#.#...#.#.....#.....#.#...#.......#.#.#...#...#.#
|
||||
#.#####.#.#####.#.#.#.#######.#.###.###.#.###.###.###.#.#####.#####.#.#.#######.#
|
||||
#.#...#q#..f#.....#...#.....#.#...#.#...#.#.#...#.#.....#...#.#...#...#.#.....#.#
|
||||
#.#.#.#.#.#.#######.###.###.###.#.#.#.###.#.###.###.#####.#.#.###.#####.#.###.#.#
|
||||
#...#.#.#.#...#...#p..#.#.#...#.#...#...#.....#...#.#.....#.#.....#...#...#...#.#
|
||||
#####.#.#####.#.#.###.#.#.###.#########.#####.###.#.#.#####.#####.###.#####.###.#
|
||||
#.....#.......#.#.#...#.#...#.#.......#.#...#.#.#...#.#...#.....#.....#.#...#.#.#
|
||||
#.###########.#.#.#####.###.#L#.#####R#.#.#.#.#.#####.#.#.#####.#####.#.#.###.#.#
|
||||
#...........#.#.#.......#...#...#...#...#.#.#.....#...#.#.....#...#...#.#...#...#
|
||||
#######.###.#.#.#########.#.#####.#.#######.#####.#.#######.#.###.#.###.###.###.#
|
||||
#.......#...#.#.#.........#.......#.....#...#.....#.#.....#.#...#.#...#...#...#.#
|
||||
#.#######.###.#.#.###.#################.#.###.#####.#.#.#.###.###.###.###.###.#.#
|
||||
#.#.........#.#.#...#.............#.....#.........#.#.#.#.....#...#.#.......#.#.#
|
||||
#.###.#######.#.###########.#####.#.###############.###.#####.#.###.#.#####.#.###
|
||||
#...#.#.......#.#.........#.#...#.#.#...#.......#...#...#.#...#.#.....#...#.#...#
|
||||
#.#G###.#######.#.#######.#.###.#.###.#.#.#####.#.###.###.#.###.#######.#.#####.#
|
||||
#.#...#....x#.#.#.#z#.....#.....#.....#.#.....#...#...#...#.#...#.......#.#...#.#
|
||||
#.###.#####.#.#.#.#.#########.#########.#####.#######.#.###.#####.#######.#.#.#.#
|
||||
#k#.#.....#...#...#.#.....#...#.......#.#...#.#.......#.#...#.....#.#...#...#.#.#
|
||||
#.#.#####.###.#####.#.###.#.###.#####.#.#.#.#.#.#.#####.#.###.#####.#.#.#####.#H#
|
||||
#.#.....#...#.....#.#...#.#.#...#...#...#.#...#.#.#.....#.#...#...#...#...#.#.#.#
|
||||
#.#.###.###.#####.#.###.#.#.#.###.#.###.#.#######.#.###.#.#.###.#.#.###.#Y#.#.#.#
|
||||
#...#...#.#...#...#.....#..o#.#.#.#.....#.#.......#.#...#...#...#...#...#...#..g#
|
||||
#####.###.#.###.#######.#####.#.#.#######.#####.###.###.#############.#####.###.#
|
||||
#...#.#...#.....#.....#.....#.#.#...#...#.......#.....#...#...........#.#...#...#
|
||||
#.#.#.###.#######.###.#######.#.###.#.###########.###.###.#.###########.#.###.###
|
||||
#.#.#.#.....#.#.....#.#.......#...#.#...#...#...#...#.#...#.......#...#.I.#.#...#
|
||||
#.#.#.#.###.#.#.###.#.#.#######.#.#.###.#.###.#.#.###.#.#########.###.#.###.###.#
|
||||
#.#.#.#.#...#s....#.#.#.......#a#.#.....#.#...#.#.#...#.....#.....#...#.....#.#.#
|
||||
#.###M#U###.#####.#.#.###.###.###.#####.#.#.###.#.#.#.#####.#.#####.#V#####.#.#.#
|
||||
#.....#...#...#...#.#...#...#.#...#....n#.#...#d..#.#.#.J.#...#.....#...#..w#.#.#
|
||||
#.#######.###.#####.###.#####.#.###.#####.###.#####.#.#.#.###.#####.#####.###.#.#
|
||||
#.......#.#.#...#...#.#.....#.#...#.#...#...#.#.#...#.#.#.#...#...#...........#.#
|
||||
#######.#.#.###E#.###.#####.#.#.#.#.###.#.###.#.#.#####.#.#####.#.#############.#
|
||||
#.........#.......#.........C.#.#.......#.......#.......#.......#...............#
|
||||
#################################################################################
|
214
2019/d19/ex1/ex1.py
Executable file
214
2019/d19/ex1/ex1.py
Executable file
|
@ -0,0 +1,214 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass, field
|
||||
from enum import IntEnum
|
||||
from itertools import product
|
||||
from typing import List, NamedTuple
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self) -> None: # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
|
||||
lines: List[List[int]] = [[0 for i in range(50)] for __ in range(50)]
|
||||
for x, y in product(range(50), range(50)):
|
||||
drone = Computer(deepcopy(memory), input_list=[x, y])
|
||||
drone.run_no_output_interrupt()
|
||||
assert len(drone.output_list) == 1
|
||||
lines[x][y] = drone.output_list.pop()
|
||||
print(sum(map(sum, lines)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d19/ex1/input
Normal file
1
2019/d19/ex1/input
Normal file
|
@ -0,0 +1 @@
|
|||
109,424,203,1,21102,11,1,0,1106,0,282,21102,18,1,0,1106,0,259,1201,1,0,221,203,1,21102,31,1,0,1106,0,282,21101,38,0,0,1106,0,259,21002,23,1,2,22102,1,1,3,21101,1,0,1,21102,57,1,0,1105,1,303,2102,1,1,222,20101,0,221,3,20101,0,221,2,21102,259,1,1,21101,80,0,0,1106,0,225,21101,0,44,2,21102,91,1,0,1105,1,303,1201,1,0,223,20101,0,222,4,21101,0,259,3,21102,225,1,2,21101,225,0,1,21102,118,1,0,1105,1,225,21002,222,1,3,21101,100,0,2,21101,133,0,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21101,148,0,0,1106,0,259,2102,1,1,223,20102,1,221,4,21002,222,1,3,21102,1,12,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,1,195,0,106,0,108,20207,1,223,2,21002,23,1,1,21102,-1,1,3,21101,0,214,0,1105,1,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2102,1,-4,249,21201,-3,0,1,22101,0,-2,2,22101,0,-1,3,21101,0,250,0,1105,1,225,22102,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21202,-2,1,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22102,1,-2,3,21101,0,343,0,1105,1,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,0,384,0,1106,0,303,1106,0,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22102,1,1,-4,109,-5,2106,0,0
|
221
2019/d19/ex2/ex2.py
Executable file
221
2019/d19/ex2/ex2.py
Executable file
|
@ -0,0 +1,221 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass, field
|
||||
from enum import IntEnum
|
||||
from typing import Iterator, List, NamedTuple, Tuple
|
||||
|
||||
|
||||
class ParameterMode(IntEnum):
|
||||
POSITION = 0 # Acts on address
|
||||
IMMEDIATE = 1 # Acts on the immediate value
|
||||
RELATIVE = 2 # Acts on offset to relative base
|
||||
|
||||
|
||||
class Instruction(NamedTuple):
|
||||
address: int # The address of the instruction, for convenience
|
||||
op: int # The opcode
|
||||
p1_mode: ParameterMode # Which mode is the first parameter in
|
||||
p2_mode: ParameterMode # Which mode is the second parameter in
|
||||
p3_mode: ParameterMode # Which mode is the third parameter in
|
||||
|
||||
|
||||
def lookup_ops(index: int, memory: List[int]) -> Instruction:
|
||||
digits = list(map(int, str(memory[index])))
|
||||
a, b, c, d, e = [0] * (5 - len(digits)) + digits # Pad with default values
|
||||
return Instruction(
|
||||
address=index,
|
||||
op=d * 10 + e,
|
||||
p1_mode=ParameterMode(c),
|
||||
p2_mode=ParameterMode(b),
|
||||
p3_mode=ParameterMode(a),
|
||||
)
|
||||
|
||||
|
||||
class InputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class OutputInterrupt(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Computer:
|
||||
memory: List[int] # Memory space
|
||||
rip: int = 0 # Instruction pointer
|
||||
input_list: List[int] = field(default_factory=list)
|
||||
output_list: List[int] = field(default_factory=list)
|
||||
is_halted: bool = field(default=False, init=False)
|
||||
relative_base: int = field(default=0, init=False)
|
||||
|
||||
def run(self) -> None:
|
||||
while not self.is_halted:
|
||||
self.run_single()
|
||||
|
||||
def run_no_output_interrupt(self) -> None:
|
||||
while not self.is_halted:
|
||||
try:
|
||||
self.run_single()
|
||||
except OutputInterrupt:
|
||||
continue
|
||||
|
||||
def run_single(self) -> None: # Returns True when halted
|
||||
instr = lookup_ops(self.rip, self.memory)
|
||||
if instr.op == 99: # Halt
|
||||
self.is_halted = True
|
||||
elif instr.op == 1: # Sum
|
||||
self._do_addition(instr)
|
||||
elif instr.op == 2: # Multiplication
|
||||
self._do_multiplication(instr)
|
||||
elif instr.op == 3: # Load from input
|
||||
self._do_input(instr)
|
||||
elif instr.op == 4: # Store to output
|
||||
self._do_output(instr)
|
||||
elif instr.op == 5: # Jump if true
|
||||
self._do_jump_if_true(instr)
|
||||
elif instr.op == 6: # Jump if false
|
||||
self._do_jump_if_false(instr)
|
||||
elif instr.op == 7: # Less than
|
||||
self._do_less_than(instr)
|
||||
elif instr.op == 8: # Equal to
|
||||
self._do_equal_to(instr)
|
||||
elif instr.op == 9: # Change relative base
|
||||
self._do_change_relative_base(instr)
|
||||
else:
|
||||
assert False # Sanity check
|
||||
|
||||
def _fill_to_addres(self, address: int) -> None:
|
||||
values = address - len(self.memory) + 1
|
||||
if values <= 0:
|
||||
return
|
||||
for __ in range(values):
|
||||
self.memory.append(0)
|
||||
|
||||
def _get_value(self, mode: ParameterMode, val: int) -> int:
|
||||
if mode == ParameterMode.POSITION:
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
elif mode == ParameterMode.RELATIVE:
|
||||
val += self.relative_base
|
||||
assert 0 <= val # Sanity check
|
||||
self._fill_to_addres(val)
|
||||
return self.memory[val]
|
||||
assert mode == ParameterMode.IMMEDIATE # Sanity check
|
||||
return val
|
||||
|
||||
def _set_value(self, mode: ParameterMode, address: int, value: int) -> None:
|
||||
if mode == ParameterMode.RELATIVE:
|
||||
address += self.relative_base
|
||||
else:
|
||||
assert mode == ParameterMode.POSITION # Sanity check
|
||||
|
||||
assert address >= 0 # Sanity check
|
||||
self._fill_to_addres(address)
|
||||
|
||||
self.memory[address] = value
|
||||
|
||||
def _do_addition(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs + rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_multiplication(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, lhs * rhs)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_input(self, instr: Instruction) -> None:
|
||||
if len(self.input_list) == 0:
|
||||
raise InputInterrupt # No input, halt until an input is provided
|
||||
|
||||
value = int(self.input_list.pop(0))
|
||||
param = self.memory[instr.address + 1]
|
||||
|
||||
self._set_value(instr.p1_mode, param, value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
def _do_output(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.output_list.append(value)
|
||||
|
||||
self.rip += 2 # Length of the instruction
|
||||
raise OutputInterrupt # Alert that we got an output to give
|
||||
|
||||
def _do_jump_if_true(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond != 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_jump_if_false(self, instr: Instruction) -> None:
|
||||
cond = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
value = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
|
||||
if cond == 0:
|
||||
self.rip = value
|
||||
else:
|
||||
self.rip += 3 # Length of the instruction
|
||||
|
||||
def _do_less_than(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs < rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_equal_to(self, instr: Instruction) -> None:
|
||||
lhs = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
rhs = self._get_value(instr.p2_mode, self.memory[instr.address + 2])
|
||||
dest = self.memory[instr.address + 3]
|
||||
|
||||
self._set_value(instr.p3_mode, dest, 1 if lhs == rhs else 0)
|
||||
|
||||
self.rip += 4 # Length of the instruction
|
||||
|
||||
def _do_change_relative_base(self, instr: Instruction) -> None:
|
||||
value = self._get_value(instr.p1_mode, self.memory[instr.address + 1])
|
||||
|
||||
self.relative_base += value
|
||||
self.rip += 2 # Length of the instruction
|
||||
|
||||
|
||||
def true_at(memory: List[int], x: int, y: int) -> bool:
|
||||
drone = Computer(deepcopy(memory), input_list=[x, y])
|
||||
drone.run_no_output_interrupt()
|
||||
assert len(drone.output_list) == 1
|
||||
return drone.output_list.pop() == 1
|
||||
|
||||
|
||||
def main() -> None:
|
||||
memory = [int(n) for n in sys.stdin.read().split(",")]
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
size = 100
|
||||
while not true_at(memory, x + size - 1, y):
|
||||
y += 1
|
||||
while not true_at(memory, x, y + size - 1):
|
||||
x += 1
|
||||
print((x * 10000 + y))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2019/d19/ex2/input
Normal file
1
2019/d19/ex2/input
Normal file
|
@ -0,0 +1 @@
|
|||
109,424,203,1,21102,11,1,0,1106,0,282,21102,18,1,0,1106,0,259,1201,1,0,221,203,1,21102,31,1,0,1106,0,282,21101,38,0,0,1106,0,259,21002,23,1,2,22102,1,1,3,21101,1,0,1,21102,57,1,0,1105,1,303,2102,1,1,222,20101,0,221,3,20101,0,221,2,21102,259,1,1,21101,80,0,0,1106,0,225,21101,0,44,2,21102,91,1,0,1105,1,303,1201,1,0,223,20101,0,222,4,21101,0,259,3,21102,225,1,2,21101,225,0,1,21102,118,1,0,1105,1,225,21002,222,1,3,21101,100,0,2,21101,133,0,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21101,148,0,0,1106,0,259,2102,1,1,223,20102,1,221,4,21002,222,1,3,21102,1,12,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21102,1,195,0,106,0,108,20207,1,223,2,21002,23,1,1,21102,-1,1,3,21101,0,214,0,1105,1,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2102,1,-4,249,21201,-3,0,1,22101,0,-2,2,22101,0,-1,3,21101,0,250,0,1105,1,225,22102,1,1,-4,109,-5,2106,0,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,21202,-2,1,-2,109,-3,2105,1,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,22102,1,-2,3,21101,0,343,0,1105,1,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,21201,-4,0,1,21101,0,384,0,1106,0,303,1106,0,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,22102,1,1,-4,109,-5,2106,0,0
|
17
2020/d01/ex1/ex1.py
Executable file
17
2020/d01/ex1/ex1.py
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
import functools
|
||||
import itertools
|
||||
import operator
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> None:
|
||||
values = [int(n) for n in sys.stdin.readlines()]
|
||||
for tup in itertools.combinations(values, 2):
|
||||
if sum(tup) == 2020:
|
||||
print(functools.reduce(operator.mul, tup))
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
200
2020/d01/ex1/input
Normal file
200
2020/d01/ex1/input
Normal file
|
@ -0,0 +1,200 @@
|
|||
1742
|
||||
1763
|
||||
1238
|
||||
1424
|
||||
1736
|
||||
1903
|
||||
1580
|
||||
1847
|
||||
1860
|
||||
1933
|
||||
1779
|
||||
1901
|
||||
1984
|
||||
1861
|
||||
1769
|
||||
1896
|
||||
1428
|
||||
2010
|
||||
1673
|
||||
1491
|
||||
1996
|
||||
1746
|
||||
1973
|
||||
1696
|
||||
1616
|
||||
2006
|
||||
1890
|
||||
1600
|
||||
1991
|
||||
1724
|
||||
1804
|
||||
1794
|
||||
462
|
||||
1706
|
||||
2002
|
||||
1939
|
||||
1834
|
||||
1312
|
||||
1943
|
||||
1465
|
||||
1405
|
||||
1459
|
||||
1659
|
||||
1288
|
||||
1241
|
||||
1935
|
||||
1294
|
||||
1388
|
||||
1772
|
||||
1945
|
||||
1649
|
||||
813
|
||||
1956
|
||||
1274
|
||||
1686
|
||||
1404
|
||||
1770
|
||||
1631
|
||||
1366
|
||||
1321
|
||||
1353
|
||||
1685
|
||||
1365
|
||||
1738
|
||||
1911
|
||||
1235
|
||||
1495
|
||||
1837
|
||||
1456
|
||||
1283
|
||||
1929
|
||||
1326
|
||||
1735
|
||||
1604
|
||||
1223
|
||||
1261
|
||||
1844
|
||||
1850
|
||||
1429
|
||||
277
|
||||
1848
|
||||
1818
|
||||
1395
|
||||
1522
|
||||
1863
|
||||
1475
|
||||
1562
|
||||
1351
|
||||
1538
|
||||
1313
|
||||
1416
|
||||
1690
|
||||
1539
|
||||
1338
|
||||
1982
|
||||
1297
|
||||
1821
|
||||
780
|
||||
1859
|
||||
1420
|
||||
1934
|
||||
1303
|
||||
1731
|
||||
1714
|
||||
1702
|
||||
1417
|
||||
1872
|
||||
1998
|
||||
1908
|
||||
1957
|
||||
1270
|
||||
1359
|
||||
1760
|
||||
1997
|
||||
1773
|
||||
2000
|
||||
1203
|
||||
1880
|
||||
1955
|
||||
1273
|
||||
1775
|
||||
1893
|
||||
1237
|
||||
1707
|
||||
1885
|
||||
1900
|
||||
1801
|
||||
1367
|
||||
1561
|
||||
1524
|
||||
1678
|
||||
1511
|
||||
1623
|
||||
1464
|
||||
1477
|
||||
1733
|
||||
1423
|
||||
1575
|
||||
1851
|
||||
2007
|
||||
1651
|
||||
804
|
||||
1836
|
||||
1849
|
||||
1713
|
||||
1401
|
||||
1502
|
||||
1806
|
||||
1506
|
||||
1646
|
||||
1968
|
||||
1253
|
||||
1889
|
||||
1759
|
||||
1734
|
||||
1611
|
||||
1558
|
||||
1256
|
||||
1657
|
||||
1778
|
||||
1953
|
||||
1578
|
||||
1717
|
||||
1498
|
||||
1381
|
||||
1919
|
||||
1512
|
||||
1391
|
||||
384
|
||||
1802
|
||||
1573
|
||||
1940
|
||||
1323
|
||||
2003
|
||||
1689
|
||||
1936
|
||||
1368
|
||||
1962
|
||||
1964
|
||||
1586
|
||||
1619
|
||||
1482
|
||||
1445
|
||||
372
|
||||
1792
|
||||
96
|
||||
1468
|
||||
1999
|
||||
1301
|
||||
1757
|
||||
1613
|
||||
1807
|
||||
1941
|
||||
1642
|
||||
1557
|
||||
1884
|
||||
1626
|
||||
489
|
||||
1989
|
||||
1327
|
17
2020/d01/ex2/ex2.py
Executable file
17
2020/d01/ex2/ex2.py
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
import functools
|
||||
import itertools
|
||||
import operator
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> None:
|
||||
values = [int(n) for n in sys.stdin.readlines()]
|
||||
for tup in itertools.combinations(values, 3):
|
||||
if sum(tup) == 2020:
|
||||
print(functools.reduce(operator.mul, tup))
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
200
2020/d01/ex2/input
Normal file
200
2020/d01/ex2/input
Normal file
|
@ -0,0 +1,200 @@
|
|||
1742
|
||||
1763
|
||||
1238
|
||||
1424
|
||||
1736
|
||||
1903
|
||||
1580
|
||||
1847
|
||||
1860
|
||||
1933
|
||||
1779
|
||||
1901
|
||||
1984
|
||||
1861
|
||||
1769
|
||||
1896
|
||||
1428
|
||||
2010
|
||||
1673
|
||||
1491
|
||||
1996
|
||||
1746
|
||||
1973
|
||||
1696
|
||||
1616
|
||||
2006
|
||||
1890
|
||||
1600
|
||||
1991
|
||||
1724
|
||||
1804
|
||||
1794
|
||||
462
|
||||
1706
|
||||
2002
|
||||
1939
|
||||
1834
|
||||
1312
|
||||
1943
|
||||
1465
|
||||
1405
|
||||
1459
|
||||
1659
|
||||
1288
|
||||
1241
|
||||
1935
|
||||
1294
|
||||
1388
|
||||
1772
|
||||
1945
|
||||
1649
|
||||
813
|
||||
1956
|
||||
1274
|
||||
1686
|
||||
1404
|
||||
1770
|
||||
1631
|
||||
1366
|
||||
1321
|
||||
1353
|
||||
1685
|
||||
1365
|
||||
1738
|
||||
1911
|
||||
1235
|
||||
1495
|
||||
1837
|
||||
1456
|
||||
1283
|
||||
1929
|
||||
1326
|
||||
1735
|
||||
1604
|
||||
1223
|
||||
1261
|
||||
1844
|
||||
1850
|
||||
1429
|
||||
277
|
||||
1848
|
||||
1818
|
||||
1395
|
||||
1522
|
||||
1863
|
||||
1475
|
||||
1562
|
||||
1351
|
||||
1538
|
||||
1313
|
||||
1416
|
||||
1690
|
||||
1539
|
||||
1338
|
||||
1982
|
||||
1297
|
||||
1821
|
||||
780
|
||||
1859
|
||||
1420
|
||||
1934
|
||||
1303
|
||||
1731
|
||||
1714
|
||||
1702
|
||||
1417
|
||||
1872
|
||||
1998
|
||||
1908
|
||||
1957
|
||||
1270
|
||||
1359
|
||||
1760
|
||||
1997
|
||||
1773
|
||||
2000
|
||||
1203
|
||||
1880
|
||||
1955
|
||||
1273
|
||||
1775
|
||||
1893
|
||||
1237
|
||||
1707
|
||||
1885
|
||||
1900
|
||||
1801
|
||||
1367
|
||||
1561
|
||||
1524
|
||||
1678
|
||||
1511
|
||||
1623
|
||||
1464
|
||||
1477
|
||||
1733
|
||||
1423
|
||||
1575
|
||||
1851
|
||||
2007
|
||||
1651
|
||||
804
|
||||
1836
|
||||
1849
|
||||
1713
|
||||
1401
|
||||
1502
|
||||
1806
|
||||
1506
|
||||
1646
|
||||
1968
|
||||
1253
|
||||
1889
|
||||
1759
|
||||
1734
|
||||
1611
|
||||
1558
|
||||
1256
|
||||
1657
|
||||
1778
|
||||
1953
|
||||
1578
|
||||
1717
|
||||
1498
|
||||
1381
|
||||
1919
|
||||
1512
|
||||
1391
|
||||
384
|
||||
1802
|
||||
1573
|
||||
1940
|
||||
1323
|
||||
2003
|
||||
1689
|
||||
1936
|
||||
1368
|
||||
1962
|
||||
1964
|
||||
1586
|
||||
1619
|
||||
1482
|
||||
1445
|
||||
372
|
||||
1792
|
||||
96
|
||||
1468
|
||||
1999
|
||||
1301
|
||||
1757
|
||||
1613
|
||||
1807
|
||||
1941
|
||||
1642
|
||||
1557
|
||||
1884
|
||||
1626
|
||||
489
|
||||
1989
|
||||
1327
|
42
2020/d02/ex1/ex1.py
Executable file
42
2020/d02/ex1/ex1.py
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
|
||||
|
||||
@dataclass
|
||||
class Policy:
|
||||
min: int
|
||||
max: int
|
||||
letter: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Password:
|
||||
policy: Policy
|
||||
password: str
|
||||
|
||||
|
||||
def is_valid(pwd: Password) -> bool:
|
||||
occurences = pwd.password.count(pwd.policy.letter)
|
||||
return pwd.policy.min <= occurences <= pwd.policy.max
|
||||
|
||||
|
||||
def solve(passwords: List[Password]) -> int:
|
||||
return sum(map(is_valid, passwords))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
pattern = re.compile("([0-9]+)-([0-9]+) (.): (.+)")
|
||||
input = [
|
||||
Password(Policy(int(m.group(1)), int(m.group(2)), m.group(3)), m.group(4))
|
||||
for m in (pattern.match(line) for line in sys.stdin.readlines())
|
||||
if m
|
||||
]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1000
2020/d02/ex1/input
Normal file
1000
2020/d02/ex1/input
Normal file
File diff suppressed because it is too large
Load diff
43
2020/d02/ex2/ex2.py
Executable file
43
2020/d02/ex2/ex2.py
Executable file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
|
||||
|
||||
@dataclass
|
||||
class Policy:
|
||||
min: int
|
||||
max: int
|
||||
letter: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Password:
|
||||
policy: Policy
|
||||
password: str
|
||||
|
||||
|
||||
def is_valid(pwd: Password) -> bool:
|
||||
min = pwd.password[pwd.policy.min - 1] == pwd.policy.letter
|
||||
max = pwd.password[pwd.policy.max - 1] == pwd.policy.letter
|
||||
return min ^ max
|
||||
|
||||
|
||||
def solve(passwords: List[Password]) -> int:
|
||||
return sum(map(is_valid, passwords))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
pattern = re.compile("([0-9]+)-([0-9]+) (.): (.+)")
|
||||
input = [
|
||||
Password(Policy(int(m.group(1)), int(m.group(2)), m.group(3)), m.group(4))
|
||||
for m in (pattern.match(line) for line in sys.stdin.readlines())
|
||||
if m
|
||||
]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1000
2020/d02/ex2/input
Normal file
1000
2020/d02/ex2/input
Normal file
File diff suppressed because it is too large
Load diff
25
2020/d03/ex1/ex1.py
Executable file
25
2020/d03/ex1/ex1.py
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def solve(trees: List[str], delta: Tuple[int, int]) -> int:
|
||||
x, y = 0, 0
|
||||
sum = 0
|
||||
while True:
|
||||
x += delta[0]
|
||||
y += delta[1]
|
||||
if y >= len(trees):
|
||||
break
|
||||
sum += trees[y][x % len(trees[0])] == "#"
|
||||
return sum
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input, (3, 1)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
323
2020/d03/ex1/input
Normal file
323
2020/d03/ex1/input
Normal file
|
@ -0,0 +1,323 @@
|
|||
...............#.#.............
|
||||
##..#....................#...##
|
||||
......#..#.#.....#..#.#.##.....
|
||||
.........#...#..............#.#
|
||||
............#.......##.........
|
||||
...#.....#.....#...#.....#..#..
|
||||
..............#..##.#..#......#
|
||||
.##.....#.....#......##.#......
|
||||
.#..........###....#...##....#.
|
||||
.....#....#.#.......#......##..
|
||||
.#....#......#.......#........#
|
||||
..#.#.......#..##.....##.......
|
||||
...#.#....#.......#.......#...#
|
||||
##.##...##..#......#.#.....#..#
|
||||
.#.#.......#..#.#......#...#.#.
|
||||
#.......##.......#...#.........
|
||||
.....#......#.#.#.....#....##..
|
||||
.#.#........#....#..#..#.......
|
||||
...#....#..###.........#.....#.
|
||||
........#........#........#....
|
||||
..##..............#.....#.#..#.
|
||||
.#...##.............#.#........
|
||||
....#..#...........#.......#...
|
||||
..#....#.....................#.
|
||||
#.#..................##......##
|
||||
.#.##....#......#........#.....
|
||||
.........##.....#....#...##..#.
|
||||
#..........#..#.#.............#
|
||||
.........#...#.#.#.#..##..##...
|
||||
#...#.....#..#..#....#...#.....
|
||||
..##.....#..................#..
|
||||
#..###.....#....#.......#..#...
|
||||
...##.##..#............#......#
|
||||
........###.........###......#.
|
||||
#..##....#.........#.........#.
|
||||
....#.....................#....
|
||||
#..#..##..#..####.##..#.....##.
|
||||
..#...#.#....#....##.....#.....
|
||||
...#.#.........#.....#.#.......
|
||||
....#................#..#...##.
|
||||
....#..#..........#...#.#.##...
|
||||
........#..##............#....#
|
||||
...#......##..........#.##...#.
|
||||
.......##......................
|
||||
.......##..........#....#.#...#
|
||||
......###.##..##..#....#...#..#
|
||||
#.#...........##.....#........#
|
||||
..#...........#..###....#.#.#..
|
||||
........#...........#......##..
|
||||
.........#...##.###...###..#...
|
||||
.....#.....#..##.........##....
|
||||
...##..............#.....#...##
|
||||
.##....#.......###.....#.......
|
||||
.#...........##.............##.
|
||||
......#..#..##.##......#......#
|
||||
........###........#......#.#..
|
||||
#.#....#.....#........#......#.
|
||||
.##..#.........##...##....#....
|
||||
.....#.........#...##.....#....
|
||||
.............#........###....#.
|
||||
......#.......#.#........#.#...
|
||||
..#....#.#...#....#...#.#...##.
|
||||
#...#......##..##......#.##.###
|
||||
...##.#....#...#....#.........#
|
||||
...#..####.....##.#..#.#...##..
|
||||
##.#..#....##......#......##...
|
||||
###.........#.#..#.#.....#.....
|
||||
...#........#..##...#.#.#..#.#.
|
||||
...###..#.###.#...#............
|
||||
....................###........
|
||||
...........#...........#.......
|
||||
#..............#.#.........###.
|
||||
....................##.....#..#
|
||||
#.#.....#.......#...#..........
|
||||
.#...#......#....##...#...#....
|
||||
.....#.##..................###.
|
||||
.........#.#..#.#......#.......
|
||||
.......#.....##..#.##.#........
|
||||
..#..........#.###.....#....#..
|
||||
......#.............#.#........
|
||||
........##....#........#.......
|
||||
...#.............#....#.#......
|
||||
#........#..####.....#.....#.#.
|
||||
.##......##...#........#..#.#..
|
||||
....##....#...#...#..##...#.#..
|
||||
#.##...###..#....##.#..........
|
||||
....#.#...#.#...#..##.###...#..
|
||||
#.....##..#..#....#.#.....##...
|
||||
.#..#..........##.#.....##.....
|
||||
.#..#........#.#.#.#...........
|
||||
.#..#.....#...........#...#....
|
||||
...#......##..........##..#....
|
||||
...#..#....#.##...#..#.....###.
|
||||
#.#....#.....##................
|
||||
#..#......#.#.#.......#........
|
||||
......#....#.#....#..##....#..#
|
||||
.#.....#.#....###.##.........#.
|
||||
.###..#.....#........#.#.......
|
||||
.#...#......#..#.#......#.....#
|
||||
#...............####...#.....#.
|
||||
.......#..........##.#........#
|
||||
#........##....##.....###..##..
|
||||
#..#.....#..##.....#....#..#...
|
||||
#.....#.......##......#.#.....#
|
||||
#.##..#......##..#.............
|
||||
##...#.....#........##.........
|
||||
....#..##....#...#.......#.#...
|
||||
....#...#...##..#....#..#...#..
|
||||
..............#.#...#....###...
|
||||
...#....#..##...##..#....##....
|
||||
#.##.#..#..#......#.#.#.#...#..
|
||||
.......#..#..##........#......#
|
||||
##.#....#....##.#......##.#....
|
||||
.#...#..............#........#.
|
||||
.#.#....#.........#............
|
||||
.#..#..###.............#....#..
|
||||
#......#...#.#..##..#...#....#.
|
||||
.......................#...#.#.
|
||||
.............#..#...##.........
|
||||
..#.#..#....#....#........#....
|
||||
#......#.##..#...#.#...........
|
||||
.....#....#...........##.#..#..
|
||||
..#.#.....#..............#.#...
|
||||
#.......#.....#................
|
||||
#..............#...#....#...#..
|
||||
...#...##..#..#............#...
|
||||
......###.....................#
|
||||
.........#.......##..#....#....
|
||||
........#...#.##..#.##......#..
|
||||
....###..#.#...#...#..#.#...###
|
||||
##...#...##.#...#.#...#.#....#.
|
||||
.........#...#.....###.........
|
||||
...#........##..#.......##.....
|
||||
.#.......##.........#.....##..#
|
||||
.#..................#...#......
|
||||
.##..#..#.#.....#.###..........
|
||||
...#.....##..#.........#...#...
|
||||
.#......#.#.......#.#..........
|
||||
.........#.#...#..........#.#..
|
||||
#..........#.##..#.##....#.....
|
||||
.#.#....#.....#..##.....#...#..
|
||||
..#........##...##..#..#....#..
|
||||
#...........##....#..###....#..
|
||||
...........##.........####...#.
|
||||
..#........###...#.#.........#.
|
||||
.#...............#.##.#.#...#..
|
||||
.#.##..#.....#.#.....##..#.....
|
||||
...#...#..#.##.##...#.......##.
|
||||
..#...#...#......##.##.##...#..
|
||||
##....#...#...#...............#
|
||||
...##...........#......#..#.#..
|
||||
#.........#......#.#.##.....#..
|
||||
........#..#.........##........
|
||||
..#.#....###.....##..#...#.....
|
||||
.........#...#.......#.....##..
|
||||
##.....................#...##..
|
||||
.#.#..#......#.................
|
||||
.....###..#......#..###..#.....
|
||||
...#.....##.........#......#..#
|
||||
......##.....#...#........#.#..
|
||||
..#.#...#......#...#.##.##.....
|
||||
...#..........#...#.......#..##
|
||||
.###........#........##........
|
||||
..#.#.#..........#.#...##......
|
||||
.........#........#......###..#
|
||||
....##..#.........#...........#
|
||||
..####..#............##.......#
|
||||
.....##.#..##.........#...#.#..
|
||||
...#.........#.....#.....#.....
|
||||
.......#...#..#...##.........#.
|
||||
...#...#..#...#....#..#........
|
||||
#............##.##...#.........
|
||||
.#.#.....#.......####.....#....
|
||||
..............#......#.#.......
|
||||
..............#...........#...#
|
||||
#...#........###....#.#....#.#.
|
||||
##.#..#..#......#......#.#.#...
|
||||
.#..#.....#..#.#..#.#.......##.
|
||||
......##.#...#...#......#...#..
|
||||
#...........##....#.#..........
|
||||
....#.......###.#...#..........
|
||||
.......................#.....#.
|
||||
........#...#..#...#.#.#.#.#...
|
||||
.#.#...........#......##...#...
|
||||
.........................#.....
|
||||
.................#.##.#...##...
|
||||
...#...##.....#.....##....#.#..
|
||||
...#...#...................#...
|
||||
...#..#..#...#...#....#........
|
||||
#....#...#.....#...............
|
||||
.......#...........#...#.......
|
||||
....#....#.....##.......#......
|
||||
.......#..........##...........
|
||||
.#.#........#..##....#......#..
|
||||
.....#.......#.#.........#...#.
|
||||
.#..####.#.#...............#..#
|
||||
.....###..#..#..........#.#..##
|
||||
..#.......#...#.....##..#..#.#.
|
||||
#....#......#..................
|
||||
........#.##.#....#...........#
|
||||
....#.#....##..#.#.....##......
|
||||
...#..#.......#....#.....#.#.#.
|
||||
#...#......#.....#.#..........#
|
||||
....#....#...............#.....
|
||||
..###......................###.
|
||||
.##....#..#.......###.....#..#.
|
||||
..###............#........#.##.
|
||||
.#........#......#.....#..#....
|
||||
....#..##...#...#.###.......#.#
|
||||
.......#.##...........#.#..#...
|
||||
.....#...##....................
|
||||
....#....#...##......#.........
|
||||
..#............##....###.#...#.
|
||||
.#........#...............#....
|
||||
#..#.#.##.........#..##....##..
|
||||
#.#....#..#.##....##...#.#.....
|
||||
.....#.....##....#.#........#..
|
||||
#..#...#...#....#....#.........
|
||||
...#........#..#.#.....##......
|
||||
..#...#...#................##..
|
||||
#........#.#.##.......#.#...#..
|
||||
#......#..####.##.....#.#..#.#.
|
||||
............#..#.#....#......##
|
||||
..#.....##....#...#.#..........
|
||||
...#...#.........#...#.#.......
|
||||
.###..#.......##.##.....#.#.#..
|
||||
...#....#...............##.#...
|
||||
....##..#..#..#.#......##.....#
|
||||
#.#..............##...##...####
|
||||
.....#.##...#.#...............#
|
||||
.##.....#.........#.......#.#.#
|
||||
#.#..#.....#.......#.......#..#
|
||||
...#.#.....#.....#......#......
|
||||
.......#....#..#.#..........#..
|
||||
......#......#.##...#..........
|
||||
.....#.......###...#...#.#.....
|
||||
#..#.#.........#.....#.##....#.
|
||||
..#.#.........#..#..#..#.....#.
|
||||
.#..##..#..#....#......#.##..#.
|
||||
...##......###.....#.##.##.....
|
||||
.#.....#...#..#...#............
|
||||
##..##..#.##....#..#...........
|
||||
...#..##..#..#.............#.##
|
||||
...............##............#.
|
||||
..#.....##........##.#...#....#
|
||||
.#.#...#.#.#..#.#.....#....#...
|
||||
.#....#...............#..#.....
|
||||
....#.##..#....#......#...###..
|
||||
#................###...#.#.....
|
||||
...#...#......##..#.#....#.....
|
||||
.#....#....#.#...##............
|
||||
....#...##..#..#........#.##...
|
||||
..##.....#..#..##..............
|
||||
..#..##..#.#..##....#....#....#
|
||||
...##.............#............
|
||||
#....#....#.#........#.....##.#
|
||||
.....#..#.#.....####...###.....
|
||||
................#......#.......
|
||||
.....#.#.#.#.#....#..#........#
|
||||
.##.#...#.#.......##....#....#.
|
||||
.....#........#................
|
||||
..#.....#..#...#..#...........#
|
||||
.#.....#...##.....##..#.#....##
|
||||
......#.......#..#......##.#...
|
||||
#.#..........#.##.#........#...
|
||||
...#..#.............#..........
|
||||
#..#..#..........#..##.#.......
|
||||
.#..#...............####..#....
|
||||
.......#.....#......#.....#.#..
|
||||
.#...............#...#.........
|
||||
.#..#..........#..#.#..##..#..#
|
||||
......##..#.....#..#......###..
|
||||
..........#...#..#.......#.....
|
||||
.#.#.#..#.....#.##.#...#..#....
|
||||
........#.......#.....#.#......
|
||||
......#.....##.....#....##.#...
|
||||
...............#......#.......#
|
||||
..#.#...#.....#.#...##......#..
|
||||
#.#.........#.#...#........####
|
||||
#..........##..#..#........##..
|
||||
.............#..#.......##.#..#
|
||||
..#........#.#....#........#.#.
|
||||
.#......####..#..#.............
|
||||
............###.......#.#..#...
|
||||
#.##......##...#...#.........#.
|
||||
....##.#.#.#......#....#..#...#
|
||||
.#..#.#....#...#.........#.....
|
||||
#...#.....##............#...#..
|
||||
#.#...#..#.................#...
|
||||
............#.#..#.....#.#.#..#
|
||||
...................#....#.##...
|
||||
.....#...#.#....#....#.#......#
|
||||
.......##.#.#......##..........
|
||||
.#..#...##.#...#..#......#.....
|
||||
......#.#..#..###..##..##......
|
||||
.#.#.#.#.....#...###.....#..#..
|
||||
.#....#.....#.......#.......#..
|
||||
..........##.........####......
|
||||
.#.#.............#..#.#...#....
|
||||
........#........##...#.#....#.
|
||||
........#......................
|
||||
..#.#....#...............#...##
|
||||
.......#.#...#..#.....##......#
|
||||
.#...#....#..........##........
|
||||
.#.........#.#............##...
|
||||
.....#......##...#.......#..#..
|
||||
#.#..#.............#...#...#...
|
||||
......#.......#............#...
|
||||
...........##....#......##.....
|
||||
.#.#..#.....................#..
|
||||
##..##.....###..##.#...........
|
||||
...##......##....#...##.....#..
|
||||
#...#.##.............#.........
|
||||
......#..#.........###.#......#
|
||||
#.#.....#.....................#
|
||||
....#####.....##........#.#..#.
|
||||
...........##..##.###..........
|
||||
..........##.....#........#...#
|
||||
.......#..#......#.....##..##.#
|
||||
.....##.#........#.........#...
|
||||
......##......................#
|
||||
.#.......#.#.#............#..#.
|
||||
.....##.#.......#.#........#...
|
33
2020/d03/ex2/ex2.py
Executable file
33
2020/d03/ex2/ex2.py
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from math import prod
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def solve(trees: List[str], delta: Tuple[int, int]) -> int:
|
||||
x, y = 0, 0
|
||||
sum = 0
|
||||
while True:
|
||||
x += delta[0]
|
||||
y += delta[1]
|
||||
if y >= len(trees):
|
||||
break
|
||||
sum += trees[y][x % len(trees[0])] == "#"
|
||||
return sum
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
deltas = [
|
||||
(1, 1),
|
||||
(3, 1),
|
||||
(5, 1),
|
||||
(7, 1),
|
||||
(1, 2),
|
||||
]
|
||||
print(prod(solve(input, delt) for delt in deltas))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
323
2020/d03/ex2/input
Normal file
323
2020/d03/ex2/input
Normal file
|
@ -0,0 +1,323 @@
|
|||
...............#.#.............
|
||||
##..#....................#...##
|
||||
......#..#.#.....#..#.#.##.....
|
||||
.........#...#..............#.#
|
||||
............#.......##.........
|
||||
...#.....#.....#...#.....#..#..
|
||||
..............#..##.#..#......#
|
||||
.##.....#.....#......##.#......
|
||||
.#..........###....#...##....#.
|
||||
.....#....#.#.......#......##..
|
||||
.#....#......#.......#........#
|
||||
..#.#.......#..##.....##.......
|
||||
...#.#....#.......#.......#...#
|
||||
##.##...##..#......#.#.....#..#
|
||||
.#.#.......#..#.#......#...#.#.
|
||||
#.......##.......#...#.........
|
||||
.....#......#.#.#.....#....##..
|
||||
.#.#........#....#..#..#.......
|
||||
...#....#..###.........#.....#.
|
||||
........#........#........#....
|
||||
..##..............#.....#.#..#.
|
||||
.#...##.............#.#........
|
||||
....#..#...........#.......#...
|
||||
..#....#.....................#.
|
||||
#.#..................##......##
|
||||
.#.##....#......#........#.....
|
||||
.........##.....#....#...##..#.
|
||||
#..........#..#.#.............#
|
||||
.........#...#.#.#.#..##..##...
|
||||
#...#.....#..#..#....#...#.....
|
||||
..##.....#..................#..
|
||||
#..###.....#....#.......#..#...
|
||||
...##.##..#............#......#
|
||||
........###.........###......#.
|
||||
#..##....#.........#.........#.
|
||||
....#.....................#....
|
||||
#..#..##..#..####.##..#.....##.
|
||||
..#...#.#....#....##.....#.....
|
||||
...#.#.........#.....#.#.......
|
||||
....#................#..#...##.
|
||||
....#..#..........#...#.#.##...
|
||||
........#..##............#....#
|
||||
...#......##..........#.##...#.
|
||||
.......##......................
|
||||
.......##..........#....#.#...#
|
||||
......###.##..##..#....#...#..#
|
||||
#.#...........##.....#........#
|
||||
..#...........#..###....#.#.#..
|
||||
........#...........#......##..
|
||||
.........#...##.###...###..#...
|
||||
.....#.....#..##.........##....
|
||||
...##..............#.....#...##
|
||||
.##....#.......###.....#.......
|
||||
.#...........##.............##.
|
||||
......#..#..##.##......#......#
|
||||
........###........#......#.#..
|
||||
#.#....#.....#........#......#.
|
||||
.##..#.........##...##....#....
|
||||
.....#.........#...##.....#....
|
||||
.............#........###....#.
|
||||
......#.......#.#........#.#...
|
||||
..#....#.#...#....#...#.#...##.
|
||||
#...#......##..##......#.##.###
|
||||
...##.#....#...#....#.........#
|
||||
...#..####.....##.#..#.#...##..
|
||||
##.#..#....##......#......##...
|
||||
###.........#.#..#.#.....#.....
|
||||
...#........#..##...#.#.#..#.#.
|
||||
...###..#.###.#...#............
|
||||
....................###........
|
||||
...........#...........#.......
|
||||
#..............#.#.........###.
|
||||
....................##.....#..#
|
||||
#.#.....#.......#...#..........
|
||||
.#...#......#....##...#...#....
|
||||
.....#.##..................###.
|
||||
.........#.#..#.#......#.......
|
||||
.......#.....##..#.##.#........
|
||||
..#..........#.###.....#....#..
|
||||
......#.............#.#........
|
||||
........##....#........#.......
|
||||
...#.............#....#.#......
|
||||
#........#..####.....#.....#.#.
|
||||
.##......##...#........#..#.#..
|
||||
....##....#...#...#..##...#.#..
|
||||
#.##...###..#....##.#..........
|
||||
....#.#...#.#...#..##.###...#..
|
||||
#.....##..#..#....#.#.....##...
|
||||
.#..#..........##.#.....##.....
|
||||
.#..#........#.#.#.#...........
|
||||
.#..#.....#...........#...#....
|
||||
...#......##..........##..#....
|
||||
...#..#....#.##...#..#.....###.
|
||||
#.#....#.....##................
|
||||
#..#......#.#.#.......#........
|
||||
......#....#.#....#..##....#..#
|
||||
.#.....#.#....###.##.........#.
|
||||
.###..#.....#........#.#.......
|
||||
.#...#......#..#.#......#.....#
|
||||
#...............####...#.....#.
|
||||
.......#..........##.#........#
|
||||
#........##....##.....###..##..
|
||||
#..#.....#..##.....#....#..#...
|
||||
#.....#.......##......#.#.....#
|
||||
#.##..#......##..#.............
|
||||
##...#.....#........##.........
|
||||
....#..##....#...#.......#.#...
|
||||
....#...#...##..#....#..#...#..
|
||||
..............#.#...#....###...
|
||||
...#....#..##...##..#....##....
|
||||
#.##.#..#..#......#.#.#.#...#..
|
||||
.......#..#..##........#......#
|
||||
##.#....#....##.#......##.#....
|
||||
.#...#..............#........#.
|
||||
.#.#....#.........#............
|
||||
.#..#..###.............#....#..
|
||||
#......#...#.#..##..#...#....#.
|
||||
.......................#...#.#.
|
||||
.............#..#...##.........
|
||||
..#.#..#....#....#........#....
|
||||
#......#.##..#...#.#...........
|
||||
.....#....#...........##.#..#..
|
||||
..#.#.....#..............#.#...
|
||||
#.......#.....#................
|
||||
#..............#...#....#...#..
|
||||
...#...##..#..#............#...
|
||||
......###.....................#
|
||||
.........#.......##..#....#....
|
||||
........#...#.##..#.##......#..
|
||||
....###..#.#...#...#..#.#...###
|
||||
##...#...##.#...#.#...#.#....#.
|
||||
.........#...#.....###.........
|
||||
...#........##..#.......##.....
|
||||
.#.......##.........#.....##..#
|
||||
.#..................#...#......
|
||||
.##..#..#.#.....#.###..........
|
||||
...#.....##..#.........#...#...
|
||||
.#......#.#.......#.#..........
|
||||
.........#.#...#..........#.#..
|
||||
#..........#.##..#.##....#.....
|
||||
.#.#....#.....#..##.....#...#..
|
||||
..#........##...##..#..#....#..
|
||||
#...........##....#..###....#..
|
||||
...........##.........####...#.
|
||||
..#........###...#.#.........#.
|
||||
.#...............#.##.#.#...#..
|
||||
.#.##..#.....#.#.....##..#.....
|
||||
...#...#..#.##.##...#.......##.
|
||||
..#...#...#......##.##.##...#..
|
||||
##....#...#...#...............#
|
||||
...##...........#......#..#.#..
|
||||
#.........#......#.#.##.....#..
|
||||
........#..#.........##........
|
||||
..#.#....###.....##..#...#.....
|
||||
.........#...#.......#.....##..
|
||||
##.....................#...##..
|
||||
.#.#..#......#.................
|
||||
.....###..#......#..###..#.....
|
||||
...#.....##.........#......#..#
|
||||
......##.....#...#........#.#..
|
||||
..#.#...#......#...#.##.##.....
|
||||
...#..........#...#.......#..##
|
||||
.###........#........##........
|
||||
..#.#.#..........#.#...##......
|
||||
.........#........#......###..#
|
||||
....##..#.........#...........#
|
||||
..####..#............##.......#
|
||||
.....##.#..##.........#...#.#..
|
||||
...#.........#.....#.....#.....
|
||||
.......#...#..#...##.........#.
|
||||
...#...#..#...#....#..#........
|
||||
#............##.##...#.........
|
||||
.#.#.....#.......####.....#....
|
||||
..............#......#.#.......
|
||||
..............#...........#...#
|
||||
#...#........###....#.#....#.#.
|
||||
##.#..#..#......#......#.#.#...
|
||||
.#..#.....#..#.#..#.#.......##.
|
||||
......##.#...#...#......#...#..
|
||||
#...........##....#.#..........
|
||||
....#.......###.#...#..........
|
||||
.......................#.....#.
|
||||
........#...#..#...#.#.#.#.#...
|
||||
.#.#...........#......##...#...
|
||||
.........................#.....
|
||||
.................#.##.#...##...
|
||||
...#...##.....#.....##....#.#..
|
||||
...#...#...................#...
|
||||
...#..#..#...#...#....#........
|
||||
#....#...#.....#...............
|
||||
.......#...........#...#.......
|
||||
....#....#.....##.......#......
|
||||
.......#..........##...........
|
||||
.#.#........#..##....#......#..
|
||||
.....#.......#.#.........#...#.
|
||||
.#..####.#.#...............#..#
|
||||
.....###..#..#..........#.#..##
|
||||
..#.......#...#.....##..#..#.#.
|
||||
#....#......#..................
|
||||
........#.##.#....#...........#
|
||||
....#.#....##..#.#.....##......
|
||||
...#..#.......#....#.....#.#.#.
|
||||
#...#......#.....#.#..........#
|
||||
....#....#...............#.....
|
||||
..###......................###.
|
||||
.##....#..#.......###.....#..#.
|
||||
..###............#........#.##.
|
||||
.#........#......#.....#..#....
|
||||
....#..##...#...#.###.......#.#
|
||||
.......#.##...........#.#..#...
|
||||
.....#...##....................
|
||||
....#....#...##......#.........
|
||||
..#............##....###.#...#.
|
||||
.#........#...............#....
|
||||
#..#.#.##.........#..##....##..
|
||||
#.#....#..#.##....##...#.#.....
|
||||
.....#.....##....#.#........#..
|
||||
#..#...#...#....#....#.........
|
||||
...#........#..#.#.....##......
|
||||
..#...#...#................##..
|
||||
#........#.#.##.......#.#...#..
|
||||
#......#..####.##.....#.#..#.#.
|
||||
............#..#.#....#......##
|
||||
..#.....##....#...#.#..........
|
||||
...#...#.........#...#.#.......
|
||||
.###..#.......##.##.....#.#.#..
|
||||
...#....#...............##.#...
|
||||
....##..#..#..#.#......##.....#
|
||||
#.#..............##...##...####
|
||||
.....#.##...#.#...............#
|
||||
.##.....#.........#.......#.#.#
|
||||
#.#..#.....#.......#.......#..#
|
||||
...#.#.....#.....#......#......
|
||||
.......#....#..#.#..........#..
|
||||
......#......#.##...#..........
|
||||
.....#.......###...#...#.#.....
|
||||
#..#.#.........#.....#.##....#.
|
||||
..#.#.........#..#..#..#.....#.
|
||||
.#..##..#..#....#......#.##..#.
|
||||
...##......###.....#.##.##.....
|
||||
.#.....#...#..#...#............
|
||||
##..##..#.##....#..#...........
|
||||
...#..##..#..#.............#.##
|
||||
...............##............#.
|
||||
..#.....##........##.#...#....#
|
||||
.#.#...#.#.#..#.#.....#....#...
|
||||
.#....#...............#..#.....
|
||||
....#.##..#....#......#...###..
|
||||
#................###...#.#.....
|
||||
...#...#......##..#.#....#.....
|
||||
.#....#....#.#...##............
|
||||
....#...##..#..#........#.##...
|
||||
..##.....#..#..##..............
|
||||
..#..##..#.#..##....#....#....#
|
||||
...##.............#............
|
||||
#....#....#.#........#.....##.#
|
||||
.....#..#.#.....####...###.....
|
||||
................#......#.......
|
||||
.....#.#.#.#.#....#..#........#
|
||||
.##.#...#.#.......##....#....#.
|
||||
.....#........#................
|
||||
..#.....#..#...#..#...........#
|
||||
.#.....#...##.....##..#.#....##
|
||||
......#.......#..#......##.#...
|
||||
#.#..........#.##.#........#...
|
||||
...#..#.............#..........
|
||||
#..#..#..........#..##.#.......
|
||||
.#..#...............####..#....
|
||||
.......#.....#......#.....#.#..
|
||||
.#...............#...#.........
|
||||
.#..#..........#..#.#..##..#..#
|
||||
......##..#.....#..#......###..
|
||||
..........#...#..#.......#.....
|
||||
.#.#.#..#.....#.##.#...#..#....
|
||||
........#.......#.....#.#......
|
||||
......#.....##.....#....##.#...
|
||||
...............#......#.......#
|
||||
..#.#...#.....#.#...##......#..
|
||||
#.#.........#.#...#........####
|
||||
#..........##..#..#........##..
|
||||
.............#..#.......##.#..#
|
||||
..#........#.#....#........#.#.
|
||||
.#......####..#..#.............
|
||||
............###.......#.#..#...
|
||||
#.##......##...#...#.........#.
|
||||
....##.#.#.#......#....#..#...#
|
||||
.#..#.#....#...#.........#.....
|
||||
#...#.....##............#...#..
|
||||
#.#...#..#.................#...
|
||||
............#.#..#.....#.#.#..#
|
||||
...................#....#.##...
|
||||
.....#...#.#....#....#.#......#
|
||||
.......##.#.#......##..........
|
||||
.#..#...##.#...#..#......#.....
|
||||
......#.#..#..###..##..##......
|
||||
.#.#.#.#.....#...###.....#..#..
|
||||
.#....#.....#.......#.......#..
|
||||
..........##.........####......
|
||||
.#.#.............#..#.#...#....
|
||||
........#........##...#.#....#.
|
||||
........#......................
|
||||
..#.#....#...............#...##
|
||||
.......#.#...#..#.....##......#
|
||||
.#...#....#..........##........
|
||||
.#.........#.#............##...
|
||||
.....#......##...#.......#..#..
|
||||
#.#..#.............#...#...#...
|
||||
......#.......#............#...
|
||||
...........##....#......##.....
|
||||
.#.#..#.....................#..
|
||||
##..##.....###..##.#...........
|
||||
...##......##....#...##.....#..
|
||||
#...#.##.............#.........
|
||||
......#..#.........###.#......#
|
||||
#.#.....#.....................#
|
||||
....#####.....##........#.#..#.
|
||||
...........##..##.###..........
|
||||
..........##.....#........#...#
|
||||
.......#..#......#.....##..##.#
|
||||
.....##.#........#.........#...
|
||||
......##......................#
|
||||
.#.......#.#.#............#..#.
|
||||
.....##.#.......#.#........#...
|
38
2020/d04/ex1/ex1.py
Executable file
38
2020/d04/ex1/ex1.py
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def validate(passport: List[str]) -> int:
|
||||
fields = [
|
||||
"byr",
|
||||
"iyr",
|
||||
"eyr",
|
||||
"hgt",
|
||||
"hcl",
|
||||
"ecl",
|
||||
"pid",
|
||||
]
|
||||
for field in fields:
|
||||
if field not in passport:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def solve(passport_fields: List[List[str]]) -> int:
|
||||
return sum(validate(passport) for passport in passport_fields)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
passports: List[List[str]] = [[]]
|
||||
for line in sys.stdin:
|
||||
if line == "\n" or line == "":
|
||||
passports.append([])
|
||||
continue
|
||||
passports[-1] += [s.split(":")[0] for s in line.split(" ")]
|
||||
print(solve(passports))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1069
2020/d04/ex1/input
Normal file
1069
2020/d04/ex1/input
Normal file
File diff suppressed because it is too large
Load diff
109
2020/d04/ex2/ex2.py
Executable file
109
2020/d04/ex2/ex2.py
Executable file
|
@ -0,0 +1,109 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
from typing import List, Tuple
|
||||
|
||||
Field = Tuple[str, ...]
|
||||
|
||||
|
||||
def validate_byr(field: str) -> bool:
|
||||
pattern = "^[0-9]{4}$"
|
||||
if not re.fullmatch(pattern, field):
|
||||
return False
|
||||
val = int(field)
|
||||
return 1920 <= val <= 2002
|
||||
|
||||
|
||||
def validate_iyr(field: str) -> bool:
|
||||
pattern = "^[0-9]{4}$"
|
||||
if not re.fullmatch(pattern, field):
|
||||
return False
|
||||
val = int(field)
|
||||
return 2010 <= val <= 2020
|
||||
|
||||
|
||||
def validate_eyr(field: str) -> bool:
|
||||
pattern = "^[0-9]{4}$"
|
||||
if not re.fullmatch(pattern, field):
|
||||
return False
|
||||
val = int(field)
|
||||
return 2020 <= val <= 2030
|
||||
|
||||
|
||||
def validate_hgt(field: str) -> bool:
|
||||
pattern = "^[0-9]+(cm|in)$"
|
||||
if not re.fullmatch(pattern, field):
|
||||
return False
|
||||
val = int(field[:-2])
|
||||
if "cm" in field:
|
||||
return 150 <= val <= 193
|
||||
return 59 <= val <= 76
|
||||
|
||||
|
||||
def validate_hcl(field: str) -> bool:
|
||||
pattern = "^#[a-f0-9]{6}$"
|
||||
if not re.fullmatch(pattern, field):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def validate_ecl(field: str) -> bool:
|
||||
return field in {
|
||||
"amb",
|
||||
"blu",
|
||||
"brn",
|
||||
"gry",
|
||||
"grn",
|
||||
"hzl",
|
||||
"oth",
|
||||
}
|
||||
|
||||
|
||||
def validate_pid(field: str) -> bool:
|
||||
pattern = "^[0-9]{9}$"
|
||||
if not re.fullmatch(pattern, field):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def validate(passport: List[Field]) -> int:
|
||||
fields = {
|
||||
"byr": validate_byr,
|
||||
"iyr": validate_iyr,
|
||||
"eyr": validate_eyr,
|
||||
"hgt": validate_hgt,
|
||||
"hcl": validate_hcl,
|
||||
"ecl": validate_ecl,
|
||||
"pid": validate_pid,
|
||||
}
|
||||
tot = 0
|
||||
for field in passport:
|
||||
if len(field) != 2:
|
||||
continue
|
||||
if field[0] not in fields:
|
||||
if field[0] == "cid":
|
||||
continue
|
||||
return False
|
||||
if not fields[field[0]](field[1].strip()):
|
||||
return False
|
||||
tot += 1
|
||||
return tot == len(fields)
|
||||
|
||||
|
||||
def solve(passport_fields: List[List[Field]]) -> int:
|
||||
return sum(validate(passport) for passport in passport_fields)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
passports: List[List[Field]] = [[]]
|
||||
for line in sys.stdin:
|
||||
if line == "\n" or line == "":
|
||||
passports.append([])
|
||||
continue
|
||||
passports[-1] += [tuple(s.split(":")) for s in line.split(" ") if s]
|
||||
print(solve(passports))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1069
2020/d04/ex2/input
Normal file
1069
2020/d04/ex2/input
Normal file
File diff suppressed because it is too large
Load diff
35
2020/d05/ex1/ex1.py
Executable file
35
2020/d05/ex1/ex1.py
Executable file
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def seat_id(boarding_pass: str) -> int:
|
||||
min_x = 0
|
||||
max_x = 128
|
||||
min_y = 0
|
||||
max_y = 8
|
||||
|
||||
for char in boarding_pass:
|
||||
if char == "F":
|
||||
max_x = (min_x + max_x) // 2
|
||||
elif char == "B":
|
||||
min_x = (min_x + max_x) // 2
|
||||
elif char == "L":
|
||||
max_y = (min_y + max_y) // 2
|
||||
elif char == "R":
|
||||
min_y = (min_y + max_y) // 2
|
||||
return min_x * 8 + min_y
|
||||
|
||||
|
||||
def solve(passes: List[str]) -> int:
|
||||
return max(seat_id(p) for p in passes)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
781
2020/d05/ex1/input
Normal file
781
2020/d05/ex1/input
Normal file
|
@ -0,0 +1,781 @@
|
|||
FBFFBFFRLL
|
||||
BFFFFBBRLR
|
||||
FFFBBBBRLR
|
||||
FBFFFBFLRL
|
||||
FFBFBFFRRL
|
||||
FFBBBBFRRR
|
||||
FBFFBFBLRR
|
||||
FFBBFBFRRL
|
||||
FFFFBBFRRL
|
||||
BFBBBBBLLL
|
||||
FFBFBFBLLL
|
||||
FFBFFFBLLL
|
||||
FBBBFBFRLL
|
||||
BBFFFBFRRR
|
||||
FFFBFBBLLR
|
||||
FBFBFBFRRR
|
||||
BBFFBFBRLL
|
||||
FBFBBBBLRL
|
||||
FBFFFFFLLL
|
||||
BFFFFFFRLL
|
||||
BFFFBFBLRL
|
||||
BFBBBFBRRL
|
||||
BFFFBFFRRL
|
||||
FBFFFFFRRR
|
||||
FFBBBBBLLR
|
||||
BFBBFFBLRL
|
||||
FBBFBBBRLR
|
||||
BFBFBFFRLL
|
||||
BFBFBFBRLL
|
||||
BFFBFBFLLL
|
||||
FFBBFFBLRL
|
||||
FBBFFBFLRR
|
||||
FBBBFBBRRR
|
||||
BFBFFBFRLR
|
||||
BFBBBFBLLL
|
||||
FFBFBBBLRR
|
||||
BFBFFBFLLL
|
||||
FBFBFBBLLL
|
||||
BFBBBFBLRL
|
||||
FBFBFBFLRL
|
||||
FFBFFBFRRL
|
||||
FBBFFBFLLL
|
||||
BFBBBBBLRL
|
||||
FBBBBBFRLR
|
||||
BFFFBBFRLL
|
||||
FBBBBFFLLR
|
||||
FBBBBBFRLL
|
||||
BFBBBFFRLR
|
||||
BFBBBFBRLL
|
||||
BFFFBFFLLL
|
||||
FFFBFBFLRL
|
||||
BFFBBFFLRL
|
||||
BBFFFBFRLL
|
||||
BFBBFFBRLR
|
||||
BFBFBFBRRL
|
||||
BBFFFBFRRL
|
||||
FBBFBBBLRR
|
||||
FFBFBBBLLL
|
||||
BFFFBFBRLR
|
||||
FFBBFBBLLL
|
||||
FBFBBFBLLL
|
||||
BFBBFBFLLR
|
||||
FFBFBBBRRL
|
||||
FFBFFFFLRL
|
||||
FFFBBFFLRR
|
||||
FBBBBBFRRR
|
||||
FFFFBBBRLL
|
||||
BFBFBBBRRR
|
||||
BBFFBFBRRL
|
||||
FBFBBFFRLR
|
||||
FBBFFBFRRR
|
||||
BBFFBFBRRR
|
||||
FBFBBFBLRR
|
||||
FBBFFBBLRR
|
||||
FBBBBFFRLL
|
||||
BFBFFFBRLR
|
||||
FBFBBFBRRL
|
||||
FFBFBBFRRR
|
||||
FBFBFFFRLL
|
||||
BFBBFFBLLR
|
||||
FBFFFFBRLR
|
||||
BFBBBFFRLL
|
||||
FFBBFFBRLR
|
||||
FFFBBFBRLL
|
||||
FBBBBBBLRR
|
||||
FBFFBBBLRR
|
||||
BFFFFBFLRL
|
||||
BBFFFFFLRR
|
||||
BFFBFFBLLR
|
||||
FFBBBFFRLL
|
||||
BFBFBFBRLR
|
||||
FBBFBFBLRR
|
||||
FBFBBBFRLR
|
||||
FBFFBBBRRR
|
||||
FBBFFBFRLL
|
||||
FBBBFFFRLR
|
||||
BFBBBBFLLR
|
||||
BFFFBFFLLR
|
||||
FFBFFFBRRR
|
||||
FBFFFBFLLR
|
||||
FFFFBBBLLR
|
||||
BFBFFFBRLL
|
||||
BFFBBFBLRL
|
||||
BFFBFBFLLR
|
||||
FFBFFBFRLR
|
||||
BFBFFFBRRL
|
||||
FFBBFBFLLL
|
||||
BFBBBBBRLR
|
||||
BFBFBFBLRR
|
||||
FBFFBFBLLR
|
||||
FBFBFBBRRL
|
||||
BFBFBBBLLL
|
||||
FFBBFBBLRL
|
||||
FBFFFBFRRL
|
||||
BFBBFFFLRR
|
||||
BFBFBBFRRR
|
||||
FBFFFFBLRL
|
||||
BBFFBBFRRR
|
||||
FFBFFBBRLR
|
||||
FBBFBFBLRL
|
||||
BFBFFFBRRR
|
||||
FFFBBBFLRL
|
||||
BFFBFFBRLL
|
||||
FBFBFFBLRR
|
||||
FFBFBBFLLL
|
||||
FFBBBFFLRL
|
||||
FFBBFFFRLR
|
||||
BBFFBFBLRL
|
||||
FFFFBBFRLR
|
||||
FFFBFFBLRR
|
||||
BFFBBBFLLR
|
||||
BFFFBBBRRL
|
||||
FBBFBFBRLL
|
||||
BFFBFFFRRR
|
||||
BBFFFFFLRL
|
||||
BBFFFBBRLL
|
||||
BFFFBBBRRR
|
||||
BFFFBBBLRL
|
||||
BBFFBFFRRR
|
||||
BFFBFFBLRL
|
||||
FBBBBFBRLR
|
||||
FFFBFBFRRL
|
||||
BFFBBBBRRL
|
||||
FBBBBBFLRR
|
||||
FBFBBBBLLR
|
||||
FBBBBFBLRR
|
||||
FFFBFFBRLL
|
||||
FFBBBBFLLR
|
||||
FFBBBBBRRL
|
||||
FBBFFFFLLL
|
||||
FBFFBBBRLL
|
||||
FBFBFFBLLR
|
||||
FBBBBBFRRL
|
||||
BFFFBFBLLL
|
||||
FFFBFFFLRL
|
||||
FFFFBBFRLL
|
||||
BFBBFFFRLR
|
||||
BFFFBBBRLR
|
||||
FFBBBFBLLR
|
||||
BFFFBFBRRR
|
||||
BFFBFBBLRL
|
||||
FFBFBFBLRR
|
||||
FBBBBFBRRR
|
||||
FFBFBFFLLR
|
||||
BBFFFFFLLR
|
||||
FBBBFBFRRR
|
||||
BBFFFFBRRL
|
||||
FBFBFBBLRL
|
||||
BFBBBFFLLR
|
||||
BBFFBBFLRL
|
||||
BFBFFBBRLR
|
||||
FBFBBBFRRL
|
||||
FBBBFFBRLL
|
||||
BBFFFFBLLR
|
||||
FFBBFBBLRR
|
||||
FBBBBBBRLR
|
||||
FFFFBBBRRL
|
||||
FBFBBBBRLR
|
||||
BBFFBFFRRL
|
||||
FBBBFFBLRL
|
||||
FFBBBFBLRR
|
||||
BFBFBBBRLL
|
||||
FBFFFBBLRL
|
||||
FBFBBBBRLL
|
||||
BBFFFBBLLL
|
||||
BFBBFFBLLL
|
||||
BFFBBBBRRR
|
||||
FBFBFFBLLL
|
||||
FBFBFBFRRL
|
||||
FBBFFFBLLL
|
||||
BBFFFBFRLR
|
||||
FBBBBFFLRR
|
||||
FBFFFBBRLL
|
||||
FFBBFBFRRR
|
||||
FBFFFFFLRR
|
||||
BFBFFBBLRR
|
||||
FFBFBFFRRR
|
||||
BFBFFBBRLL
|
||||
FBBFFFFRRL
|
||||
BFFBBFBRLL
|
||||
BFFFFFBLLR
|
||||
FBFBBFBLLR
|
||||
BFFBBFBRLR
|
||||
BFFBFBFRRR
|
||||
FFBFBBFRLL
|
||||
FFFBBBBLRR
|
||||
BFFFBFBLLR
|
||||
FBBBBFBLRL
|
||||
FBFBBFFLRL
|
||||
FFFBFFFRLL
|
||||
BFFFFBBRRL
|
||||
FBBFFFBRRR
|
||||
FBBFBFFLLR
|
||||
BFBBBBBRRR
|
||||
BFFBFBFRLL
|
||||
FFBFBBFRRL
|
||||
BFBFBFBLLR
|
||||
FFBFBBFLLR
|
||||
FFBFFFFLRR
|
||||
FBBBFBBRRL
|
||||
BFFBFBFRLR
|
||||
BFFBFFBRRL
|
||||
BFBBBFBRLR
|
||||
BBFFFFBLRL
|
||||
FBBBFFBRRL
|
||||
FBFFFBBRRL
|
||||
FBBBBBBLLL
|
||||
FFFBFFBLLL
|
||||
BFBBFBFRLL
|
||||
FBFBFFBRLR
|
||||
FFFFBBBRRR
|
||||
BBFFFBBRLR
|
||||
BFBBBBFRLR
|
||||
FBFFBBFLRR
|
||||
BFFFBFFRLR
|
||||
FFFBBBBLLR
|
||||
FBFFFFBLRR
|
||||
FBFBFBBRLL
|
||||
FBFFBBBRLR
|
||||
BFFFFFFLRR
|
||||
FBFFFFFRLL
|
||||
FFBFBFFRLL
|
||||
FFFBBFFRLR
|
||||
FBBFBFFRRL
|
||||
FBBBBBBRRR
|
||||
BFBFBBBLRL
|
||||
BBFFFFBRRR
|
||||
FFBFFBBLRL
|
||||
FBBBBBBLLR
|
||||
FFBBFFFLRL
|
||||
FBBBFBBLRR
|
||||
FFBBBBBRLR
|
||||
BFBFFFFLLR
|
||||
BFFBBBBRLL
|
||||
BFBFBFFLRL
|
||||
FBBFFFBLRL
|
||||
BFBFBBBRRL
|
||||
BFBFBFBLRL
|
||||
BFBBFBFLRR
|
||||
BFFFFBFRLR
|
||||
BFFFBFBRLL
|
||||
FBFBFBFLLL
|
||||
FBFFBFFLRL
|
||||
BFFFFFFRRL
|
||||
FBBFBFFRLR
|
||||
FFBBBFFLLR
|
||||
FBBBBFFLRL
|
||||
FBBBFBBRLR
|
||||
BFBBBFFLRL
|
||||
FBFFBBBLRL
|
||||
BFFFFBFRRL
|
||||
BFFFBFFLRR
|
||||
FFBFBBFLRL
|
||||
BFBFFFBLRL
|
||||
BFFFFFBLLL
|
||||
FBFFBFBLLL
|
||||
FBFBBBBRRL
|
||||
FBBFFBBRLR
|
||||
BFFFBBFRRL
|
||||
BFBBFBBRLR
|
||||
FFFBFBBLRR
|
||||
FFFBFBFRLR
|
||||
FBFBFBFRLR
|
||||
BFBFBBBRLR
|
||||
BFFFFBBLLL
|
||||
BFFBBFBRRR
|
||||
BFFBBBFLLL
|
||||
FFBBBFFRRL
|
||||
BFBBBFBLLR
|
||||
FBBFFBBLLR
|
||||
FBBFBBFLRL
|
||||
BFFFFFBRRR
|
||||
FBBBFBBRLL
|
||||
FBFBFFBRRR
|
||||
BFFBBBFRRR
|
||||
FBBBBBBLRL
|
||||
FFBBBFFLRR
|
||||
BFFBBBFRLL
|
||||
BBFFBBFRLL
|
||||
FBBFBBFRLR
|
||||
BFBFBFFRRR
|
||||
BFBFBBFLRL
|
||||
BFFFFBFRLL
|
||||
FFBBFBFLLR
|
||||
BFFBFBBLRR
|
||||
FBFFBBBRRL
|
||||
FBBFBBFRLL
|
||||
FBFFFBBLLR
|
||||
FFFBBBBRRR
|
||||
FFFFBBBLRL
|
||||
FFBBFFFRRL
|
||||
BFFBBFFRRL
|
||||
BFFFBBFLRL
|
||||
BFFFFBBLRR
|
||||
BBFFBBBLRR
|
||||
BFBFFFFLRR
|
||||
FBFBBBBLLL
|
||||
BBFFFBBLRR
|
||||
FFFBFBFLRR
|
||||
FBBFFFFLRL
|
||||
FFBBBBFRLL
|
||||
FBFFBFBLRL
|
||||
BFBBFBBLLL
|
||||
FBBFBBFLLL
|
||||
FFBFFBBRLL
|
||||
BFBFFFFRLR
|
||||
FBFFBBFRRR
|
||||
FFFBBFFRRR
|
||||
FFFBFFBRLR
|
||||
FBBBBBFLLL
|
||||
FBBBFFFLRL
|
||||
FFBBFFFLRR
|
||||
FFFBBBBRRL
|
||||
BFBFBBFRLL
|
||||
BFBFFBBRRL
|
||||
FBBFBBFRRL
|
||||
BFBFBBFLLR
|
||||
BBFFBBBRRR
|
||||
BFFFBBFRLR
|
||||
FFFBBBFRLR
|
||||
BFFBFFFRLL
|
||||
BFBFFFFRRL
|
||||
FFBBFFFLLL
|
||||
FBFBBBBLRR
|
||||
FBFBFFFLRR
|
||||
BBFFBFFLRR
|
||||
FBBBFBBLRL
|
||||
BFBFBFBLLL
|
||||
FBFBFFFLLR
|
||||
BFFBBFBLRR
|
||||
FBBFFFBRRL
|
||||
BFFBBFFRRR
|
||||
FBBFBBBRRL
|
||||
BFFFFBBLLR
|
||||
FFBBBBFLLL
|
||||
BFFBFFBRRR
|
||||
BFFFFBFRRR
|
||||
FFFBBBFRRR
|
||||
FBFBFFFRLR
|
||||
FBBBFBFLLR
|
||||
FFBBFFBRLL
|
||||
FBFBFFFLLL
|
||||
BFFBFBFRRL
|
||||
BFBFFBFRRL
|
||||
BFBBBBFLLL
|
||||
FBBBFBFRRL
|
||||
FFBFBFFLLL
|
||||
BFBBFFFRRL
|
||||
FFBBFFBLLR
|
||||
BFFBBBBRLR
|
||||
FFBBBBBLRR
|
||||
BFFBFFFRRL
|
||||
BFFBFBBRLL
|
||||
FBBBFBFRLR
|
||||
FBBFFFFLRR
|
||||
BFFFBBFLLR
|
||||
FFFBBFBRRL
|
||||
FFBBFFBLRR
|
||||
FBBFFFBRLR
|
||||
BFBBBBBRLL
|
||||
BBFFFFFRRL
|
||||
FFBFFBBRRL
|
||||
BFBFFBFLLR
|
||||
FBFBBBFLLL
|
||||
FBFFFFFRRL
|
||||
BFFFBFBLRR
|
||||
FBFFFFBLLR
|
||||
FBBFBFBRRR
|
||||
FBBBFFFLLR
|
||||
BBFFBFBLRR
|
||||
BBFFFBFLLL
|
||||
FBFFFBFRLR
|
||||
BFFFBFFLRL
|
||||
BBFFBFFLRL
|
||||
BFFFFFFLLR
|
||||
BBFFBBBLLL
|
||||
FFBFBBBLLR
|
||||
FBBFBBBLRL
|
||||
BFBBFBBLRR
|
||||
FFBFBFBLLR
|
||||
FFBFBFBRRL
|
||||
BFBBFBBRRL
|
||||
BFFBFFFLLR
|
||||
FFBBFFBRRL
|
||||
BBFFBBBRRL
|
||||
FFFBBFBRLR
|
||||
BFBBFBFRRR
|
||||
BFFFFFFRRR
|
||||
FBBBFFBLLL
|
||||
BFBFFFFLLL
|
||||
BBFFBFBLLR
|
||||
BFBFBBFRLR
|
||||
FFBFBBBRRR
|
||||
BFFFBBFLLL
|
||||
FBFFBBFRLL
|
||||
FFBBFBFRLL
|
||||
BFBFBBBLLR
|
||||
FBBFBFBLLL
|
||||
BBFFFFBRLL
|
||||
BBFFBFBLLL
|
||||
BFFBFFBLRR
|
||||
BFFBBFBLLL
|
||||
FFBFFFBLRR
|
||||
FBBFFBFRRL
|
||||
FBBBBFBLLL
|
||||
FFBFFBBLLR
|
||||
BFFBBBFLRR
|
||||
FBFBFFBRLL
|
||||
FFBFFFBRLL
|
||||
FFBFFBFLLL
|
||||
FBFBBFBLRL
|
||||
FBBFBFFRRR
|
||||
BFBFBFFLLR
|
||||
FBBFFFBLLR
|
||||
BFBBBBFRRR
|
||||
FBBFBBFRRR
|
||||
BBFFBFFRLR
|
||||
FBFBBBFRLL
|
||||
FBBFBBBLLR
|
||||
BFFFFFFLRL
|
||||
BFBFFBBRRR
|
||||
BFFFBFFRLL
|
||||
BFBBFBFLRL
|
||||
FFBFFFFRRR
|
||||
BFFBBFFRLR
|
||||
FBBBBBFLLR
|
||||
FBFBFFBLRL
|
||||
FFFBBFBLLR
|
||||
FBBFBFBLLR
|
||||
FFFBFFBRRR
|
||||
FBFFFFFRLR
|
||||
FBFBBFBRLR
|
||||
FBBBFBFLRR
|
||||
FBFBBBFLRL
|
||||
BFFBFFFLRL
|
||||
FFBBBFFRRR
|
||||
FFBBBBBLLL
|
||||
FBFFBBFLLR
|
||||
FFBFBFFLRR
|
||||
FFFBBBFLRR
|
||||
BFBFBBFLLL
|
||||
BBFFBFFLLR
|
||||
FFBBFBBRLL
|
||||
FBBFFBBLLL
|
||||
FBFFBFBRLL
|
||||
BFBFBFFLRR
|
||||
FBBBFFBRLR
|
||||
FFBFFBFRLL
|
||||
FFFFBBBLLL
|
||||
FFBFFBBRRR
|
||||
FBBBBFBRLL
|
||||
BFFFFBBRRR
|
||||
FFBBFFFRLL
|
||||
FFBFBFBRLL
|
||||
BBFFFFBLLL
|
||||
FFBBBFBRRL
|
||||
BFFFFBBLRL
|
||||
FBBBFBBLLR
|
||||
FBBBFBBLLL
|
||||
FFBFBFBLRL
|
||||
FBBBBFFRRR
|
||||
FBBFFFFRLR
|
||||
FFBFFFBRLR
|
||||
BFBFBFBRRR
|
||||
FFFBFBBRLL
|
||||
FBBBFFBRRR
|
||||
FBBFBFFRLL
|
||||
BFFBFBFLRR
|
||||
BFBBBFFRRL
|
||||
BFFBBFBLLR
|
||||
FFBBBFBRLL
|
||||
FBFBFBBLRR
|
||||
BFBBFFFLRL
|
||||
BFBFBBFLRR
|
||||
BFBBBFFRRR
|
||||
FBBBFFFRRL
|
||||
FBFBFBFLLR
|
||||
FBBFFFFLLR
|
||||
FFBFBBFRLR
|
||||
FFFBFBBLRL
|
||||
BBFFFBBLLR
|
||||
BFFBBBFRLR
|
||||
FFFFBBBRLR
|
||||
BBFFBBFRLR
|
||||
FBFFFFBRLL
|
||||
FBFBFFFRRR
|
||||
FBFFFBBLLL
|
||||
BFBBBBFRLL
|
||||
FBFBFFBRRL
|
||||
FFFBFFFRLR
|
||||
BFBBFBFRRL
|
||||
FBFFBFFLRR
|
||||
FBFFFBBLRR
|
||||
FFBFBBBRLR
|
||||
FBBFBFFLRR
|
||||
FBFFFBBRRR
|
||||
FFBFBBBRLL
|
||||
FFBBBBBRRR
|
||||
BFFBBFFLLL
|
||||
BFBBBBBRRL
|
||||
BBFFBBBRLL
|
||||
FBFFFFFLRL
|
||||
BFFBBFFLRR
|
||||
FBFFBBFLRL
|
||||
BFBFFBFRRR
|
||||
FBFBBFBRLL
|
||||
BFFFBFBRRL
|
||||
FBBFFBFLLR
|
||||
BFFFFFFLLL
|
||||
FBFBFBFRLL
|
||||
FBBBBFFRRL
|
||||
BFBFFBBLLR
|
||||
FBBFBFBRRL
|
||||
FFFBFFFLLR
|
||||
FFBBBBBLRL
|
||||
FFBFFBBLRR
|
||||
FFFBFBFRRR
|
||||
BFBBFBBRLL
|
||||
BFBBBFBLRR
|
||||
FFBBBBFLRR
|
||||
FBBBFFBLLR
|
||||
BBFFBBBLLR
|
||||
FBFBBFFRRL
|
||||
FBBBBBFLRL
|
||||
FFFBBFFRRL
|
||||
BFFBBBBLRR
|
||||
FFFFBBBLRR
|
||||
FFFFBBFLRR
|
||||
FBFFFBFLLL
|
||||
FBFBFBBLLR
|
||||
BFFBBBBLLL
|
||||
FFBFFFFRLR
|
||||
BFBBFFBLRR
|
||||
FFBBFBFLRL
|
||||
BFBFBFFLLL
|
||||
BFFBFBBLLR
|
||||
BFBBFBBLRL
|
||||
FFBBBBFLRL
|
||||
FBBBFFFLLL
|
||||
FFFBFFBRRL
|
||||
BFFFFBBRLL
|
||||
BFFFBBBRLL
|
||||
BFFBFFFLRR
|
||||
FFBFBFBRRR
|
||||
BBFFBBFLLR
|
||||
FFBBFBBLLR
|
||||
FFBFFBFRRR
|
||||
FFBBBFFRLR
|
||||
BFFBBBBLLR
|
||||
FFFBFFFLRR
|
||||
FBFFFFFLLR
|
||||
FBFFBBBLLL
|
||||
BBFFBBFLLL
|
||||
FFBBFBFLRR
|
||||
BFFBFBFLRL
|
||||
FBFBBBFRRR
|
||||
BFBBFBBLLR
|
||||
FBFFFFBRRL
|
||||
FFFBBFBLRR
|
||||
BBFFFFBLRR
|
||||
BFBBBBFRRL
|
||||
FFBBBFBLLL
|
||||
BFBBFBFRLR
|
||||
BFBBFFBRRL
|
||||
BFBFBFFRRL
|
||||
FBBFFBBLRL
|
||||
FFFBFFBLRL
|
||||
BFFBBFFRLL
|
||||
FBBBFFFRLL
|
||||
FBBFBBFLLR
|
||||
FFBFFFFLLR
|
||||
FBBBFBFLRL
|
||||
BFFFBBBLLR
|
||||
FBFBBBBRRR
|
||||
FBBFBFBRLR
|
||||
FFFBFBFLLR
|
||||
FFFFBBFRRR
|
||||
FFFBBFFLRL
|
||||
BFBFFBFRLL
|
||||
FFFBFFBLLR
|
||||
FBBFFFBRLL
|
||||
FFBBBFBRRR
|
||||
FFBBFBBRLR
|
||||
BBFFFFFRRR
|
||||
FFBFFFFRLL
|
||||
FBBFFBBRRL
|
||||
BBFFFBFLRR
|
||||
FBBFFFFRRR
|
||||
FFBFFFBRRL
|
||||
BFBBFBFLLL
|
||||
BFFFFBFLRR
|
||||
BBFFFFFLLL
|
||||
FFBBFBBRRL
|
||||
FFBFBFFLRL
|
||||
FBFFBBFRRL
|
||||
BBFFBFBRLR
|
||||
BBFFBBFLRR
|
||||
FBFFBFBRRR
|
||||
FBBFBBFLRR
|
||||
FBFFFBFRLL
|
||||
BFBFFFFLRL
|
||||
FFFBBFBRRR
|
||||
BFBBBBBLLR
|
||||
FBBFFBBRRR
|
||||
FFBBBFFLLL
|
||||
FBBBBFBLLR
|
||||
BBFFFFFRLL
|
||||
FFBBBBFRLR
|
||||
FBFBFBBRRR
|
||||
FBFFBFFLLL
|
||||
FBFFBBBLLR
|
||||
FBBBBFBRRL
|
||||
BFBFBFFRLR
|
||||
FBBFBBBRLL
|
||||
BFBBFFFRLL
|
||||
FBBBFBFLLL
|
||||
FFBFFFFRRL
|
||||
FBFBBFFRRR
|
||||
FBFFFFBLLL
|
||||
FBBBBBBRLL
|
||||
BFFBFBBRRR
|
||||
BBFFBBFRRL
|
||||
FBBFBFFLRL
|
||||
FBFFFFBRRR
|
||||
FBBFFFFRLL
|
||||
FFFBFFFRRR
|
||||
FBFFBBFLLL
|
||||
BFFFFBFLLL
|
||||
BFFFFBFLLR
|
||||
FFBFFBFLLR
|
||||
FFBFFBFLRR
|
||||
BFFBBBBLRL
|
||||
FFBBFFBLLL
|
||||
FBBFBBBLLL
|
||||
FBFBBBFLLR
|
||||
BFFBBBFLRL
|
||||
BFBBFFBRLL
|
||||
FBFFBFFRRR
|
||||
FFBFFFBLRL
|
||||
FFFBBBFRRL
|
||||
FFBFBBFLRR
|
||||
FFFBBBBLRL
|
||||
FFFBBFFLLL
|
||||
FFFBFBBRRR
|
||||
FBBFBFFLLL
|
||||
BFFFBBBLLL
|
||||
BFFBFFFRLR
|
||||
FFFBBBBLLL
|
||||
BFFFFFBRRL
|
||||
FFBBFFFLLR
|
||||
BFBBFFFRRR
|
||||
BFBFFBFLRR
|
||||
FFFBBBFLLR
|
||||
FBFBBBFLRR
|
||||
BBFFBBBRLR
|
||||
FBFBBFFLRR
|
||||
FFBBBFBLRL
|
||||
FFFBBBFRLL
|
||||
BFFBFFBRLR
|
||||
BBFFFBBRRR
|
||||
BFBBBBFLRL
|
||||
BFBBBFBRRR
|
||||
FBBBBFFLLL
|
||||
FFFBFBBLLL
|
||||
BBFFFFFRLR
|
||||
BBFFBFFLLL
|
||||
FFBFBBBLRL
|
||||
FFBBFBFRLR
|
||||
BFBBBBBLRR
|
||||
FFBFFFBLLR
|
||||
FFBFFBFLRL
|
||||
BFFBFBBRLR
|
||||
FBFBFFFRRL
|
||||
FBBBFFFLRR
|
||||
FFFBBFFLLR
|
||||
FBBBBFFRLR
|
||||
FFBBFBBRRR
|
||||
BFBBFBBRRR
|
||||
BFBFBBFRRL
|
||||
BFFBBBFRRL
|
||||
FFFBFFFLLL
|
||||
FBBFFBFLRL
|
||||
FFFBFBBRLR
|
||||
BFBBFFFLLR
|
||||
BFBBFFBRRR
|
||||
FBFFBFBRRL
|
||||
FFBBBBBRLL
|
||||
BFFBFFBLLL
|
||||
BFFFBBFRRR
|
||||
FBFFFBFRRR
|
||||
FFBFBFBRLR
|
||||
FBFBBFFLLR
|
||||
FBBFBBBRRR
|
||||
BFBFFFFRRR
|
||||
FFBFFFFLLL
|
||||
FBFBBFFRLL
|
||||
BFBFFBFLRL
|
||||
BFBBFFFLLL
|
||||
FBFBBFBRRR
|
||||
BFBFFFBLLR
|
||||
BFBFFFBLLL
|
||||
BBFFFBFLLR
|
||||
BBFFBFFRLL
|
||||
FFBBBBFRRL
|
||||
BBFFFBFLRL
|
||||
BBFFBBBLRL
|
||||
BFBFFFBLRR
|
||||
FFFBFBFRLL
|
||||
BFBFFBBLLL
|
||||
BBFFFBBRRL
|
||||
BFBBBFFLLL
|
||||
BFFBBFFLLR
|
||||
FFBFFBBLLL
|
||||
BFFBBFBRRL
|
||||
BFFFFFBLRL
|
||||
BBFFFFBRLR
|
||||
FBFBBFFLLL
|
||||
FFBBBFBRLR
|
||||
FFFBBFBLLL
|
||||
FBFFFBBRLR
|
||||
FFBFBFFRLR
|
||||
BFFFFFBLRR
|
||||
FFFBBBBRLL
|
||||
FFBBFFFRRR
|
||||
BFFFFFBRLR
|
||||
FBBBFFBLRR
|
||||
FBFBFBBRLR
|
||||
FBBFFFBLRR
|
||||
BFBFFBBLRL
|
||||
FBFFBFBRLR
|
||||
FBFBFFFLRL
|
||||
BFFFFFBRLL
|
||||
BFBBBBFLRR
|
||||
BFFBFFFLLL
|
||||
FBFFBFFRRL
|
||||
FFFBBFFRLL
|
||||
BFFFBFFRRR
|
||||
FBFFBFFLLR
|
||||
FFFBBBFLLL
|
||||
FBFFFBFLRR
|
||||
BFFBFBBLLL
|
||||
BFFFBBBLRR
|
||||
FBBBBBBRRL
|
||||
FBFFBFFRLR
|
||||
FBBFFBBRLL
|
||||
FBBBFFFRRR
|
||||
BFFBFBBRRL
|
||||
FFBBFFBRRR
|
||||
BFBBBFFLRR
|
||||
FFFBFBBRRL
|
||||
BFBFBBBLRR
|
||||
FFFBBFBLRL
|
||||
FBFFBBFRLR
|
||||
BFFFBBFLRR
|
||||
BBFFFBBLRL
|
||||
FBBFFBFRLR
|
||||
FFFBFBFLLL
|
||||
FFFBFFFRRL
|
||||
BBFBFFFLLL
|
||||
FBFBFBFLRR
|
||||
BFBFFFFRLL
|
41
2020/d05/ex2/ex2.py
Executable file
41
2020/d05/ex2/ex2.py
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def seat_id(boarding_pass: str) -> int:
|
||||
min_x = 0
|
||||
max_x = 128
|
||||
min_y = 0
|
||||
max_y = 8
|
||||
|
||||
for char in boarding_pass:
|
||||
if char == "F":
|
||||
max_x = (min_x + max_x) // 2
|
||||
elif char == "B":
|
||||
min_x = (min_x + max_x) // 2
|
||||
elif char == "L":
|
||||
max_y = (min_y + max_y) // 2
|
||||
elif char == "R":
|
||||
min_y = (min_y + max_y) // 2
|
||||
return min_x * 8 + min_y
|
||||
|
||||
|
||||
def solve(passes: List[str]) -> int:
|
||||
ids = sorted(seat_id(p) for p in passes)
|
||||
|
||||
for prev, cur in zip(ids, ids[1:]):
|
||||
if prev + 1 != cur:
|
||||
return prev + 1
|
||||
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
781
2020/d05/ex2/input
Normal file
781
2020/d05/ex2/input
Normal file
|
@ -0,0 +1,781 @@
|
|||
FBFFBFFRLL
|
||||
BFFFFBBRLR
|
||||
FFFBBBBRLR
|
||||
FBFFFBFLRL
|
||||
FFBFBFFRRL
|
||||
FFBBBBFRRR
|
||||
FBFFBFBLRR
|
||||
FFBBFBFRRL
|
||||
FFFFBBFRRL
|
||||
BFBBBBBLLL
|
||||
FFBFBFBLLL
|
||||
FFBFFFBLLL
|
||||
FBBBFBFRLL
|
||||
BBFFFBFRRR
|
||||
FFFBFBBLLR
|
||||
FBFBFBFRRR
|
||||
BBFFBFBRLL
|
||||
FBFBBBBLRL
|
||||
FBFFFFFLLL
|
||||
BFFFFFFRLL
|
||||
BFFFBFBLRL
|
||||
BFBBBFBRRL
|
||||
BFFFBFFRRL
|
||||
FBFFFFFRRR
|
||||
FFBBBBBLLR
|
||||
BFBBFFBLRL
|
||||
FBBFBBBRLR
|
||||
BFBFBFFRLL
|
||||
BFBFBFBRLL
|
||||
BFFBFBFLLL
|
||||
FFBBFFBLRL
|
||||
FBBFFBFLRR
|
||||
FBBBFBBRRR
|
||||
BFBFFBFRLR
|
||||
BFBBBFBLLL
|
||||
FFBFBBBLRR
|
||||
BFBFFBFLLL
|
||||
FBFBFBBLLL
|
||||
BFBBBFBLRL
|
||||
FBFBFBFLRL
|
||||
FFBFFBFRRL
|
||||
FBBFFBFLLL
|
||||
BFBBBBBLRL
|
||||
FBBBBBFRLR
|
||||
BFFFBBFRLL
|
||||
FBBBBFFLLR
|
||||
FBBBBBFRLL
|
||||
BFBBBFFRLR
|
||||
BFBBBFBRLL
|
||||
BFFFBFFLLL
|
||||
FFFBFBFLRL
|
||||
BFFBBFFLRL
|
||||
BBFFFBFRLL
|
||||
BFBBFFBRLR
|
||||
BFBFBFBRRL
|
||||
BBFFFBFRRL
|
||||
FBBFBBBLRR
|
||||
FFBFBBBLLL
|
||||
BFFFBFBRLR
|
||||
FFBBFBBLLL
|
||||
FBFBBFBLLL
|
||||
BFBBFBFLLR
|
||||
FFBFBBBRRL
|
||||
FFBFFFFLRL
|
||||
FFFBBFFLRR
|
||||
FBBBBBFRRR
|
||||
FFFFBBBRLL
|
||||
BFBFBBBRRR
|
||||
BBFFBFBRRL
|
||||
FBFBBFFRLR
|
||||
FBBFFBFRRR
|
||||
BBFFBFBRRR
|
||||
FBFBBFBLRR
|
||||
FBBFFBBLRR
|
||||
FBBBBFFRLL
|
||||
BFBFFFBRLR
|
||||
FBFBBFBRRL
|
||||
FFBFBBFRRR
|
||||
FBFBFFFRLL
|
||||
BFBBFFBLLR
|
||||
FBFFFFBRLR
|
||||
BFBBBFFRLL
|
||||
FFBBFFBRLR
|
||||
FFFBBFBRLL
|
||||
FBBBBBBLRR
|
||||
FBFFBBBLRR
|
||||
BFFFFBFLRL
|
||||
BBFFFFFLRR
|
||||
BFFBFFBLLR
|
||||
FFBBBFFRLL
|
||||
BFBFBFBRLR
|
||||
FBBFBFBLRR
|
||||
FBFBBBFRLR
|
||||
FBFFBBBRRR
|
||||
FBBFFBFRLL
|
||||
FBBBFFFRLR
|
||||
BFBBBBFLLR
|
||||
BFFFBFFLLR
|
||||
FFBFFFBRRR
|
||||
FBFFFBFLLR
|
||||
FFFFBBBLLR
|
||||
BFBFFFBRLL
|
||||
BFFBBFBLRL
|
||||
BFFBFBFLLR
|
||||
FFBFFBFRLR
|
||||
BFBFFFBRRL
|
||||
FFBBFBFLLL
|
||||
BFBBBBBRLR
|
||||
BFBFBFBLRR
|
||||
FBFFBFBLLR
|
||||
FBFBFBBRRL
|
||||
BFBFBBBLLL
|
||||
FFBBFBBLRL
|
||||
FBFFFBFRRL
|
||||
BFBBFFFLRR
|
||||
BFBFBBFRRR
|
||||
FBFFFFBLRL
|
||||
BBFFBBFRRR
|
||||
FFBFFBBRLR
|
||||
FBBFBFBLRL
|
||||
BFBFFFBRRR
|
||||
FFFBBBFLRL
|
||||
BFFBFFBRLL
|
||||
FBFBFFBLRR
|
||||
FFBFBBFLLL
|
||||
FFBBBFFLRL
|
||||
FFBBFFFRLR
|
||||
BBFFBFBLRL
|
||||
FFFFBBFRLR
|
||||
FFFBFFBLRR
|
||||
BFFBBBFLLR
|
||||
BFFFBBBRRL
|
||||
FBBFBFBRLL
|
||||
BFFBFFFRRR
|
||||
BBFFFFFLRL
|
||||
BBFFFBBRLL
|
||||
BFFFBBBRRR
|
||||
BFFFBBBLRL
|
||||
BBFFBFFRRR
|
||||
BFFBFFBLRL
|
||||
FBBBBFBRLR
|
||||
FFFBFBFRRL
|
||||
BFFBBBBRRL
|
||||
FBBBBBFLRR
|
||||
FBFBBBBLLR
|
||||
FBBBBFBLRR
|
||||
FFFBFFBRLL
|
||||
FFBBBBFLLR
|
||||
FFBBBBBRRL
|
||||
FBBFFFFLLL
|
||||
FBFFBBBRLL
|
||||
FBFBFFBLLR
|
||||
FBBBBBFRRL
|
||||
BFFFBFBLLL
|
||||
FFFBFFFLRL
|
||||
FFFFBBFRLL
|
||||
BFBBFFFRLR
|
||||
BFFFBBBRLR
|
||||
FFBBBFBLLR
|
||||
BFFFBFBRRR
|
||||
BFFBFBBLRL
|
||||
FFBFBFBLRR
|
||||
FBBBBFBRRR
|
||||
FFBFBFFLLR
|
||||
BBFFFFFLLR
|
||||
FBBBFBFRRR
|
||||
BBFFFFBRRL
|
||||
FBFBFBBLRL
|
||||
BFBBBFFLLR
|
||||
BBFFBBFLRL
|
||||
BFBFFBBRLR
|
||||
FBFBBBFRRL
|
||||
FBBBFFBRLL
|
||||
BBFFFFBLLR
|
||||
FFBBFBBLRR
|
||||
FBBBBBBRLR
|
||||
FFFFBBBRRL
|
||||
FBFBBBBRLR
|
||||
BBFFBFFRRL
|
||||
FBBBFFBLRL
|
||||
FFBBBFBLRR
|
||||
BFBFBBBRLL
|
||||
FBFFFBBLRL
|
||||
FBFBBBBRLL
|
||||
BBFFFBBLLL
|
||||
BFBBFFBLLL
|
||||
BFFBBBBRRR
|
||||
FBFBFFBLLL
|
||||
FBFBFBFRRL
|
||||
FBBFFFBLLL
|
||||
BBFFFBFRLR
|
||||
FBBBBFFLRR
|
||||
FBFFFBBRLL
|
||||
FFBBFBFRRR
|
||||
FBFFFFFLRR
|
||||
BFBFFBBLRR
|
||||
FFBFBFFRRR
|
||||
BFBFFBBRLL
|
||||
FBBFFFFRRL
|
||||
BFFBBFBRLL
|
||||
BFFFFFBLLR
|
||||
FBFBBFBLLR
|
||||
BFFBBFBRLR
|
||||
BFFBFBFRRR
|
||||
FFBFBBFRLL
|
||||
FFFBBBBLRR
|
||||
BFFFBFBLLR
|
||||
FBBBBFBLRL
|
||||
FBFBBFFLRL
|
||||
FFFBFFFRLL
|
||||
BFFFFBBRRL
|
||||
FBBFFFBRRR
|
||||
FBBFBFFLLR
|
||||
BFBBBBBRRR
|
||||
BFFBFBFRLL
|
||||
FFBFBBFRRL
|
||||
BFBFBFBLLR
|
||||
FFBFBBFLLR
|
||||
FFBFFFFLRR
|
||||
FBBBFBBRRL
|
||||
BFFBFBFRLR
|
||||
BFFBFFBRRL
|
||||
BFBBBFBRLR
|
||||
BBFFFFBLRL
|
||||
FBBBFFBRRL
|
||||
FBFFFBBRRL
|
||||
FBBBBBBLLL
|
||||
FFFBFFBLLL
|
||||
BFBBFBFRLL
|
||||
FBFBFFBRLR
|
||||
FFFFBBBRRR
|
||||
BBFFFBBRLR
|
||||
BFBBBBFRLR
|
||||
FBFFBBFLRR
|
||||
BFFFBFFRLR
|
||||
FFFBBBBLLR
|
||||
FBFFFFBLRR
|
||||
FBFBFBBRLL
|
||||
FBFFBBBRLR
|
||||
BFFFFFFLRR
|
||||
FBFFFFFRLL
|
||||
FFBFBFFRLL
|
||||
FFFBBFFRLR
|
||||
FBBFBFFRRL
|
||||
FBBBBBBRRR
|
||||
BFBFBBBLRL
|
||||
BBFFFFBRRR
|
||||
FFBFFBBLRL
|
||||
FBBBBBBLLR
|
||||
FFBBFFFLRL
|
||||
FBBBFBBLRR
|
||||
FFBBBBBRLR
|
||||
BFBFFFFLLR
|
||||
BFFBBBBRLL
|
||||
BFBFBFFLRL
|
||||
FBBFFFBLRL
|
||||
BFBFBBBRRL
|
||||
BFBFBFBLRL
|
||||
BFBBFBFLRR
|
||||
BFFFFBFRLR
|
||||
BFFFBFBRLL
|
||||
FBFBFBFLLL
|
||||
FBFFBFFLRL
|
||||
BFFFFFFRRL
|
||||
FBBFBFFRLR
|
||||
FFBBBFFLLR
|
||||
FBBBBFFLRL
|
||||
FBBBFBBRLR
|
||||
BFBBBFFLRL
|
||||
FBFFBBBLRL
|
||||
BFFFFBFRRL
|
||||
BFFFBFFLRR
|
||||
FFBFBBFLRL
|
||||
BFBFFFBLRL
|
||||
BFFFFFBLLL
|
||||
FBFFBFBLLL
|
||||
FBFBBBBRRL
|
||||
FBBFFBBRLR
|
||||
BFFFBBFRRL
|
||||
BFBBFBBRLR
|
||||
FFFBFBBLRR
|
||||
FFFBFBFRLR
|
||||
FBFBFBFRLR
|
||||
BFBFBBBRLR
|
||||
BFFFFBBLLL
|
||||
BFFBBFBRRR
|
||||
BFFBBBFLLL
|
||||
FFBBBFFRRL
|
||||
BFBBBFBLLR
|
||||
FBBFFBBLLR
|
||||
FBBFBBFLRL
|
||||
BFFFFFBRRR
|
||||
FBBBFBBRLL
|
||||
FBFBFFBRRR
|
||||
BFFBBBFRRR
|
||||
FBBBBBBLRL
|
||||
FFBBBFFLRR
|
||||
BFFBBBFRLL
|
||||
BBFFBBFRLL
|
||||
FBBFBBFRLR
|
||||
BFBFBFFRRR
|
||||
BFBFBBFLRL
|
||||
BFFFFBFRLL
|
||||
FFBBFBFLLR
|
||||
BFFBFBBLRR
|
||||
FBFFBBBRRL
|
||||
FBBFBBFRLL
|
||||
FBFFFBBLLR
|
||||
FFFBBBBRRR
|
||||
FFFFBBBLRL
|
||||
FFBBFFFRRL
|
||||
BFFBBFFRRL
|
||||
BFFFBBFLRL
|
||||
BFFFFBBLRR
|
||||
BBFFBBBLRR
|
||||
BFBFFFFLRR
|
||||
FBFBBBBLLL
|
||||
BBFFFBBLRR
|
||||
FFFBFBFLRR
|
||||
FBBFFFFLRL
|
||||
FFBBBBFRLL
|
||||
FBFFBFBLRL
|
||||
BFBBFBBLLL
|
||||
FBBFBBFLLL
|
||||
FFBFFBBRLL
|
||||
BFBFFFFRLR
|
||||
FBFFBBFRRR
|
||||
FFFBBFFRRR
|
||||
FFFBFFBRLR
|
||||
FBBBBBFLLL
|
||||
FBBBFFFLRL
|
||||
FFBBFFFLRR
|
||||
FFFBBBBRRL
|
||||
BFBFBBFRLL
|
||||
BFBFFBBRRL
|
||||
FBBFBBFRRL
|
||||
BFBFBBFLLR
|
||||
BBFFBBBRRR
|
||||
BFFFBBFRLR
|
||||
FFFBBBFRLR
|
||||
BFFBFFFRLL
|
||||
BFBFFFFRRL
|
||||
FFBBFFFLLL
|
||||
FBFBBBBLRR
|
||||
FBFBFFFLRR
|
||||
BBFFBFFLRR
|
||||
FBBBFBBLRL
|
||||
BFBFBFBLLL
|
||||
FBFBFFFLLR
|
||||
BFFBBFBLRR
|
||||
FBBFFFBRRL
|
||||
BFFBBFFRRR
|
||||
FBBFBBBRRL
|
||||
BFFFFBBLLR
|
||||
FFBBBBFLLL
|
||||
BFFBFFBRRR
|
||||
BFFFFBFRRR
|
||||
FFFBBBFRRR
|
||||
FBFBFFFRLR
|
||||
FBBBFBFLLR
|
||||
FFBBFFBRLL
|
||||
FBFBFFFLLL
|
||||
BFFBFBFRRL
|
||||
BFBFFBFRRL
|
||||
BFBBBBFLLL
|
||||
FBBBFBFRRL
|
||||
FFBFBFFLLL
|
||||
BFBBFFFRRL
|
||||
FFBBFFBLLR
|
||||
BFFBBBBRLR
|
||||
FFBBBBBLRR
|
||||
BFFBFFFRRL
|
||||
BFFBFBBRLL
|
||||
FBBBFBFRLR
|
||||
FBBFFFFLRR
|
||||
BFFFBBFLLR
|
||||
FFFBBFBRRL
|
||||
FFBBFFBLRR
|
||||
FBBFFFBRLR
|
||||
BFBBBBBRLL
|
||||
BBFFFFFRRL
|
||||
FFBFFBBRRL
|
||||
BFBFFBFLLR
|
||||
FBFBBBFLLL
|
||||
FBFFFFFRRL
|
||||
BFFFBFBLRR
|
||||
FBFFFFBLLR
|
||||
FBBFBFBRRR
|
||||
FBBBFFFLLR
|
||||
BBFFBFBLRR
|
||||
BBFFFBFLLL
|
||||
FBFFFBFRLR
|
||||
BFFFBFFLRL
|
||||
BBFFBFFLRL
|
||||
BFFFFFFLLR
|
||||
BBFFBBBLLL
|
||||
FFBFBBBLLR
|
||||
FBBFBBBLRL
|
||||
BFBBFBBLRR
|
||||
FFBFBFBLLR
|
||||
FFBFBFBRRL
|
||||
BFBBFBBRRL
|
||||
BFFBFFFLLR
|
||||
FFBBFFBRRL
|
||||
BBFFBBBRRL
|
||||
FFFBBFBRLR
|
||||
BFBBFBFRRR
|
||||
BFFFFFFRRR
|
||||
FBBBFFBLLL
|
||||
BFBFFFFLLL
|
||||
BBFFBFBLLR
|
||||
BFBFBBFRLR
|
||||
FFBFBBBRRR
|
||||
BFFFBBFLLL
|
||||
FBFFBBFRLL
|
||||
FFBBFBFRLL
|
||||
BFBFBBBLLR
|
||||
FBBFBFBLLL
|
||||
BBFFFFBRLL
|
||||
BBFFBFBLLL
|
||||
BFFBFFBLRR
|
||||
BFFBBFBLLL
|
||||
FFBFFFBLRR
|
||||
FBBFFBFRRL
|
||||
FBBBBFBLLL
|
||||
FFBFFBBLLR
|
||||
BFFBBBFLRR
|
||||
FBFBFFBRLL
|
||||
FFBFFFBRLL
|
||||
FFBFFBFLLL
|
||||
FBFBBFBLRL
|
||||
FBBFBFFRRR
|
||||
BFBFBFFLLR
|
||||
FBBFFFBLLR
|
||||
BFBBBBFRRR
|
||||
FBBFBBFRRR
|
||||
BBFFBFFRLR
|
||||
FBFBBBFRLL
|
||||
FBBFBBBLLR
|
||||
BFFFFFFLRL
|
||||
BFBFFBBRRR
|
||||
BFFFBFFRLL
|
||||
BFBBFBFLRL
|
||||
FFBFFFFRRR
|
||||
BFFBBFFRLR
|
||||
FBBBBBFLLR
|
||||
FBFBFFBLRL
|
||||
FFFBBFBLLR
|
||||
FBBFBFBLLR
|
||||
FFFBFFBRRR
|
||||
FBFFFFFRLR
|
||||
FBFBBFBRLR
|
||||
FBBBFBFLRR
|
||||
FBFBBBFLRL
|
||||
BFFBFFFLRL
|
||||
FFBBBFFRRR
|
||||
FFBBBBBLLL
|
||||
FBFFBBFLLR
|
||||
FFBFBFFLRR
|
||||
FFFBBBFLRR
|
||||
BFBFBBFLLL
|
||||
BBFFBFFLLR
|
||||
FFBBFBBRLL
|
||||
FBBFFBBLLL
|
||||
FBFFBFBRLL
|
||||
BFBFBFFLRR
|
||||
FBBBFFBRLR
|
||||
FFBFFBFRLL
|
||||
FFFFBBBLLL
|
||||
FFBFFBBRRR
|
||||
FBBBBFBRLL
|
||||
BFFFFBBRRR
|
||||
FFBBFFFRLL
|
||||
FFBFBFBRLL
|
||||
BBFFFFBLLL
|
||||
FFBBBFBRRL
|
||||
BFFFFBBLRL
|
||||
FBBBFBBLLR
|
||||
FBBBFBBLLL
|
||||
FFBFBFBLRL
|
||||
FBBBBFFRRR
|
||||
FBBFFFFRLR
|
||||
FFBFFFBRLR
|
||||
BFBFBFBRRR
|
||||
FFFBFBBRLL
|
||||
FBBBFFBRRR
|
||||
FBBFBFFRLL
|
||||
BFFBFBFLRR
|
||||
BFBBBFFRRL
|
||||
BFFBBFBLLR
|
||||
FFBBBFBRLL
|
||||
FBFBFBBLRR
|
||||
BFBBFFFLRL
|
||||
BFBFBBFLRR
|
||||
BFBBBFFRRR
|
||||
FBBBFFFRRL
|
||||
FBFBFBFLLR
|
||||
FBBFFFFLLR
|
||||
FFBFBBFRLR
|
||||
FFFBFBBLRL
|
||||
BBFFFBBLLR
|
||||
BFFBBBFRLR
|
||||
FFFFBBBRLR
|
||||
BBFFBBFRLR
|
||||
FBFFFFBRLL
|
||||
FBFBFFFRRR
|
||||
FBFFFBBLLL
|
||||
BFBBBBFRLL
|
||||
FBFBFFBRRL
|
||||
FFFBFFFRLR
|
||||
BFBBFBFRRL
|
||||
FBFFBFFLRR
|
||||
FBFFFBBLRR
|
||||
FFBFBBBRLR
|
||||
FBBFBFFLRR
|
||||
FBFFFBBRRR
|
||||
FFBFBBBRLL
|
||||
FFBBBBBRRR
|
||||
BFFBBFFLLL
|
||||
BFBBBBBRRL
|
||||
BBFFBBBRLL
|
||||
FBFFFFFLRL
|
||||
BFFBBFFLRR
|
||||
FBFFBBFLRL
|
||||
BFBFFBFRRR
|
||||
FBFBBFBRLL
|
||||
BFFFBFBRRL
|
||||
FBBFFBFLLR
|
||||
BFFFFFFLLL
|
||||
FBFBFBFRLL
|
||||
FBBBBFFRRL
|
||||
BFBFFBBLLR
|
||||
FBBFBFBRRL
|
||||
FFFBFFFLLR
|
||||
FFBBBBBLRL
|
||||
FFBFFBBLRR
|
||||
FFFBFBFRRR
|
||||
BFBBFBBRLL
|
||||
BFBBBFBLRR
|
||||
FFBBBBFLRR
|
||||
FBBBFFBLLR
|
||||
BBFFBBBLLR
|
||||
FBFBBFFRRL
|
||||
FBBBBBFLRL
|
||||
FFFBBFFRRL
|
||||
BFFBBBBLRR
|
||||
FFFFBBBLRR
|
||||
FFFFBBFLRR
|
||||
FBFFFBFLLL
|
||||
FBFBFBBLLR
|
||||
BFFBBBBLLL
|
||||
FFBFFFFRLR
|
||||
BFBBFFBLRR
|
||||
FFBBFBFLRL
|
||||
BFBFBFFLLL
|
||||
BFFBFBBLLR
|
||||
BFBBFBBLRL
|
||||
FFBBBBFLRL
|
||||
FBBBFFFLLL
|
||||
FFFBFFBRRL
|
||||
BFFFFBBRLL
|
||||
BFFFBBBRLL
|
||||
BFFBFFFLRR
|
||||
FFBFBFBRRR
|
||||
BBFFBBFLLR
|
||||
FFBBFBBLLR
|
||||
FFBFFBFRRR
|
||||
FFBBBFFRLR
|
||||
BFFBBBBLLR
|
||||
FFFBFFFLRR
|
||||
FBFFFFFLLR
|
||||
FBFFBBBLLL
|
||||
BBFFBBFLLL
|
||||
FFBBFBFLRR
|
||||
BFFBFBFLRL
|
||||
FBFBBBFRRR
|
||||
BFBBFBBLLR
|
||||
FBFFFFBRRL
|
||||
FFFBBFBLRR
|
||||
BBFFFFBLRR
|
||||
BFBBBBFRRL
|
||||
FFBBBFBLLL
|
||||
BFBBFBFRLR
|
||||
BFBBFFBRRL
|
||||
BFBFBFFRRL
|
||||
FBBFFBBLRL
|
||||
FFFBFFBLRL
|
||||
BFFBBFFRLL
|
||||
FBBBFFFRLL
|
||||
FBBFBBFLLR
|
||||
FFBFFFFLLR
|
||||
FBBBFBFLRL
|
||||
BFFFBBBLLR
|
||||
FBFBBBBRRR
|
||||
FBBFBFBRLR
|
||||
FFFBFBFLLR
|
||||
FFFFBBFRRR
|
||||
FFFBBFFLRL
|
||||
BFBFFBFRLL
|
||||
FFFBFFBLLR
|
||||
FBBFFFBRLL
|
||||
FFBBBFBRRR
|
||||
FFBBFBBRLR
|
||||
BBFFFFFRRR
|
||||
FFBFFFFRLL
|
||||
FBBFFBBRRL
|
||||
BBFFFBFLRR
|
||||
FBBFFFFRRR
|
||||
FFBFFFBRRL
|
||||
BFBBFBFLLL
|
||||
BFFFFBFLRR
|
||||
BBFFFFFLLL
|
||||
FFBBFBBRRL
|
||||
FFBFBFFLRL
|
||||
FBFFBBFRRL
|
||||
BBFFBFBRLR
|
||||
BBFFBBFLRR
|
||||
FBFFBFBRRR
|
||||
FBBFBBFLRR
|
||||
FBFFFBFRLL
|
||||
BFBFFFFLRL
|
||||
FFFBBFBRRR
|
||||
BFBBBBBLLR
|
||||
FBBFFBBRRR
|
||||
FFBBBFFLLL
|
||||
FBBBBFBLLR
|
||||
BBFFFFFRLL
|
||||
FFBBBBFRLR
|
||||
FBFBFBBRRR
|
||||
FBFFBFFLLL
|
||||
FBFFBBBLLR
|
||||
FBBBBFBRRL
|
||||
BFBFBFFRLR
|
||||
FBBFBBBRLL
|
||||
BFBBFFFRLL
|
||||
FBBBFBFLLL
|
||||
FFBFFFFRRL
|
||||
FBFBBFFRRR
|
||||
FBFFFFBLLL
|
||||
FBBBBBBRLL
|
||||
BFFBFBBRRR
|
||||
BBFFBBFRRL
|
||||
FBBFBFFLRL
|
||||
FBFFFFBRRR
|
||||
FBBFFFFRLL
|
||||
FFFBFFFRRR
|
||||
FBFFBBFLLL
|
||||
BFFFFBFLLL
|
||||
BFFFFBFLLR
|
||||
FFBFFBFLLR
|
||||
FFBFFBFLRR
|
||||
BFFBBBBLRL
|
||||
FFBBFFBLLL
|
||||
FBBFBBBLLL
|
||||
FBFBBBFLLR
|
||||
BFFBBBFLRL
|
||||
BFBBFFBRLL
|
||||
FBFFBFFRRR
|
||||
FFBFFFBLRL
|
||||
FFFBBBFRRL
|
||||
FFBFBBFLRR
|
||||
FFFBBBBLRL
|
||||
FFFBBFFLLL
|
||||
FFFBFBBRRR
|
||||
FBBFBFFLLL
|
||||
BFFFBBBLLL
|
||||
BFFBFFFRLR
|
||||
FFFBBBBLLL
|
||||
BFFFFFBRRL
|
||||
FFBBFFFLLR
|
||||
BFBBFFFRRR
|
||||
BFBFFBFLRR
|
||||
FFFBBBFLLR
|
||||
FBFBBBFLRR
|
||||
BBFFBBBRLR
|
||||
FBFBBFFLRR
|
||||
FFBBBFBLRL
|
||||
FFFBBBFRLL
|
||||
BFFBFFBRLR
|
||||
BBFFFBBRRR
|
||||
BFBBBBFLRL
|
||||
BFBBBFBRRR
|
||||
FBBBBFFLLL
|
||||
FFFBFBBLLL
|
||||
BBFFFFFRLR
|
||||
BBFFBFFLLL
|
||||
FFBFBBBLRL
|
||||
FFBBFBFRLR
|
||||
BFBBBBBLRR
|
||||
FFBFFFBLLR
|
||||
FFBFFBFLRL
|
||||
BFFBFBBRLR
|
||||
FBFBFFFRRL
|
||||
FBBBFFFLRR
|
||||
FFFBBFFLLR
|
||||
FBBBBFFRLR
|
||||
FFBBFBBRRR
|
||||
BFBBFBBRRR
|
||||
BFBFBBFRRL
|
||||
BFFBBBFRRL
|
||||
FFFBFFFLLL
|
||||
FBBFFBFLRL
|
||||
FFFBFBBRLR
|
||||
BFBBFFFLLR
|
||||
BFBBFFBRRR
|
||||
FBFFBFBRRL
|
||||
FFBBBBBRLL
|
||||
BFFBFFBLLL
|
||||
BFFFBBFRRR
|
||||
FBFFFBFRRR
|
||||
FFBFBFBRLR
|
||||
FBFBBFFLLR
|
||||
FBBFBBBRRR
|
||||
BFBFFFFRRR
|
||||
FFBFFFFLLL
|
||||
FBFBBFFRLL
|
||||
BFBFFBFLRL
|
||||
BFBBFFFLLL
|
||||
FBFBBFBRRR
|
||||
BFBFFFBLLR
|
||||
BFBFFFBLLL
|
||||
BBFFFBFLLR
|
||||
BBFFBFFRLL
|
||||
FFBBBBFRRL
|
||||
BBFFFBFLRL
|
||||
BBFFBBBLRL
|
||||
BFBFFFBLRR
|
||||
FFFBFBFRLL
|
||||
BFBFFBBLLL
|
||||
BBFFFBBRRL
|
||||
BFBBBFFLLL
|
||||
BFFBBFFLLR
|
||||
FFBFFBBLLL
|
||||
BFFBBFBRRL
|
||||
BFFFFFBLRL
|
||||
BBFFFFBRLR
|
||||
FBFBBFFLLL
|
||||
FFBBBFBRLR
|
||||
FFFBBFBLLL
|
||||
FBFFFBBRLR
|
||||
FFBFBFFRLR
|
||||
BFFFFFBLRR
|
||||
FFFBBBBRLL
|
||||
FFBBFFFRRR
|
||||
BFFFFFBRLR
|
||||
FBBBFFBLRR
|
||||
FBFBFBBRLR
|
||||
FBBFFFBLRR
|
||||
BFBFFBBLRL
|
||||
FBFFBFBRLR
|
||||
FBFBFFFLRL
|
||||
BFFFFFBRLL
|
||||
BFBBBBFLRR
|
||||
BFFBFFFLLL
|
||||
FBFFBFFRRL
|
||||
FFFBBFFRLL
|
||||
BFFFBFFRRR
|
||||
FBFFBFFLLR
|
||||
FFFBBBFLLL
|
||||
FBFFFBFLRR
|
||||
BFFBFBBLLL
|
||||
BFFFBBBLRR
|
||||
FBBBBBBRRL
|
||||
FBFFBFFRLR
|
||||
FBBFFBBRLL
|
||||
FBBBFFFRRR
|
||||
BFFBFBBRRL
|
||||
FFBBFFBRRR
|
||||
BFBBBFFLRR
|
||||
FFFBFBBRRL
|
||||
BFBFBBBLRR
|
||||
FFFBBFBLRL
|
||||
FBFFBBFRLR
|
||||
BFFFBBFLRR
|
||||
BBFFFBBLRL
|
||||
FBBFFBFRLR
|
||||
FFFBFBFLLL
|
||||
FFFBFFFRRL
|
||||
BBFBFFFLLL
|
||||
FBFBFBFLRR
|
||||
BFBFFFFRLL
|
25
2020/d06/ex1/ex1.py
Executable file
25
2020/d06/ex1/ex1.py
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import DefaultDict, List, Set
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
answers: DefaultDict[int, Set[str]] = defaultdict(set)
|
||||
group = 0
|
||||
for line in raw:
|
||||
if line == "":
|
||||
group += 1
|
||||
continue
|
||||
answers[group] |= {char for char in line}
|
||||
return sum(len(answer) for answer in answers.values())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2246
2020/d06/ex1/input
Normal file
2246
2020/d06/ex1/input
Normal file
File diff suppressed because it is too large
Load diff
31
2020/d06/ex2/ex2.py
Executable file
31
2020/d06/ex2/ex2.py
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import DefaultDict, List, Set
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
answers: DefaultDict[int, Set[str]] = defaultdict(set)
|
||||
group = 0
|
||||
first = True
|
||||
for line in raw:
|
||||
if line == "":
|
||||
group += 1
|
||||
first = True
|
||||
continue
|
||||
if not first:
|
||||
answers[group] &= {char for char in line}
|
||||
else:
|
||||
answers[group] = {char for char in line}
|
||||
first = False
|
||||
return sum(len(answer) for answer in answers.values())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2246
2020/d06/ex2/input
Normal file
2246
2020/d06/ex2/input
Normal file
File diff suppressed because it is too large
Load diff
77
2020/d07/ex1/ex1.py
Executable file
77
2020/d07/ex1/ex1.py
Executable file
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Set, Tuple
|
||||
|
||||
|
||||
@dataclass(eq=True, frozen=True) # Hashable
|
||||
class ColorInfo:
|
||||
num: int
|
||||
color: str
|
||||
|
||||
|
||||
Graph = Dict[str, Set[ColorInfo]]
|
||||
|
||||
|
||||
def extract_info(line: str) -> Tuple[str, Set[ColorInfo]]:
|
||||
color_pattern = re.compile("(.*) contain ")
|
||||
match = color_pattern.search(line)
|
||||
assert match is not None
|
||||
color = match.group(1).replace("bags", "bag")
|
||||
|
||||
line = line[match.end() : -1] # Remove period at end of line
|
||||
|
||||
if line == "no other bags":
|
||||
return color, set()
|
||||
|
||||
colors: Set[ColorInfo] = set()
|
||||
pattern = re.compile("([0-9]+) (.*)")
|
||||
for col in line.split(", "):
|
||||
match = pattern.search(col)
|
||||
assert match is not None
|
||||
colors |= {
|
||||
ColorInfo(int(match.group(1)), match.group(2).replace("bags", "bag"))
|
||||
}
|
||||
|
||||
return color, colors
|
||||
|
||||
|
||||
def to_graph(raw: List[str]) -> Graph:
|
||||
return {color: inside for color, inside in map(extract_info, raw)}
|
||||
|
||||
|
||||
def reverse(graph: Graph) -> Graph:
|
||||
reverse: Graph = defaultdict(set)
|
||||
|
||||
for color, contained in graph.items():
|
||||
for col in contained:
|
||||
reverse[col.color] |= {ColorInfo(-1, color)}
|
||||
|
||||
return reverse
|
||||
|
||||
|
||||
def containing(graph: Graph, col: str) -> Set[ColorInfo]:
|
||||
res = deepcopy(graph[col])
|
||||
for contains in graph[col]:
|
||||
res |= containing(graph, contains.color)
|
||||
return res
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
graph = to_graph(raw)
|
||||
reverse_graph = reverse(graph)
|
||||
|
||||
return len(containing(reverse_graph, "shiny gold bag"))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
594
2020/d07/ex1/input
Normal file
594
2020/d07/ex1/input
Normal file
|
@ -0,0 +1,594 @@
|
|||
shiny aqua bags contain 1 dark white bag.
|
||||
muted blue bags contain 1 vibrant lavender bag, 4 dotted silver bags, 2 dim indigo bags.
|
||||
drab gray bags contain 5 mirrored white bags, 1 light green bag, 5 shiny lavender bags, 5 faded aqua bags.
|
||||
muted indigo bags contain 4 muted chartreuse bags, 2 dotted teal bags.
|
||||
drab white bags contain 2 dull fuchsia bags, 1 vibrant bronze bag.
|
||||
dim lavender bags contain 4 muted tan bags.
|
||||
dotted tomato bags contain 1 mirrored lime bag, 2 vibrant white bags.
|
||||
clear orange bags contain 5 clear violet bags, 2 dull beige bags, 2 dark chartreuse bags.
|
||||
bright lime bags contain no other bags.
|
||||
striped brown bags contain 3 bright orange bags.
|
||||
vibrant green bags contain 3 shiny fuchsia bags.
|
||||
plaid tomato bags contain 3 faded chartreuse bags, 2 wavy salmon bags, 1 faded white bag, 3 mirrored maroon bags.
|
||||
drab beige bags contain 2 shiny bronze bags, 4 pale violet bags, 3 bright tomato bags, 4 pale red bags.
|
||||
posh green bags contain 2 dull lavender bags, 4 clear plum bags, 2 dark gray bags.
|
||||
dull maroon bags contain 3 dull magenta bags, 1 dull tan bag, 1 faded cyan bag, 5 dull silver bags.
|
||||
faded crimson bags contain 2 muted purple bags, 4 dotted olive bags, 5 drab silver bags.
|
||||
wavy bronze bags contain 3 dark orange bags, 2 dark brown bags, 5 bright silver bags.
|
||||
dark turquoise bags contain 5 dull plum bags.
|
||||
dull lavender bags contain 4 dotted maroon bags, 3 muted brown bags, 4 drab black bags, 4 dull cyan bags.
|
||||
dotted plum bags contain 1 shiny bronze bag, 3 clear brown bags, 3 muted indigo bags.
|
||||
dull white bags contain 3 clear tan bags, 5 shiny gold bags, 2 drab crimson bags.
|
||||
dull teal bags contain 2 bright tomato bags.
|
||||
shiny crimson bags contain 3 light green bags, 5 striped brown bags, 3 faded fuchsia bags.
|
||||
wavy brown bags contain 1 drab crimson bag, 2 wavy indigo bags.
|
||||
dark tan bags contain 2 faded gray bags, 4 shiny salmon bags.
|
||||
shiny red bags contain 4 dull chartreuse bags, 5 pale tomato bags.
|
||||
bright orange bags contain no other bags.
|
||||
wavy yellow bags contain 5 light indigo bags, 5 dark gray bags, 5 plaid indigo bags, 4 faded red bags.
|
||||
faded bronze bags contain 4 faded cyan bags, 5 shiny beige bags, 5 muted red bags.
|
||||
dull bronze bags contain 1 mirrored beige bag, 5 muted violet bags, 1 wavy lime bag.
|
||||
dark lime bags contain 2 drab maroon bags, 5 bright indigo bags, 4 shiny black bags, 5 dotted turquoise bags.
|
||||
drab red bags contain 5 bright red bags, 2 vibrant brown bags.
|
||||
dotted salmon bags contain 3 vibrant turquoise bags, 2 dull beige bags, 3 light turquoise bags.
|
||||
dull gray bags contain 3 striped green bags, 3 wavy coral bags, 1 dark gray bag, 2 light indigo bags.
|
||||
faded black bags contain 4 muted fuchsia bags, 4 wavy coral bags, 1 drab tomato bag.
|
||||
muted magenta bags contain 2 posh chartreuse bags, 4 pale violet bags.
|
||||
light tan bags contain 2 posh turquoise bags, 3 vibrant white bags, 1 light black bag.
|
||||
dark blue bags contain 3 plaid indigo bags, 2 posh black bags.
|
||||
dull indigo bags contain 4 light gray bags, 3 dotted tan bags, 4 dull coral bags.
|
||||
dim fuchsia bags contain 3 vibrant yellow bags, 3 mirrored cyan bags, 4 mirrored brown bags.
|
||||
shiny beige bags contain 2 dull silver bags, 3 bright lime bags, 5 dull magenta bags.
|
||||
light cyan bags contain 3 vibrant violet bags, 2 mirrored tomato bags, 2 vibrant coral bags, 4 mirrored silver bags.
|
||||
clear turquoise bags contain 4 drab tomato bags, 3 shiny gold bags, 4 drab gold bags.
|
||||
pale teal bags contain 2 wavy maroon bags, 2 dotted olive bags, 4 shiny white bags, 2 drab turquoise bags.
|
||||
dark purple bags contain 1 wavy indigo bag, 3 bright black bags, 3 dotted teal bags.
|
||||
bright white bags contain 5 wavy red bags, 2 mirrored cyan bags, 3 drab green bags.
|
||||
mirrored aqua bags contain 1 faded violet bag, 5 dotted purple bags.
|
||||
shiny lime bags contain 4 dark aqua bags.
|
||||
pale bronze bags contain 1 clear crimson bag.
|
||||
vibrant white bags contain 5 plaid lavender bags, 1 drab red bag, 4 vibrant brown bags.
|
||||
plaid tan bags contain 5 dim crimson bags.
|
||||
posh olive bags contain 3 bright red bags.
|
||||
plaid brown bags contain 5 vibrant turquoise bags.
|
||||
mirrored tomato bags contain 2 dotted chartreuse bags, 3 light aqua bags, 3 posh beige bags.
|
||||
plaid blue bags contain 5 striped green bags, 1 plaid purple bag, 4 muted gold bags.
|
||||
shiny tan bags contain 5 striped coral bags, 1 dull brown bag.
|
||||
shiny gold bags contain 1 dull magenta bag, 5 dark white bags, 4 faded turquoise bags.
|
||||
dull salmon bags contain 2 plaid gold bags, 2 light indigo bags.
|
||||
striped tomato bags contain 2 striped tan bags, 4 light blue bags, 4 drab tan bags.
|
||||
drab tomato bags contain 3 dim teal bags, 4 striped yellow bags, 3 bright red bags.
|
||||
faded olive bags contain 1 drab plum bag, 1 pale aqua bag, 3 light blue bags.
|
||||
dotted indigo bags contain 2 clear tomato bags.
|
||||
dark white bags contain 5 light aqua bags, 2 dim teal bags, 2 muted fuchsia bags, 5 light purple bags.
|
||||
dull orange bags contain 4 pale gold bags, 5 posh brown bags, 2 mirrored brown bags, 3 dark bronze bags.
|
||||
bright maroon bags contain 1 mirrored yellow bag, 4 light teal bags.
|
||||
bright silver bags contain 1 vibrant coral bag, 3 dim teal bags, 5 light purple bags.
|
||||
muted olive bags contain 5 plaid orange bags, 1 muted magenta bag.
|
||||
dull silver bags contain no other bags.
|
||||
pale maroon bags contain 2 pale bronze bags.
|
||||
light gray bags contain 4 vibrant yellow bags, 2 pale red bags.
|
||||
drab teal bags contain 2 light crimson bags, 3 vibrant brown bags, 3 vibrant tan bags.
|
||||
bright gold bags contain 1 wavy red bag, 5 wavy coral bags.
|
||||
plaid chartreuse bags contain 2 dim coral bags, 4 drab silver bags, 5 dim chartreuse bags, 3 light purple bags.
|
||||
clear blue bags contain 2 pale tomato bags, 4 dull gold bags, 4 dim fuchsia bags, 4 pale coral bags.
|
||||
vibrant purple bags contain 5 faded orange bags.
|
||||
plaid aqua bags contain 3 muted cyan bags, 2 wavy gray bags, 4 drab green bags, 4 pale beige bags.
|
||||
muted lime bags contain 1 muted tan bag.
|
||||
faded coral bags contain 3 drab turquoise bags, 1 shiny plum bag, 5 mirrored green bags, 5 clear white bags.
|
||||
vibrant lime bags contain 5 posh coral bags.
|
||||
faded green bags contain 3 pale orange bags, 5 dull turquoise bags, 1 mirrored crimson bag.
|
||||
mirrored gray bags contain 5 dim indigo bags.
|
||||
wavy maroon bags contain 4 mirrored bronze bags, 1 striped olive bag, 2 dull salmon bags, 3 shiny crimson bags.
|
||||
dark violet bags contain 2 light purple bags.
|
||||
dark green bags contain 2 dim cyan bags.
|
||||
pale black bags contain 1 mirrored gold bag.
|
||||
bright yellow bags contain 2 vibrant crimson bags, 3 plaid lime bags, 2 dotted gold bags.
|
||||
muted teal bags contain 1 pale violet bag, 4 dull silver bags.
|
||||
dim beige bags contain 5 wavy red bags.
|
||||
muted purple bags contain 4 clear cyan bags.
|
||||
plaid fuchsia bags contain 3 dark coral bags.
|
||||
plaid bronze bags contain 5 plaid orange bags, 2 drab indigo bags.
|
||||
faded indigo bags contain 1 dark chartreuse bag, 4 dull green bags, 1 mirrored magenta bag.
|
||||
posh plum bags contain 3 dark chartreuse bags, 3 dotted turquoise bags, 4 dull maroon bags, 1 posh bronze bag.
|
||||
pale gold bags contain 4 striped brown bags.
|
||||
mirrored chartreuse bags contain 4 bright silver bags, 3 mirrored tomato bags, 4 wavy orange bags.
|
||||
pale orange bags contain 2 posh fuchsia bags, 2 clear salmon bags, 2 bright green bags.
|
||||
clear brown bags contain 4 light lime bags, 4 bright green bags, 5 pale yellow bags, 2 drab cyan bags.
|
||||
shiny plum bags contain 5 vibrant gray bags, 3 bright blue bags, 5 dark tomato bags.
|
||||
wavy white bags contain 4 plaid lime bags, 4 posh maroon bags, 5 drab lime bags, 1 vibrant crimson bag.
|
||||
faded red bags contain 1 dull coral bag, 5 clear cyan bags, 4 plaid chartreuse bags, 3 plaid orange bags.
|
||||
plaid red bags contain 5 pale blue bags, 4 light crimson bags, 3 faded fuchsia bags.
|
||||
bright cyan bags contain 3 dark white bags, 2 light crimson bags, 1 bright aqua bag.
|
||||
muted lavender bags contain 1 light green bag, 4 striped silver bags, 3 posh crimson bags.
|
||||
wavy crimson bags contain 1 light purple bag, 4 bright blue bags, 2 dull coral bags, 1 wavy beige bag.
|
||||
faded aqua bags contain 5 muted brown bags.
|
||||
mirrored fuchsia bags contain 1 faded beige bag, 3 muted gold bags.
|
||||
dark chartreuse bags contain 5 bright lime bags.
|
||||
plaid green bags contain 4 mirrored tan bags, 1 mirrored tomato bag, 5 pale indigo bags, 1 mirrored plum bag.
|
||||
shiny black bags contain 3 plaid chartreuse bags.
|
||||
dotted purple bags contain 2 dim teal bags.
|
||||
faded tan bags contain 2 bright fuchsia bags, 5 shiny fuchsia bags, 1 muted fuchsia bag, 1 mirrored brown bag.
|
||||
drab brown bags contain 1 striped orange bag, 4 dotted tomato bags.
|
||||
dull olive bags contain 1 striped black bag, 1 vibrant magenta bag.
|
||||
mirrored plum bags contain 1 clear gold bag, 5 pale green bags.
|
||||
dim tomato bags contain 4 drab gold bags, 2 shiny aqua bags.
|
||||
light lavender bags contain 1 muted violet bag.
|
||||
dim gray bags contain 3 light purple bags, 1 posh crimson bag, 1 faded brown bag.
|
||||
muted aqua bags contain 4 dull beige bags, 4 dull red bags.
|
||||
faded silver bags contain 1 mirrored cyan bag.
|
||||
shiny green bags contain 5 dull maroon bags.
|
||||
muted chartreuse bags contain 2 clear tan bags.
|
||||
plaid plum bags contain 1 dotted lime bag, 4 clear brown bags, 4 dull red bags.
|
||||
dotted silver bags contain 1 posh coral bag.
|
||||
dim crimson bags contain 4 faded violet bags, 1 striped silver bag.
|
||||
bright brown bags contain 1 bright coral bag, 3 posh brown bags, 4 drab tan bags.
|
||||
wavy cyan bags contain 3 clear gold bags, 1 mirrored salmon bag, 3 bright fuchsia bags, 2 light bronze bags.
|
||||
dull violet bags contain 5 striped white bags, 4 light blue bags, 4 dim black bags.
|
||||
vibrant olive bags contain 2 vibrant coral bags.
|
||||
bright coral bags contain 2 vibrant tan bags, 3 shiny indigo bags, 2 plaid indigo bags.
|
||||
dim turquoise bags contain 1 pale violet bag.
|
||||
striped crimson bags contain 2 faded gray bags.
|
||||
clear green bags contain 3 mirrored olive bags, 3 shiny tomato bags.
|
||||
faded violet bags contain 2 wavy coral bags, 2 dull tan bags, 1 dull silver bag, 1 bright orange bag.
|
||||
pale chartreuse bags contain 4 shiny crimson bags, 2 clear bronze bags.
|
||||
light plum bags contain 3 drab bronze bags, 1 bright bronze bag, 1 posh yellow bag.
|
||||
pale tomato bags contain 1 dim teal bag, 5 drab cyan bags, 3 muted coral bags, 2 dim chartreuse bags.
|
||||
plaid coral bags contain 1 striped tan bag, 3 vibrant cyan bags, 3 light beige bags, 2 dotted green bags.
|
||||
bright gray bags contain 4 mirrored teal bags, 4 striped brown bags, 1 dim green bag, 4 clear cyan bags.
|
||||
drab fuchsia bags contain 2 mirrored salmon bags, 4 posh orange bags, 3 faded crimson bags, 3 pale plum bags.
|
||||
light tomato bags contain 2 dotted gold bags, 1 dotted bronze bag.
|
||||
muted violet bags contain 2 light chartreuse bags.
|
||||
drab tan bags contain 2 light green bags, 5 bright red bags, 4 shiny beige bags.
|
||||
drab chartreuse bags contain 2 drab salmon bags, 2 dark brown bags, 4 clear turquoise bags.
|
||||
drab violet bags contain 4 faded red bags.
|
||||
posh cyan bags contain 4 bright violet bags.
|
||||
posh orange bags contain 4 pale plum bags, 5 posh aqua bags.
|
||||
plaid silver bags contain 1 dotted brown bag, 3 drab gold bags, 4 clear yellow bags.
|
||||
mirrored silver bags contain 3 shiny beige bags, 1 drab silver bag.
|
||||
faded gray bags contain no other bags.
|
||||
wavy tomato bags contain 1 bright brown bag, 3 striped red bags, 2 vibrant maroon bags.
|
||||
posh violet bags contain 2 dim aqua bags.
|
||||
bright blue bags contain 5 light lime bags, 2 faded violet bags, 3 light aqua bags, 4 vibrant coral bags.
|
||||
dark teal bags contain 5 muted fuchsia bags.
|
||||
striped fuchsia bags contain 1 wavy turquoise bag, 5 wavy green bags, 4 posh gold bags.
|
||||
posh maroon bags contain 2 dull red bags.
|
||||
shiny purple bags contain 2 clear tan bags.
|
||||
wavy lime bags contain 2 dark coral bags, 1 shiny gold bag.
|
||||
wavy silver bags contain 4 dotted white bags.
|
||||
shiny silver bags contain 2 plaid gold bags, 2 dim green bags, 5 plaid lime bags, 3 dull red bags.
|
||||
wavy red bags contain 3 vibrant brown bags, 4 bright indigo bags.
|
||||
dull chartreuse bags contain 4 dotted lime bags, 2 bright silver bags, 3 dull red bags, 4 wavy maroon bags.
|
||||
vibrant silver bags contain 1 bright fuchsia bag, 3 drab lavender bags, 2 drab olive bags, 3 dotted teal bags.
|
||||
striped gray bags contain 5 plaid orange bags, 1 wavy coral bag.
|
||||
striped green bags contain 4 wavy coral bags, 4 shiny gold bags, 3 dark brown bags, 5 vibrant brown bags.
|
||||
mirrored violet bags contain 3 dim silver bags, 1 posh tomato bag, 1 light salmon bag.
|
||||
dull purple bags contain 1 light gray bag, 3 wavy yellow bags, 1 wavy salmon bag.
|
||||
mirrored beige bags contain 4 dark cyan bags, 5 dull green bags.
|
||||
posh lime bags contain 3 posh chartreuse bags.
|
||||
vibrant tan bags contain 2 dull plum bags, 1 striped brown bag, 4 vibrant coral bags.
|
||||
dotted orange bags contain 1 mirrored olive bag, 5 drab silver bags.
|
||||
clear indigo bags contain 3 light lime bags, 4 dull coral bags.
|
||||
pale gray bags contain 1 faded black bag, 3 dim green bags, 4 wavy lavender bags, 2 posh brown bags.
|
||||
posh gold bags contain 5 dark tan bags, 2 dotted olive bags, 5 dark aqua bags.
|
||||
striped chartreuse bags contain 2 dull magenta bags, 1 posh tomato bag.
|
||||
mirrored bronze bags contain 2 faded fuchsia bags.
|
||||
clear salmon bags contain 4 posh bronze bags, 5 clear plum bags, 5 dull blue bags.
|
||||
posh purple bags contain 5 dim gray bags, 3 faded brown bags.
|
||||
faded lime bags contain 5 dim turquoise bags, 3 dark indigo bags, 2 vibrant gray bags, 1 muted silver bag.
|
||||
wavy beige bags contain 1 dark bronze bag, 4 dull plum bags, 4 mirrored silver bags.
|
||||
clear yellow bags contain 2 vibrant teal bags.
|
||||
vibrant plum bags contain 4 muted chartreuse bags, 4 posh silver bags.
|
||||
striped yellow bags contain 2 dull maroon bags, 5 bright red bags, 2 posh chartreuse bags.
|
||||
dark coral bags contain 3 dull tan bags.
|
||||
dull magenta bags contain no other bags.
|
||||
dark gold bags contain 1 dotted indigo bag, 4 shiny teal bags, 4 dotted silver bags.
|
||||
dim tan bags contain 1 striped lavender bag, 1 shiny tomato bag.
|
||||
muted maroon bags contain 2 dull salmon bags, 4 dim chartreuse bags, 3 bright aqua bags, 2 faded indigo bags.
|
||||
vibrant tomato bags contain 2 dark silver bags, 3 plaid purple bags.
|
||||
dotted lime bags contain 3 shiny crimson bags, 2 pale yellow bags.
|
||||
muted fuchsia bags contain 1 dull tan bag.
|
||||
bright tan bags contain 5 pale gold bags, 5 drab teal bags, 2 light blue bags.
|
||||
dark crimson bags contain 4 shiny orange bags, 3 faded purple bags, 3 bright white bags.
|
||||
striped tan bags contain 4 dotted turquoise bags, 4 drab lime bags, 5 dim teal bags.
|
||||
posh fuchsia bags contain 2 dotted olive bags, 2 mirrored beige bags, 3 shiny bronze bags.
|
||||
pale silver bags contain 4 vibrant lavender bags, 4 clear beige bags, 4 striped gold bags.
|
||||
posh aqua bags contain 4 drab lime bags, 4 dull tan bags, 5 vibrant tan bags.
|
||||
plaid salmon bags contain 5 dim coral bags, 2 wavy bronze bags.
|
||||
mirrored orange bags contain 4 vibrant gray bags.
|
||||
dim yellow bags contain 5 pale tan bags, 4 dark black bags.
|
||||
dotted coral bags contain 4 dotted chartreuse bags, 2 bright red bags, 1 vibrant white bag, 1 vibrant brown bag.
|
||||
muted crimson bags contain 4 striped orange bags, 5 pale yellow bags, 3 posh blue bags, 1 muted red bag.
|
||||
striped lavender bags contain 3 striped brown bags.
|
||||
striped maroon bags contain 2 shiny yellow bags.
|
||||
vibrant blue bags contain 3 faded cyan bags, 1 shiny lime bag, 3 dark tomato bags.
|
||||
pale lavender bags contain 4 plaid magenta bags, 4 striped blue bags.
|
||||
dull tan bags contain 4 shiny indigo bags, 2 light purple bags, 4 faded cyan bags.
|
||||
dotted beige bags contain 3 drab indigo bags.
|
||||
light indigo bags contain 1 faded cyan bag, 5 bright aqua bags, 1 shiny indigo bag.
|
||||
vibrant crimson bags contain 4 dotted fuchsia bags.
|
||||
wavy blue bags contain 4 wavy teal bags, 1 dull blue bag.
|
||||
vibrant chartreuse bags contain 4 striped orange bags.
|
||||
vibrant cyan bags contain 5 wavy coral bags.
|
||||
faded brown bags contain 5 faded turquoise bags.
|
||||
faded magenta bags contain 1 dull indigo bag, 4 plaid aqua bags, 4 dim crimson bags.
|
||||
mirrored coral bags contain 4 drab crimson bags, 2 light salmon bags, 2 clear indigo bags.
|
||||
faded cyan bags contain no other bags.
|
||||
dark brown bags contain 5 light purple bags.
|
||||
wavy violet bags contain 3 dull coral bags, 1 bright aqua bag, 3 shiny lavender bags.
|
||||
posh tomato bags contain 4 vibrant chartreuse bags, 4 mirrored teal bags.
|
||||
pale crimson bags contain 1 plaid orange bag, 1 dark violet bag, 3 plaid lavender bags.
|
||||
dark fuchsia bags contain 4 plaid beige bags, 2 plaid chartreuse bags.
|
||||
plaid magenta bags contain 3 clear lavender bags, 5 mirrored brown bags, 5 shiny bronze bags.
|
||||
striped blue bags contain 1 dull bronze bag, 1 dotted fuchsia bag, 1 light lavender bag, 1 clear turquoise bag.
|
||||
dotted olive bags contain 4 dotted turquoise bags, 5 dotted bronze bags, 3 pale yellow bags, 4 pale red bags.
|
||||
posh silver bags contain 3 pale violet bags, 1 plaid salmon bag, 1 posh coral bag.
|
||||
dotted chartreuse bags contain 3 bright blue bags.
|
||||
light coral bags contain 4 shiny fuchsia bags, 2 pale red bags, 1 muted silver bag, 2 bright cyan bags.
|
||||
pale brown bags contain 5 light aqua bags.
|
||||
dotted black bags contain 2 plaid purple bags, 1 mirrored aqua bag, 5 posh beige bags.
|
||||
posh coral bags contain 3 dark aqua bags, 2 pale yellow bags, 5 plaid blue bags, 4 dim aqua bags.
|
||||
shiny gray bags contain 1 bright gold bag, 1 muted bronze bag, 5 striped green bags, 5 shiny teal bags.
|
||||
drab orange bags contain 5 plaid salmon bags, 2 vibrant beige bags.
|
||||
plaid yellow bags contain 4 clear teal bags, 2 bright red bags.
|
||||
striped violet bags contain 4 mirrored fuchsia bags, 4 vibrant white bags, 3 dim teal bags.
|
||||
dim aqua bags contain 1 muted fuchsia bag, 1 dull tan bag.
|
||||
light orange bags contain 2 bright red bags, 4 dark white bags, 1 dim chartreuse bag, 5 faded fuchsia bags.
|
||||
faded salmon bags contain 5 wavy gray bags.
|
||||
shiny yellow bags contain 2 vibrant plum bags, 3 dim teal bags, 1 plaid tan bag, 5 posh plum bags.
|
||||
vibrant beige bags contain 2 wavy lavender bags, 4 posh chartreuse bags, 3 pale teal bags, 5 wavy lime bags.
|
||||
light fuchsia bags contain 3 clear brown bags, 3 bright lavender bags.
|
||||
pale magenta bags contain 4 posh silver bags.
|
||||
dark maroon bags contain 3 drab turquoise bags.
|
||||
faded beige bags contain 1 vibrant white bag, 4 drab red bags, 1 drab lavender bag.
|
||||
bright bronze bags contain 1 pale bronze bag, 3 muted silver bags, 2 striped coral bags, 3 clear gray bags.
|
||||
light silver bags contain 3 dotted lavender bags, 2 wavy lavender bags.
|
||||
muted salmon bags contain 2 drab tan bags, 5 wavy tomato bags.
|
||||
bright black bags contain 5 plaid tan bags.
|
||||
dim chartreuse bags contain 5 muted gold bags, 5 bright blue bags, 5 faded cyan bags.
|
||||
shiny white bags contain 4 bright tan bags.
|
||||
bright red bags contain 3 dull silver bags.
|
||||
dark aqua bags contain 2 dull red bags.
|
||||
drab plum bags contain 4 muted brown bags, 5 muted plum bags.
|
||||
muted yellow bags contain 5 light purple bags, 3 dotted silver bags, 3 faded turquoise bags.
|
||||
light violet bags contain 1 pale red bag, 4 dim silver bags, 2 mirrored bronze bags.
|
||||
pale lime bags contain 4 bright lavender bags.
|
||||
pale tan bags contain 4 striped green bags, 2 dotted chartreuse bags.
|
||||
dim green bags contain 1 light lime bag, 1 shiny beige bag.
|
||||
mirrored gold bags contain 4 mirrored white bags.
|
||||
dim silver bags contain 5 pale coral bags, 3 wavy coral bags.
|
||||
dull aqua bags contain 3 posh indigo bags, 5 dotted coral bags, 1 dark salmon bag, 3 striped crimson bags.
|
||||
posh yellow bags contain 1 dark bronze bag, 2 mirrored white bags, 2 light crimson bags.
|
||||
mirrored magenta bags contain 1 bright violet bag, 2 drab lavender bags, 3 pale violet bags, 2 plaid salmon bags.
|
||||
shiny chartreuse bags contain 2 dotted purple bags, 5 wavy red bags, 3 plaid beige bags.
|
||||
light black bags contain 1 dark chartreuse bag, 3 faded tomato bags.
|
||||
clear plum bags contain 5 vibrant brown bags, 3 dim coral bags, 4 mirrored brown bags, 1 faded black bag.
|
||||
pale violet bags contain 2 dull tan bags.
|
||||
bright fuchsia bags contain 4 dull orange bags.
|
||||
dotted teal bags contain 5 bright red bags, 3 wavy red bags, 1 dull coral bag, 3 clear plum bags.
|
||||
dotted blue bags contain 2 wavy beige bags, 3 muted purple bags.
|
||||
muted gray bags contain 3 faded aqua bags, 1 shiny olive bag, 5 clear salmon bags, 1 vibrant violet bag.
|
||||
dull beige bags contain 1 wavy lavender bag, 4 dark bronze bags, 5 dull tan bags.
|
||||
drab turquoise bags contain 3 posh gray bags, 5 drab red bags.
|
||||
vibrant yellow bags contain 2 shiny aqua bags, 4 light chartreuse bags.
|
||||
posh brown bags contain 3 bright green bags, 5 posh lavender bags.
|
||||
faded gold bags contain 4 vibrant maroon bags, 4 dotted purple bags.
|
||||
dotted turquoise bags contain 5 clear plum bags, 3 muted gold bags, 4 dark violet bags.
|
||||
dotted tan bags contain 5 dim aqua bags, 4 striped violet bags.
|
||||
posh crimson bags contain 4 striped blue bags, 5 dull magenta bags, 2 bright coral bags.
|
||||
muted white bags contain 5 dull olive bags.
|
||||
vibrant teal bags contain 5 dotted turquoise bags, 1 striped tan bag, 1 drab tan bag.
|
||||
dotted yellow bags contain 3 plaid turquoise bags, 2 posh yellow bags, 4 striped blue bags, 5 posh black bags.
|
||||
posh magenta bags contain 5 mirrored black bags.
|
||||
dotted green bags contain 4 dim crimson bags, 1 shiny lavender bag, 4 bright salmon bags, 1 plaid gray bag.
|
||||
bright green bags contain 3 bright aqua bags, 3 dull maroon bags, 4 dark brown bags.
|
||||
dark gray bags contain 5 muted purple bags, 2 striped blue bags, 4 faded lavender bags.
|
||||
bright crimson bags contain 2 striped olive bags, 3 muted blue bags.
|
||||
muted cyan bags contain 3 shiny tomato bags.
|
||||
light yellow bags contain 2 striped red bags, 4 shiny crimson bags.
|
||||
pale aqua bags contain 5 shiny yellow bags, 3 dark lavender bags, 3 posh white bags.
|
||||
clear red bags contain 1 dotted silver bag, 1 dull teal bag, 1 faded maroon bag, 1 dotted salmon bag.
|
||||
pale red bags contain 2 faded gray bags.
|
||||
dotted maroon bags contain 5 posh aqua bags, 3 dull silver bags.
|
||||
dull blue bags contain 4 light crimson bags, 3 light lime bags, 1 dark orange bag, 5 light indigo bags.
|
||||
posh turquoise bags contain 1 muted gold bag, 5 striped lavender bags, 3 dull salmon bags, 5 vibrant chartreuse bags.
|
||||
striped magenta bags contain 1 posh silver bag, 5 dark brown bags.
|
||||
pale blue bags contain 2 muted gold bags, 4 vibrant brown bags, 1 light lavender bag.
|
||||
vibrant violet bags contain 5 bright red bags.
|
||||
faded fuchsia bags contain 2 light lime bags, 4 bright lime bags, 3 pale violet bags.
|
||||
shiny coral bags contain 1 clear plum bag, 5 muted chartreuse bags, 1 muted violet bag, 5 striped yellow bags.
|
||||
pale olive bags contain 4 plaid lime bags, 1 posh salmon bag.
|
||||
wavy tan bags contain 3 faded gray bags.
|
||||
faded chartreuse bags contain 3 dim coral bags, 1 mirrored bronze bag, 3 posh bronze bags.
|
||||
mirrored brown bags contain 1 faded violet bag, 4 dull maroon bags, 5 dotted magenta bags.
|
||||
clear white bags contain 5 muted magenta bags, 4 dull magenta bags, 3 pale plum bags, 4 drab indigo bags.
|
||||
drab maroon bags contain 2 clear beige bags, 3 wavy beige bags, 5 faded purple bags.
|
||||
striped silver bags contain 3 drab tomato bags.
|
||||
faded plum bags contain 1 clear teal bag, 3 bright aqua bags.
|
||||
plaid violet bags contain 2 drab violet bags, 4 muted turquoise bags, 5 muted indigo bags.
|
||||
clear black bags contain 5 muted fuchsia bags, 1 muted coral bag, 2 light black bags.
|
||||
vibrant maroon bags contain 1 dark lavender bag, 1 pale crimson bag, 4 bright indigo bags, 5 mirrored maroon bags.
|
||||
drab indigo bags contain 2 dim coral bags, 1 drab green bag, 2 shiny lavender bags.
|
||||
drab olive bags contain 2 dark aqua bags, 4 striped brown bags.
|
||||
dull crimson bags contain 3 dull cyan bags.
|
||||
wavy teal bags contain 4 striped orange bags, 2 drab cyan bags.
|
||||
dark red bags contain 2 dull maroon bags, 4 muted plum bags, 4 dull plum bags.
|
||||
striped salmon bags contain 3 bright red bags, 1 light aqua bag, 4 wavy gold bags.
|
||||
mirrored tan bags contain 5 dotted olive bags, 2 dim tomato bags, 2 mirrored tomato bags, 4 clear teal bags.
|
||||
striped white bags contain 2 pale coral bags, 2 shiny green bags.
|
||||
shiny tomato bags contain 5 pale coral bags, 5 dull beige bags.
|
||||
vibrant indigo bags contain 2 dim black bags, 4 dim blue bags, 3 dim white bags.
|
||||
wavy lavender bags contain 4 faded bronze bags, 4 muted red bags, 3 light lime bags, 4 muted gold bags.
|
||||
shiny turquoise bags contain 2 dull red bags, 5 faded gray bags, 1 muted turquoise bag.
|
||||
shiny lavender bags contain 5 bright aqua bags.
|
||||
posh tan bags contain 1 shiny yellow bag, 3 drab magenta bags.
|
||||
light green bags contain 4 bright red bags, 1 vibrant coral bag.
|
||||
drab black bags contain 5 faded tomato bags, 3 dotted chartreuse bags.
|
||||
clear chartreuse bags contain 3 wavy bronze bags, 4 plaid purple bags, 3 dark orange bags.
|
||||
dull black bags contain 1 wavy teal bag, 3 light lavender bags, 2 striped indigo bags.
|
||||
wavy black bags contain 2 clear orange bags, 4 muted purple bags.
|
||||
pale plum bags contain 1 bright coral bag, 1 drab tan bag, 1 plaid fuchsia bag, 1 dotted fuchsia bag.
|
||||
dotted violet bags contain 3 bright black bags.
|
||||
posh red bags contain 3 bright black bags.
|
||||
plaid lime bags contain 5 posh beige bags, 1 dotted turquoise bag.
|
||||
wavy aqua bags contain 1 dark yellow bag, 3 drab indigo bags.
|
||||
dim magenta bags contain 3 dark violet bags.
|
||||
drab aqua bags contain 5 posh orange bags, 1 dark silver bag, 4 plaid purple bags, 2 wavy teal bags.
|
||||
dull brown bags contain 4 light lime bags.
|
||||
striped orange bags contain 5 light crimson bags, 3 muted tan bags, 5 dotted coral bags, 3 plaid blue bags.
|
||||
muted brown bags contain 1 posh blue bag, 4 dotted magenta bags, 3 dull coral bags.
|
||||
faded blue bags contain 5 striped black bags, 1 vibrant yellow bag.
|
||||
plaid indigo bags contain 3 dark brown bags, 5 light purple bags, 4 light aqua bags, 3 light green bags.
|
||||
plaid turquoise bags contain 5 dotted teal bags.
|
||||
light turquoise bags contain 2 dull salmon bags, 5 dotted tan bags.
|
||||
dim purple bags contain 4 muted white bags, 5 drab purple bags.
|
||||
pale coral bags contain 5 posh gray bags.
|
||||
clear lime bags contain 3 dim magenta bags, 3 plaid tomato bags, 1 drab magenta bag, 3 shiny purple bags.
|
||||
dim black bags contain 3 clear gold bags, 4 muted violet bags.
|
||||
light maroon bags contain 4 muted yellow bags, 1 pale cyan bag, 2 mirrored turquoise bags, 4 dull lavender bags.
|
||||
clear magenta bags contain 2 shiny magenta bags, 2 muted chartreuse bags.
|
||||
striped bronze bags contain 5 clear tan bags, 1 drab lavender bag, 2 pale crimson bags.
|
||||
dark salmon bags contain 1 vibrant plum bag, 5 drab tan bags, 4 drab coral bags, 4 dull tan bags.
|
||||
vibrant salmon bags contain 2 muted olive bags.
|
||||
dim gold bags contain 2 dim olive bags, 5 plaid olive bags, 2 posh orange bags.
|
||||
wavy chartreuse bags contain 4 shiny yellow bags, 4 vibrant blue bags.
|
||||
vibrant brown bags contain 3 striped brown bags, 4 muted red bags, 2 shiny indigo bags.
|
||||
plaid maroon bags contain 2 muted teal bags, 2 pale yellow bags, 2 bright beige bags, 5 striped yellow bags.
|
||||
dim indigo bags contain 4 dull tomato bags, 4 clear cyan bags, 2 shiny salmon bags, 1 bright aqua bag.
|
||||
muted red bags contain 3 dull tan bags, 4 dull magenta bags, 1 bright aqua bag.
|
||||
posh beige bags contain 5 shiny black bags, 3 dotted magenta bags, 3 drab blue bags, 2 muted coral bags.
|
||||
pale fuchsia bags contain 3 dark brown bags, 5 posh gold bags.
|
||||
dark bronze bags contain 1 dim green bag, 5 posh chartreuse bags.
|
||||
dim coral bags contain 3 dull coral bags, 3 striped brown bags.
|
||||
drab crimson bags contain 2 dark bronze bags, 4 shiny indigo bags, 3 dull tan bags.
|
||||
bright indigo bags contain 3 bright blue bags.
|
||||
pale yellow bags contain 5 dim aqua bags, 1 vibrant brown bag, 2 vibrant tan bags, 3 wavy lavender bags.
|
||||
drab salmon bags contain 1 dotted indigo bag, 3 muted chartreuse bags, 5 dark olive bags.
|
||||
muted orange bags contain 4 faded lime bags, 2 dull coral bags, 5 vibrant magenta bags, 4 dull magenta bags.
|
||||
striped gold bags contain 2 dull silver bags, 5 bright lavender bags, 5 dim teal bags, 5 dark coral bags.
|
||||
posh chartreuse bags contain 3 dim teal bags, 5 light aqua bags.
|
||||
shiny blue bags contain 3 dull tan bags, 5 muted magenta bags.
|
||||
muted silver bags contain 3 wavy blue bags, 2 dim teal bags, 5 muted bronze bags.
|
||||
shiny bronze bags contain 1 light green bag, 4 vibrant magenta bags.
|
||||
wavy coral bags contain no other bags.
|
||||
shiny orange bags contain 2 muted purple bags.
|
||||
posh teal bags contain 4 clear plum bags.
|
||||
striped turquoise bags contain 3 muted indigo bags.
|
||||
dim bronze bags contain 2 shiny silver bags, 1 light silver bag, 2 dim indigo bags, 4 dim tomato bags.
|
||||
plaid white bags contain 4 drab turquoise bags.
|
||||
wavy indigo bags contain 3 clear gold bags, 5 mirrored bronze bags.
|
||||
faded teal bags contain 4 mirrored white bags.
|
||||
shiny fuchsia bags contain 3 drab indigo bags.
|
||||
dim red bags contain 3 clear bronze bags.
|
||||
dotted brown bags contain 4 wavy maroon bags, 5 drab green bags, 3 dark purple bags.
|
||||
dark tomato bags contain 3 vibrant coral bags, 5 dull coral bags, 2 drab cyan bags, 1 posh blue bag.
|
||||
clear teal bags contain 3 dark white bags.
|
||||
dark silver bags contain 3 dark cyan bags, 4 plaid salmon bags.
|
||||
wavy fuchsia bags contain 4 bright brown bags, 4 bright aqua bags, 5 light orange bags.
|
||||
light bronze bags contain 4 clear plum bags.
|
||||
striped purple bags contain 1 dim indigo bag.
|
||||
clear tomato bags contain 4 mirrored tomato bags, 3 muted indigo bags, 1 striped tan bag.
|
||||
muted turquoise bags contain 5 faded beige bags, 4 clear crimson bags, 2 bright teal bags.
|
||||
dull cyan bags contain 5 mirrored aqua bags, 2 shiny aqua bags, 3 light black bags, 4 bright coral bags.
|
||||
plaid crimson bags contain 2 mirrored teal bags, 2 dull fuchsia bags.
|
||||
shiny maroon bags contain 1 posh gold bag.
|
||||
dim white bags contain 5 striped brown bags, 2 dull magenta bags, 5 plaid tan bags.
|
||||
muted green bags contain 2 dull magenta bags, 5 clear cyan bags.
|
||||
plaid teal bags contain 2 dark tan bags, 3 pale lime bags.
|
||||
dotted lavender bags contain 2 posh aqua bags, 3 dull cyan bags.
|
||||
light salmon bags contain 5 dark silver bags.
|
||||
faded white bags contain 2 wavy maroon bags, 3 dull cyan bags.
|
||||
dull tomato bags contain 2 dim aqua bags, 4 posh lavender bags, 1 faded red bag.
|
||||
dark olive bags contain 5 clear bronze bags, 2 drab plum bags.
|
||||
pale indigo bags contain 2 mirrored beige bags, 5 wavy turquoise bags, 4 striped green bags, 2 dotted lavender bags.
|
||||
plaid purple bags contain 1 light lime bag.
|
||||
clear purple bags contain 3 vibrant white bags.
|
||||
dark yellow bags contain 2 pale olive bags, 4 pale cyan bags, 5 bright teal bags.
|
||||
muted beige bags contain 2 posh lime bags, 5 shiny gray bags, 2 dull blue bags.
|
||||
vibrant orange bags contain 5 posh crimson bags, 4 light chartreuse bags.
|
||||
light magenta bags contain 2 plaid maroon bags, 1 posh beige bag, 5 pale salmon bags.
|
||||
dotted crimson bags contain 5 dark chartreuse bags.
|
||||
striped coral bags contain 2 dim aqua bags.
|
||||
striped aqua bags contain 3 posh salmon bags, 3 dull red bags.
|
||||
mirrored salmon bags contain 5 bright red bags, 2 light green bags, 3 clear black bags, 5 posh brown bags.
|
||||
posh white bags contain 4 drab violet bags, 2 dotted silver bags.
|
||||
posh blue bags contain 4 dull maroon bags, 3 vibrant coral bags.
|
||||
dim orange bags contain 2 dull olive bags.
|
||||
shiny teal bags contain 1 faded tomato bag, 4 muted violet bags.
|
||||
mirrored maroon bags contain 3 dull blue bags.
|
||||
dark lavender bags contain 1 drab red bag, 3 shiny indigo bags, 4 faded beige bags, 1 drab turquoise bag.
|
||||
shiny olive bags contain 3 dark violet bags, 1 striped gold bag, 2 mirrored lime bags.
|
||||
bright violet bags contain 2 wavy bronze bags, 3 drab olive bags, 5 mirrored olive bags, 2 wavy lavender bags.
|
||||
clear olive bags contain 5 faded turquoise bags.
|
||||
mirrored lavender bags contain 1 light white bag, 4 light purple bags, 3 wavy lavender bags, 2 shiny lime bags.
|
||||
pale turquoise bags contain 4 dark tan bags.
|
||||
shiny salmon bags contain 1 shiny gold bag, 5 drab turquoise bags.
|
||||
vibrant gray bags contain 3 posh brown bags.
|
||||
dark indigo bags contain 1 mirrored black bag, 5 dull beige bags, 4 shiny beige bags, 3 drab lavender bags.
|
||||
light teal bags contain 5 dark olive bags, 5 vibrant chartreuse bags, 3 plaid salmon bags, 5 light yellow bags.
|
||||
clear violet bags contain 3 light crimson bags.
|
||||
clear tan bags contain 3 striped orange bags, 4 wavy lavender bags, 3 striped silver bags.
|
||||
clear bronze bags contain 2 plaid beige bags.
|
||||
clear gray bags contain 4 dotted cyan bags, 4 vibrant plum bags.
|
||||
drab cyan bags contain 1 light aqua bag, 1 drab teal bag, 3 bright orange bags, 3 dark white bags.
|
||||
plaid beige bags contain 3 dull green bags.
|
||||
wavy gold bags contain 4 shiny olive bags, 3 bright tan bags.
|
||||
clear aqua bags contain 3 posh chartreuse bags, 4 drab silver bags, 5 clear gray bags.
|
||||
bright chartreuse bags contain 2 light violet bags, 3 vibrant gray bags.
|
||||
plaid black bags contain 2 posh gray bags.
|
||||
light beige bags contain 4 dotted olive bags, 5 dull olive bags, 1 faded orange bag.
|
||||
mirrored teal bags contain 4 mirrored aqua bags.
|
||||
bright magenta bags contain 1 mirrored magenta bag, 3 bright blue bags, 1 vibrant blue bag, 2 drab gold bags.
|
||||
dim maroon bags contain 4 light bronze bags, 5 clear violet bags.
|
||||
light lime bags contain 4 plaid indigo bags.
|
||||
posh lavender bags contain 4 dark brown bags.
|
||||
clear beige bags contain 4 posh silver bags, 3 dull coral bags, 2 posh gray bags.
|
||||
drab bronze bags contain 4 plaid maroon bags.
|
||||
mirrored purple bags contain 3 dim magenta bags.
|
||||
dark magenta bags contain 4 faded maroon bags, 1 drab crimson bag, 5 dotted brown bags, 2 bright teal bags.
|
||||
dim brown bags contain 3 muted olive bags, 5 drab green bags, 1 mirrored olive bag.
|
||||
dark plum bags contain 2 vibrant tan bags.
|
||||
bright turquoise bags contain 1 mirrored aqua bag, 3 clear plum bags.
|
||||
muted black bags contain 5 faded cyan bags, 5 pale tan bags, 2 dotted chartreuse bags.
|
||||
dotted gray bags contain 3 posh plum bags.
|
||||
vibrant black bags contain 2 vibrant magenta bags, 5 faded cyan bags.
|
||||
mirrored cyan bags contain 2 clear cyan bags, 4 light aqua bags, 5 drab blue bags, 1 drab gold bag.
|
||||
wavy purple bags contain 5 striped magenta bags, 3 clear maroon bags, 1 mirrored green bag, 1 pale black bag.
|
||||
drab blue bags contain 3 mirrored lime bags, 1 mirrored blue bag.
|
||||
clear maroon bags contain 5 bright orange bags.
|
||||
shiny cyan bags contain 2 clear gray bags, 5 pale crimson bags.
|
||||
pale cyan bags contain 2 wavy turquoise bags, 5 wavy salmon bags.
|
||||
plaid gold bags contain 1 clear lavender bag, 1 bright beige bag.
|
||||
mirrored lime bags contain 2 dull tan bags, 3 shiny beige bags.
|
||||
drab green bags contain 1 vibrant yellow bag.
|
||||
dull red bags contain 5 plaid blue bags, 5 clear brown bags, 3 pale salmon bags, 2 dark orange bags.
|
||||
bright beige bags contain 4 dull silver bags, 5 vibrant brown bags, 4 drab red bags, 2 pale violet bags.
|
||||
clear silver bags contain 4 drab indigo bags, 2 clear salmon bags.
|
||||
posh bronze bags contain 5 bright indigo bags, 5 dotted purple bags, 1 dark violet bag, 2 dark orange bags.
|
||||
posh salmon bags contain 5 bright red bags, 3 striped green bags, 3 dark brown bags.
|
||||
clear cyan bags contain 5 dark chartreuse bags, 1 bright indigo bag, 4 pale yellow bags, 2 vibrant coral bags.
|
||||
mirrored blue bags contain 2 vibrant white bags.
|
||||
mirrored yellow bags contain 5 dotted gray bags, 4 dull maroon bags, 2 striped violet bags, 5 clear tomato bags.
|
||||
striped teal bags contain 2 clear black bags, 3 pale coral bags.
|
||||
faded orange bags contain 2 dark bronze bags.
|
||||
mirrored indigo bags contain 3 light tomato bags, 2 shiny crimson bags.
|
||||
pale green bags contain 4 light chartreuse bags.
|
||||
plaid cyan bags contain 4 plaid fuchsia bags, 2 shiny teal bags, 3 dotted fuchsia bags, 3 dim red bags.
|
||||
muted gold bags contain 2 dull tan bags, 1 faded bronze bag, 4 dull maroon bags.
|
||||
wavy green bags contain 5 pale coral bags, 1 dull blue bag, 4 drab blue bags, 1 striped tan bag.
|
||||
light chartreuse bags contain 4 striped brown bags, 5 plaid purple bags, 4 drab cyan bags, 3 dull plum bags.
|
||||
dotted cyan bags contain 4 shiny black bags.
|
||||
light purple bags contain no other bags.
|
||||
dotted aqua bags contain 4 light gray bags, 2 light purple bags, 5 mirrored lime bags.
|
||||
drab gold bags contain 2 bright green bags, 5 bright indigo bags.
|
||||
posh gray bags contain 5 bright orange bags, 5 bright blue bags.
|
||||
striped red bags contain 4 drab green bags, 1 clear cyan bag.
|
||||
dotted bronze bags contain 5 light orange bags.
|
||||
muted plum bags contain 2 bright black bags, 3 dotted tomato bags, 2 vibrant brown bags.
|
||||
mirrored black bags contain 3 plaid chartreuse bags, 2 shiny indigo bags, 2 shiny beige bags.
|
||||
drab lavender bags contain 5 drab cyan bags, 1 muted purple bag, 1 wavy red bag, 3 drab crimson bags.
|
||||
vibrant turquoise bags contain 3 shiny beige bags, 3 striped brown bags, 5 dim teal bags.
|
||||
muted tan bags contain 1 plaid purple bag, 3 shiny beige bags, 1 drab gold bag.
|
||||
pale beige bags contain 5 bright silver bags.
|
||||
wavy olive bags contain 4 dotted turquoise bags, 4 dull silver bags, 1 bright gold bag.
|
||||
dim olive bags contain 5 light lavender bags, 4 shiny tomato bags, 4 clear cyan bags.
|
||||
wavy salmon bags contain 4 bright aqua bags.
|
||||
dotted gold bags contain 3 shiny red bags, 3 dull fuchsia bags.
|
||||
shiny violet bags contain 3 dotted tomato bags, 1 drab coral bag.
|
||||
striped plum bags contain 4 drab beige bags, 3 clear tan bags, 5 light aqua bags, 1 shiny fuchsia bag.
|
||||
clear lavender bags contain 2 bright aqua bags, 3 dull silver bags, 3 bright green bags, 2 bright orange bags.
|
||||
faded maroon bags contain 5 dark indigo bags, 1 posh fuchsia bag.
|
||||
vibrant red bags contain 4 striped fuchsia bags, 3 drab orange bags, 1 clear brown bag, 1 plaid turquoise bag.
|
||||
dull coral bags contain 2 dim teal bags, 3 faded bronze bags.
|
||||
pale salmon bags contain 3 dull magenta bags, 1 light crimson bag.
|
||||
dotted magenta bags contain 4 dull maroon bags, 2 bright lime bags, 4 plaid indigo bags, 4 faded cyan bags.
|
||||
wavy gray bags contain 4 muted gray bags, 3 shiny magenta bags, 1 posh teal bag.
|
||||
light red bags contain 4 shiny chartreuse bags.
|
||||
dim blue bags contain 4 vibrant orange bags.
|
||||
muted bronze bags contain 5 mirrored aqua bags, 4 dim green bags.
|
||||
drab lime bags contain 1 drab cyan bag, 3 pale crimson bags, 4 bright green bags, 3 drab lavender bags.
|
||||
light white bags contain 5 bright green bags.
|
||||
bright teal bags contain 4 shiny brown bags, 4 dark silver bags.
|
||||
striped beige bags contain 2 shiny magenta bags.
|
||||
wavy magenta bags contain 5 pale bronze bags, 5 pale plum bags, 3 muted silver bags.
|
||||
dark orange bags contain 1 drab tomato bag, 3 striped brown bags, 1 dim teal bag, 5 bright beige bags.
|
||||
striped indigo bags contain 1 vibrant gold bag, 1 shiny green bag.
|
||||
clear coral bags contain 2 shiny gray bags.
|
||||
faded yellow bags contain 4 faded gold bags, 2 bright turquoise bags, 5 dark silver bags, 3 wavy coral bags.
|
||||
dim plum bags contain 1 clear purple bag, 4 light brown bags.
|
||||
mirrored turquoise bags contain 5 wavy indigo bags, 3 dark fuchsia bags, 5 plaid white bags, 2 dim turquoise bags.
|
||||
posh black bags contain 2 striped black bags, 5 dim teal bags, 3 bright silver bags, 5 posh beige bags.
|
||||
dotted fuchsia bags contain 1 faded turquoise bag, 2 shiny lavender bags, 4 posh salmon bags, 1 clear olive bag.
|
||||
faded lavender bags contain 2 striped yellow bags, 1 posh lavender bag.
|
||||
dim lime bags contain 2 wavy gray bags, 5 clear gray bags.
|
||||
vibrant bronze bags contain 3 drab tomato bags, 5 bright tan bags.
|
||||
dull plum bags contain 5 bright red bags, 4 dull magenta bags.
|
||||
dim teal bags contain 4 light purple bags, 4 plaid lavender bags, 1 dull magenta bag.
|
||||
dull yellow bags contain 4 vibrant orange bags, 1 dark tomato bag, 5 pale tan bags.
|
||||
dull green bags contain 2 bright blue bags, 5 dull red bags.
|
||||
light crimson bags contain 5 dull maroon bags, 4 muted gold bags.
|
||||
dark black bags contain 1 dim silver bag, 3 plaid magenta bags.
|
||||
bright lavender bags contain 4 muted fuchsia bags.
|
||||
drab coral bags contain 4 shiny chartreuse bags, 3 posh yellow bags, 3 wavy indigo bags.
|
||||
mirrored crimson bags contain 3 posh maroon bags, 5 striped olive bags, 3 mirrored magenta bags.
|
||||
muted coral bags contain 3 wavy violet bags, 1 dotted chartreuse bag, 1 shiny beige bag.
|
||||
vibrant gold bags contain 2 dull orange bags, 1 clear chartreuse bag.
|
||||
wavy orange bags contain 5 dark bronze bags.
|
||||
mirrored white bags contain 5 clear gold bags, 3 drab tomato bags, 4 dotted bronze bags, 3 striped orange bags.
|
||||
clear gold bags contain 3 drab indigo bags, 4 wavy violet bags, 2 shiny salmon bags, 4 light brown bags.
|
||||
shiny magenta bags contain 5 drab silver bags, 2 muted gold bags.
|
||||
dim violet bags contain 1 posh lime bag, 4 shiny orange bags, 2 posh chartreuse bags.
|
||||
striped olive bags contain 4 plaid indigo bags, 5 dim chartreuse bags, 4 clear lavender bags.
|
||||
plaid gray bags contain 3 shiny gold bags, 2 dull coral bags.
|
||||
clear crimson bags contain 4 shiny aqua bags, 3 light crimson bags, 5 dim chartreuse bags.
|
||||
drab silver bags contain 1 dim teal bag, 3 faded cyan bags, 1 shiny indigo bag.
|
||||
mirrored green bags contain 5 dotted lime bags, 4 pale cyan bags.
|
||||
bright aqua bags contain no other bags.
|
||||
bright plum bags contain 4 dim aqua bags, 2 dull crimson bags, 1 wavy maroon bag.
|
||||
vibrant lavender bags contain 1 plaid tan bag, 3 vibrant brown bags, 3 drab gold bags, 4 faded red bags.
|
||||
pale white bags contain 3 bright brown bags, 4 mirrored beige bags.
|
||||
plaid lavender bags contain 1 dull magenta bag, 2 dull silver bags, 1 shiny indigo bag.
|
||||
bright salmon bags contain 1 striped coral bag, 4 plaid lavender bags, 1 muted red bag, 1 drab red bag.
|
||||
plaid olive bags contain 5 faded turquoise bags, 4 dim green bags, 2 striped beige bags.
|
||||
wavy plum bags contain 1 clear lavender bag, 2 faded brown bags.
|
||||
clear fuchsia bags contain 1 muted bronze bag.
|
||||
wavy turquoise bags contain 5 shiny lime bags, 1 drab olive bag, 4 dim white bags, 1 dotted gray bag.
|
||||
vibrant aqua bags contain 2 faded lavender bags.
|
||||
dotted white bags contain 3 muted crimson bags, 5 mirrored white bags, 1 mirrored fuchsia bag.
|
||||
bright purple bags contain 2 dotted chartreuse bags, 4 posh cyan bags, 3 bright plum bags.
|
||||
light aqua bags contain 1 plaid lavender bag, 3 wavy coral bags, 5 shiny indigo bags.
|
||||
drab yellow bags contain 4 shiny teal bags, 2 dotted green bags, 5 vibrant silver bags, 3 dotted turquoise bags.
|
||||
mirrored olive bags contain 1 dull plum bag.
|
||||
light olive bags contain 1 shiny coral bag, 4 drab white bags, 3 dim turquoise bags, 4 dull gold bags.
|
||||
shiny indigo bags contain no other bags.
|
||||
dull gold bags contain 3 dark indigo bags.
|
||||
bright tomato bags contain 5 muted blue bags.
|
||||
faded purple bags contain 4 bright orange bags, 2 faded violet bags.
|
||||
drab magenta bags contain 3 wavy lavender bags, 2 drab cyan bags, 2 clear beige bags, 4 bright indigo bags.
|
||||
striped lime bags contain 4 light tan bags.
|
||||
light gold bags contain 2 pale plum bags.
|
||||
striped black bags contain 1 plaid salmon bag, 2 plaid beige bags, 4 dotted teal bags, 2 posh chartreuse bags.
|
||||
faded tomato bags contain 2 striped yellow bags, 4 muted red bags.
|
||||
dull fuchsia bags contain 5 dotted olive bags, 2 muted purple bags.
|
||||
pale purple bags contain 4 posh silver bags, 4 wavy yellow bags.
|
||||
bright olive bags contain 5 shiny fuchsia bags, 5 dull crimson bags, 5 drab red bags, 5 posh turquoise bags.
|
||||
vibrant fuchsia bags contain 1 vibrant beige bag, 5 shiny magenta bags.
|
||||
faded turquoise bags contain 5 light lime bags, 4 dark white bags.
|
||||
plaid orange bags contain 5 vibrant coral bags, 4 light crimson bags, 4 plaid chartreuse bags, 1 dull green bag.
|
||||
posh indigo bags contain 3 wavy green bags, 2 shiny orange bags, 5 faded violet bags, 2 dotted coral bags.
|
||||
mirrored red bags contain 4 mirrored olive bags, 1 dark silver bag, 1 dull red bag.
|
||||
dim salmon bags contain 1 striped salmon bag, 5 faded gray bags.
|
||||
dim cyan bags contain 3 wavy olive bags, 5 drab purple bags, 3 mirrored bronze bags.
|
||||
light blue bags contain 2 striped bronze bags, 4 dull white bags, 1 posh bronze bag.
|
||||
dull turquoise bags contain 4 striped red bags, 1 light lavender bag, 5 plaid bronze bags, 1 mirrored brown bag.
|
||||
vibrant coral bags contain 1 bright orange bag.
|
||||
striped cyan bags contain 2 dark white bags, 4 drab red bags, 2 plaid salmon bags.
|
||||
muted tomato bags contain 4 drab red bags, 3 vibrant silver bags, 4 clear fuchsia bags, 3 wavy white bags.
|
||||
dotted red bags contain 1 light blue bag.
|
||||
dark beige bags contain 2 posh lime bags, 3 striped black bags.
|
||||
dark cyan bags contain 1 dim chartreuse bag, 2 shiny beige bags, 4 dotted magenta bags, 4 light chartreuse bags.
|
||||
dull lime bags contain 3 muted chartreuse bags.
|
||||
light brown bags contain 3 mirrored brown bags.
|
||||
vibrant magenta bags contain 1 dim green bag.
|
||||
shiny brown bags contain 5 bright brown bags, 3 faded cyan bags, 5 clear tan bags, 2 plaid maroon bags.
|
||||
drab purple bags contain 1 shiny indigo bag, 4 striped yellow bags.
|
66
2020/d07/ex2/ex2.py
Executable file
66
2020/d07/ex2/ex2.py
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Set, Tuple
|
||||
|
||||
|
||||
@dataclass(eq=True, frozen=True) # Hashable
|
||||
class ColorInfo:
|
||||
num: int
|
||||
color: str
|
||||
|
||||
|
||||
Graph = Dict[str, Set[ColorInfo]]
|
||||
|
||||
|
||||
def extract_info(line: str) -> Tuple[str, Set[ColorInfo]]:
|
||||
color_pattern = re.compile("(.*) contain ")
|
||||
match = color_pattern.search(line)
|
||||
assert match is not None
|
||||
color = match.group(1).replace("bags", "bag")
|
||||
|
||||
line = line[match.end() : -1] # Remove period at end of line
|
||||
|
||||
if line == "no other bags":
|
||||
return color, set()
|
||||
|
||||
colors: Set[ColorInfo] = set()
|
||||
pattern = re.compile("([0-9]+) (.*)")
|
||||
for col in line.split(", "):
|
||||
match = pattern.search(col)
|
||||
assert match is not None
|
||||
colors |= {
|
||||
ColorInfo(int(match.group(1)), match.group(2).replace("bags", "bag"))
|
||||
}
|
||||
|
||||
return color, colors
|
||||
|
||||
|
||||
def to_graph(raw: List[str]) -> Graph:
|
||||
return {color: inside for color, inside in map(extract_info, raw)}
|
||||
|
||||
|
||||
def num_bags(graph: Graph, col: str) -> int:
|
||||
return sum(
|
||||
contained.num * (1 + num_bags(graph, contained.color))
|
||||
for contained in graph[col]
|
||||
)
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
graph = to_graph(raw)
|
||||
|
||||
return num_bags(graph, "shiny gold bag")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
594
2020/d07/ex2/input
Normal file
594
2020/d07/ex2/input
Normal file
|
@ -0,0 +1,594 @@
|
|||
shiny aqua bags contain 1 dark white bag.
|
||||
muted blue bags contain 1 vibrant lavender bag, 4 dotted silver bags, 2 dim indigo bags.
|
||||
drab gray bags contain 5 mirrored white bags, 1 light green bag, 5 shiny lavender bags, 5 faded aqua bags.
|
||||
muted indigo bags contain 4 muted chartreuse bags, 2 dotted teal bags.
|
||||
drab white bags contain 2 dull fuchsia bags, 1 vibrant bronze bag.
|
||||
dim lavender bags contain 4 muted tan bags.
|
||||
dotted tomato bags contain 1 mirrored lime bag, 2 vibrant white bags.
|
||||
clear orange bags contain 5 clear violet bags, 2 dull beige bags, 2 dark chartreuse bags.
|
||||
bright lime bags contain no other bags.
|
||||
striped brown bags contain 3 bright orange bags.
|
||||
vibrant green bags contain 3 shiny fuchsia bags.
|
||||
plaid tomato bags contain 3 faded chartreuse bags, 2 wavy salmon bags, 1 faded white bag, 3 mirrored maroon bags.
|
||||
drab beige bags contain 2 shiny bronze bags, 4 pale violet bags, 3 bright tomato bags, 4 pale red bags.
|
||||
posh green bags contain 2 dull lavender bags, 4 clear plum bags, 2 dark gray bags.
|
||||
dull maroon bags contain 3 dull magenta bags, 1 dull tan bag, 1 faded cyan bag, 5 dull silver bags.
|
||||
faded crimson bags contain 2 muted purple bags, 4 dotted olive bags, 5 drab silver bags.
|
||||
wavy bronze bags contain 3 dark orange bags, 2 dark brown bags, 5 bright silver bags.
|
||||
dark turquoise bags contain 5 dull plum bags.
|
||||
dull lavender bags contain 4 dotted maroon bags, 3 muted brown bags, 4 drab black bags, 4 dull cyan bags.
|
||||
dotted plum bags contain 1 shiny bronze bag, 3 clear brown bags, 3 muted indigo bags.
|
||||
dull white bags contain 3 clear tan bags, 5 shiny gold bags, 2 drab crimson bags.
|
||||
dull teal bags contain 2 bright tomato bags.
|
||||
shiny crimson bags contain 3 light green bags, 5 striped brown bags, 3 faded fuchsia bags.
|
||||
wavy brown bags contain 1 drab crimson bag, 2 wavy indigo bags.
|
||||
dark tan bags contain 2 faded gray bags, 4 shiny salmon bags.
|
||||
shiny red bags contain 4 dull chartreuse bags, 5 pale tomato bags.
|
||||
bright orange bags contain no other bags.
|
||||
wavy yellow bags contain 5 light indigo bags, 5 dark gray bags, 5 plaid indigo bags, 4 faded red bags.
|
||||
faded bronze bags contain 4 faded cyan bags, 5 shiny beige bags, 5 muted red bags.
|
||||
dull bronze bags contain 1 mirrored beige bag, 5 muted violet bags, 1 wavy lime bag.
|
||||
dark lime bags contain 2 drab maroon bags, 5 bright indigo bags, 4 shiny black bags, 5 dotted turquoise bags.
|
||||
drab red bags contain 5 bright red bags, 2 vibrant brown bags.
|
||||
dotted salmon bags contain 3 vibrant turquoise bags, 2 dull beige bags, 3 light turquoise bags.
|
||||
dull gray bags contain 3 striped green bags, 3 wavy coral bags, 1 dark gray bag, 2 light indigo bags.
|
||||
faded black bags contain 4 muted fuchsia bags, 4 wavy coral bags, 1 drab tomato bag.
|
||||
muted magenta bags contain 2 posh chartreuse bags, 4 pale violet bags.
|
||||
light tan bags contain 2 posh turquoise bags, 3 vibrant white bags, 1 light black bag.
|
||||
dark blue bags contain 3 plaid indigo bags, 2 posh black bags.
|
||||
dull indigo bags contain 4 light gray bags, 3 dotted tan bags, 4 dull coral bags.
|
||||
dim fuchsia bags contain 3 vibrant yellow bags, 3 mirrored cyan bags, 4 mirrored brown bags.
|
||||
shiny beige bags contain 2 dull silver bags, 3 bright lime bags, 5 dull magenta bags.
|
||||
light cyan bags contain 3 vibrant violet bags, 2 mirrored tomato bags, 2 vibrant coral bags, 4 mirrored silver bags.
|
||||
clear turquoise bags contain 4 drab tomato bags, 3 shiny gold bags, 4 drab gold bags.
|
||||
pale teal bags contain 2 wavy maroon bags, 2 dotted olive bags, 4 shiny white bags, 2 drab turquoise bags.
|
||||
dark purple bags contain 1 wavy indigo bag, 3 bright black bags, 3 dotted teal bags.
|
||||
bright white bags contain 5 wavy red bags, 2 mirrored cyan bags, 3 drab green bags.
|
||||
mirrored aqua bags contain 1 faded violet bag, 5 dotted purple bags.
|
||||
shiny lime bags contain 4 dark aqua bags.
|
||||
pale bronze bags contain 1 clear crimson bag.
|
||||
vibrant white bags contain 5 plaid lavender bags, 1 drab red bag, 4 vibrant brown bags.
|
||||
plaid tan bags contain 5 dim crimson bags.
|
||||
posh olive bags contain 3 bright red bags.
|
||||
plaid brown bags contain 5 vibrant turquoise bags.
|
||||
mirrored tomato bags contain 2 dotted chartreuse bags, 3 light aqua bags, 3 posh beige bags.
|
||||
plaid blue bags contain 5 striped green bags, 1 plaid purple bag, 4 muted gold bags.
|
||||
shiny tan bags contain 5 striped coral bags, 1 dull brown bag.
|
||||
shiny gold bags contain 1 dull magenta bag, 5 dark white bags, 4 faded turquoise bags.
|
||||
dull salmon bags contain 2 plaid gold bags, 2 light indigo bags.
|
||||
striped tomato bags contain 2 striped tan bags, 4 light blue bags, 4 drab tan bags.
|
||||
drab tomato bags contain 3 dim teal bags, 4 striped yellow bags, 3 bright red bags.
|
||||
faded olive bags contain 1 drab plum bag, 1 pale aqua bag, 3 light blue bags.
|
||||
dotted indigo bags contain 2 clear tomato bags.
|
||||
dark white bags contain 5 light aqua bags, 2 dim teal bags, 2 muted fuchsia bags, 5 light purple bags.
|
||||
dull orange bags contain 4 pale gold bags, 5 posh brown bags, 2 mirrored brown bags, 3 dark bronze bags.
|
||||
bright maroon bags contain 1 mirrored yellow bag, 4 light teal bags.
|
||||
bright silver bags contain 1 vibrant coral bag, 3 dim teal bags, 5 light purple bags.
|
||||
muted olive bags contain 5 plaid orange bags, 1 muted magenta bag.
|
||||
dull silver bags contain no other bags.
|
||||
pale maroon bags contain 2 pale bronze bags.
|
||||
light gray bags contain 4 vibrant yellow bags, 2 pale red bags.
|
||||
drab teal bags contain 2 light crimson bags, 3 vibrant brown bags, 3 vibrant tan bags.
|
||||
bright gold bags contain 1 wavy red bag, 5 wavy coral bags.
|
||||
plaid chartreuse bags contain 2 dim coral bags, 4 drab silver bags, 5 dim chartreuse bags, 3 light purple bags.
|
||||
clear blue bags contain 2 pale tomato bags, 4 dull gold bags, 4 dim fuchsia bags, 4 pale coral bags.
|
||||
vibrant purple bags contain 5 faded orange bags.
|
||||
plaid aqua bags contain 3 muted cyan bags, 2 wavy gray bags, 4 drab green bags, 4 pale beige bags.
|
||||
muted lime bags contain 1 muted tan bag.
|
||||
faded coral bags contain 3 drab turquoise bags, 1 shiny plum bag, 5 mirrored green bags, 5 clear white bags.
|
||||
vibrant lime bags contain 5 posh coral bags.
|
||||
faded green bags contain 3 pale orange bags, 5 dull turquoise bags, 1 mirrored crimson bag.
|
||||
mirrored gray bags contain 5 dim indigo bags.
|
||||
wavy maroon bags contain 4 mirrored bronze bags, 1 striped olive bag, 2 dull salmon bags, 3 shiny crimson bags.
|
||||
dark violet bags contain 2 light purple bags.
|
||||
dark green bags contain 2 dim cyan bags.
|
||||
pale black bags contain 1 mirrored gold bag.
|
||||
bright yellow bags contain 2 vibrant crimson bags, 3 plaid lime bags, 2 dotted gold bags.
|
||||
muted teal bags contain 1 pale violet bag, 4 dull silver bags.
|
||||
dim beige bags contain 5 wavy red bags.
|
||||
muted purple bags contain 4 clear cyan bags.
|
||||
plaid fuchsia bags contain 3 dark coral bags.
|
||||
plaid bronze bags contain 5 plaid orange bags, 2 drab indigo bags.
|
||||
faded indigo bags contain 1 dark chartreuse bag, 4 dull green bags, 1 mirrored magenta bag.
|
||||
posh plum bags contain 3 dark chartreuse bags, 3 dotted turquoise bags, 4 dull maroon bags, 1 posh bronze bag.
|
||||
pale gold bags contain 4 striped brown bags.
|
||||
mirrored chartreuse bags contain 4 bright silver bags, 3 mirrored tomato bags, 4 wavy orange bags.
|
||||
pale orange bags contain 2 posh fuchsia bags, 2 clear salmon bags, 2 bright green bags.
|
||||
clear brown bags contain 4 light lime bags, 4 bright green bags, 5 pale yellow bags, 2 drab cyan bags.
|
||||
shiny plum bags contain 5 vibrant gray bags, 3 bright blue bags, 5 dark tomato bags.
|
||||
wavy white bags contain 4 plaid lime bags, 4 posh maroon bags, 5 drab lime bags, 1 vibrant crimson bag.
|
||||
faded red bags contain 1 dull coral bag, 5 clear cyan bags, 4 plaid chartreuse bags, 3 plaid orange bags.
|
||||
plaid red bags contain 5 pale blue bags, 4 light crimson bags, 3 faded fuchsia bags.
|
||||
bright cyan bags contain 3 dark white bags, 2 light crimson bags, 1 bright aqua bag.
|
||||
muted lavender bags contain 1 light green bag, 4 striped silver bags, 3 posh crimson bags.
|
||||
wavy crimson bags contain 1 light purple bag, 4 bright blue bags, 2 dull coral bags, 1 wavy beige bag.
|
||||
faded aqua bags contain 5 muted brown bags.
|
||||
mirrored fuchsia bags contain 1 faded beige bag, 3 muted gold bags.
|
||||
dark chartreuse bags contain 5 bright lime bags.
|
||||
plaid green bags contain 4 mirrored tan bags, 1 mirrored tomato bag, 5 pale indigo bags, 1 mirrored plum bag.
|
||||
shiny black bags contain 3 plaid chartreuse bags.
|
||||
dotted purple bags contain 2 dim teal bags.
|
||||
faded tan bags contain 2 bright fuchsia bags, 5 shiny fuchsia bags, 1 muted fuchsia bag, 1 mirrored brown bag.
|
||||
drab brown bags contain 1 striped orange bag, 4 dotted tomato bags.
|
||||
dull olive bags contain 1 striped black bag, 1 vibrant magenta bag.
|
||||
mirrored plum bags contain 1 clear gold bag, 5 pale green bags.
|
||||
dim tomato bags contain 4 drab gold bags, 2 shiny aqua bags.
|
||||
light lavender bags contain 1 muted violet bag.
|
||||
dim gray bags contain 3 light purple bags, 1 posh crimson bag, 1 faded brown bag.
|
||||
muted aqua bags contain 4 dull beige bags, 4 dull red bags.
|
||||
faded silver bags contain 1 mirrored cyan bag.
|
||||
shiny green bags contain 5 dull maroon bags.
|
||||
muted chartreuse bags contain 2 clear tan bags.
|
||||
plaid plum bags contain 1 dotted lime bag, 4 clear brown bags, 4 dull red bags.
|
||||
dotted silver bags contain 1 posh coral bag.
|
||||
dim crimson bags contain 4 faded violet bags, 1 striped silver bag.
|
||||
bright brown bags contain 1 bright coral bag, 3 posh brown bags, 4 drab tan bags.
|
||||
wavy cyan bags contain 3 clear gold bags, 1 mirrored salmon bag, 3 bright fuchsia bags, 2 light bronze bags.
|
||||
dull violet bags contain 5 striped white bags, 4 light blue bags, 4 dim black bags.
|
||||
vibrant olive bags contain 2 vibrant coral bags.
|
||||
bright coral bags contain 2 vibrant tan bags, 3 shiny indigo bags, 2 plaid indigo bags.
|
||||
dim turquoise bags contain 1 pale violet bag.
|
||||
striped crimson bags contain 2 faded gray bags.
|
||||
clear green bags contain 3 mirrored olive bags, 3 shiny tomato bags.
|
||||
faded violet bags contain 2 wavy coral bags, 2 dull tan bags, 1 dull silver bag, 1 bright orange bag.
|
||||
pale chartreuse bags contain 4 shiny crimson bags, 2 clear bronze bags.
|
||||
light plum bags contain 3 drab bronze bags, 1 bright bronze bag, 1 posh yellow bag.
|
||||
pale tomato bags contain 1 dim teal bag, 5 drab cyan bags, 3 muted coral bags, 2 dim chartreuse bags.
|
||||
plaid coral bags contain 1 striped tan bag, 3 vibrant cyan bags, 3 light beige bags, 2 dotted green bags.
|
||||
bright gray bags contain 4 mirrored teal bags, 4 striped brown bags, 1 dim green bag, 4 clear cyan bags.
|
||||
drab fuchsia bags contain 2 mirrored salmon bags, 4 posh orange bags, 3 faded crimson bags, 3 pale plum bags.
|
||||
light tomato bags contain 2 dotted gold bags, 1 dotted bronze bag.
|
||||
muted violet bags contain 2 light chartreuse bags.
|
||||
drab tan bags contain 2 light green bags, 5 bright red bags, 4 shiny beige bags.
|
||||
drab chartreuse bags contain 2 drab salmon bags, 2 dark brown bags, 4 clear turquoise bags.
|
||||
drab violet bags contain 4 faded red bags.
|
||||
posh cyan bags contain 4 bright violet bags.
|
||||
posh orange bags contain 4 pale plum bags, 5 posh aqua bags.
|
||||
plaid silver bags contain 1 dotted brown bag, 3 drab gold bags, 4 clear yellow bags.
|
||||
mirrored silver bags contain 3 shiny beige bags, 1 drab silver bag.
|
||||
faded gray bags contain no other bags.
|
||||
wavy tomato bags contain 1 bright brown bag, 3 striped red bags, 2 vibrant maroon bags.
|
||||
posh violet bags contain 2 dim aqua bags.
|
||||
bright blue bags contain 5 light lime bags, 2 faded violet bags, 3 light aqua bags, 4 vibrant coral bags.
|
||||
dark teal bags contain 5 muted fuchsia bags.
|
||||
striped fuchsia bags contain 1 wavy turquoise bag, 5 wavy green bags, 4 posh gold bags.
|
||||
posh maroon bags contain 2 dull red bags.
|
||||
shiny purple bags contain 2 clear tan bags.
|
||||
wavy lime bags contain 2 dark coral bags, 1 shiny gold bag.
|
||||
wavy silver bags contain 4 dotted white bags.
|
||||
shiny silver bags contain 2 plaid gold bags, 2 dim green bags, 5 plaid lime bags, 3 dull red bags.
|
||||
wavy red bags contain 3 vibrant brown bags, 4 bright indigo bags.
|
||||
dull chartreuse bags contain 4 dotted lime bags, 2 bright silver bags, 3 dull red bags, 4 wavy maroon bags.
|
||||
vibrant silver bags contain 1 bright fuchsia bag, 3 drab lavender bags, 2 drab olive bags, 3 dotted teal bags.
|
||||
striped gray bags contain 5 plaid orange bags, 1 wavy coral bag.
|
||||
striped green bags contain 4 wavy coral bags, 4 shiny gold bags, 3 dark brown bags, 5 vibrant brown bags.
|
||||
mirrored violet bags contain 3 dim silver bags, 1 posh tomato bag, 1 light salmon bag.
|
||||
dull purple bags contain 1 light gray bag, 3 wavy yellow bags, 1 wavy salmon bag.
|
||||
mirrored beige bags contain 4 dark cyan bags, 5 dull green bags.
|
||||
posh lime bags contain 3 posh chartreuse bags.
|
||||
vibrant tan bags contain 2 dull plum bags, 1 striped brown bag, 4 vibrant coral bags.
|
||||
dotted orange bags contain 1 mirrored olive bag, 5 drab silver bags.
|
||||
clear indigo bags contain 3 light lime bags, 4 dull coral bags.
|
||||
pale gray bags contain 1 faded black bag, 3 dim green bags, 4 wavy lavender bags, 2 posh brown bags.
|
||||
posh gold bags contain 5 dark tan bags, 2 dotted olive bags, 5 dark aqua bags.
|
||||
striped chartreuse bags contain 2 dull magenta bags, 1 posh tomato bag.
|
||||
mirrored bronze bags contain 2 faded fuchsia bags.
|
||||
clear salmon bags contain 4 posh bronze bags, 5 clear plum bags, 5 dull blue bags.
|
||||
posh purple bags contain 5 dim gray bags, 3 faded brown bags.
|
||||
faded lime bags contain 5 dim turquoise bags, 3 dark indigo bags, 2 vibrant gray bags, 1 muted silver bag.
|
||||
wavy beige bags contain 1 dark bronze bag, 4 dull plum bags, 4 mirrored silver bags.
|
||||
clear yellow bags contain 2 vibrant teal bags.
|
||||
vibrant plum bags contain 4 muted chartreuse bags, 4 posh silver bags.
|
||||
striped yellow bags contain 2 dull maroon bags, 5 bright red bags, 2 posh chartreuse bags.
|
||||
dark coral bags contain 3 dull tan bags.
|
||||
dull magenta bags contain no other bags.
|
||||
dark gold bags contain 1 dotted indigo bag, 4 shiny teal bags, 4 dotted silver bags.
|
||||
dim tan bags contain 1 striped lavender bag, 1 shiny tomato bag.
|
||||
muted maroon bags contain 2 dull salmon bags, 4 dim chartreuse bags, 3 bright aqua bags, 2 faded indigo bags.
|
||||
vibrant tomato bags contain 2 dark silver bags, 3 plaid purple bags.
|
||||
dotted lime bags contain 3 shiny crimson bags, 2 pale yellow bags.
|
||||
muted fuchsia bags contain 1 dull tan bag.
|
||||
bright tan bags contain 5 pale gold bags, 5 drab teal bags, 2 light blue bags.
|
||||
dark crimson bags contain 4 shiny orange bags, 3 faded purple bags, 3 bright white bags.
|
||||
striped tan bags contain 4 dotted turquoise bags, 4 drab lime bags, 5 dim teal bags.
|
||||
posh fuchsia bags contain 2 dotted olive bags, 2 mirrored beige bags, 3 shiny bronze bags.
|
||||
pale silver bags contain 4 vibrant lavender bags, 4 clear beige bags, 4 striped gold bags.
|
||||
posh aqua bags contain 4 drab lime bags, 4 dull tan bags, 5 vibrant tan bags.
|
||||
plaid salmon bags contain 5 dim coral bags, 2 wavy bronze bags.
|
||||
mirrored orange bags contain 4 vibrant gray bags.
|
||||
dim yellow bags contain 5 pale tan bags, 4 dark black bags.
|
||||
dotted coral bags contain 4 dotted chartreuse bags, 2 bright red bags, 1 vibrant white bag, 1 vibrant brown bag.
|
||||
muted crimson bags contain 4 striped orange bags, 5 pale yellow bags, 3 posh blue bags, 1 muted red bag.
|
||||
striped lavender bags contain 3 striped brown bags.
|
||||
striped maroon bags contain 2 shiny yellow bags.
|
||||
vibrant blue bags contain 3 faded cyan bags, 1 shiny lime bag, 3 dark tomato bags.
|
||||
pale lavender bags contain 4 plaid magenta bags, 4 striped blue bags.
|
||||
dull tan bags contain 4 shiny indigo bags, 2 light purple bags, 4 faded cyan bags.
|
||||
dotted beige bags contain 3 drab indigo bags.
|
||||
light indigo bags contain 1 faded cyan bag, 5 bright aqua bags, 1 shiny indigo bag.
|
||||
vibrant crimson bags contain 4 dotted fuchsia bags.
|
||||
wavy blue bags contain 4 wavy teal bags, 1 dull blue bag.
|
||||
vibrant chartreuse bags contain 4 striped orange bags.
|
||||
vibrant cyan bags contain 5 wavy coral bags.
|
||||
faded brown bags contain 5 faded turquoise bags.
|
||||
faded magenta bags contain 1 dull indigo bag, 4 plaid aqua bags, 4 dim crimson bags.
|
||||
mirrored coral bags contain 4 drab crimson bags, 2 light salmon bags, 2 clear indigo bags.
|
||||
faded cyan bags contain no other bags.
|
||||
dark brown bags contain 5 light purple bags.
|
||||
wavy violet bags contain 3 dull coral bags, 1 bright aqua bag, 3 shiny lavender bags.
|
||||
posh tomato bags contain 4 vibrant chartreuse bags, 4 mirrored teal bags.
|
||||
pale crimson bags contain 1 plaid orange bag, 1 dark violet bag, 3 plaid lavender bags.
|
||||
dark fuchsia bags contain 4 plaid beige bags, 2 plaid chartreuse bags.
|
||||
plaid magenta bags contain 3 clear lavender bags, 5 mirrored brown bags, 5 shiny bronze bags.
|
||||
striped blue bags contain 1 dull bronze bag, 1 dotted fuchsia bag, 1 light lavender bag, 1 clear turquoise bag.
|
||||
dotted olive bags contain 4 dotted turquoise bags, 5 dotted bronze bags, 3 pale yellow bags, 4 pale red bags.
|
||||
posh silver bags contain 3 pale violet bags, 1 plaid salmon bag, 1 posh coral bag.
|
||||
dotted chartreuse bags contain 3 bright blue bags.
|
||||
light coral bags contain 4 shiny fuchsia bags, 2 pale red bags, 1 muted silver bag, 2 bright cyan bags.
|
||||
pale brown bags contain 5 light aqua bags.
|
||||
dotted black bags contain 2 plaid purple bags, 1 mirrored aqua bag, 5 posh beige bags.
|
||||
posh coral bags contain 3 dark aqua bags, 2 pale yellow bags, 5 plaid blue bags, 4 dim aqua bags.
|
||||
shiny gray bags contain 1 bright gold bag, 1 muted bronze bag, 5 striped green bags, 5 shiny teal bags.
|
||||
drab orange bags contain 5 plaid salmon bags, 2 vibrant beige bags.
|
||||
plaid yellow bags contain 4 clear teal bags, 2 bright red bags.
|
||||
striped violet bags contain 4 mirrored fuchsia bags, 4 vibrant white bags, 3 dim teal bags.
|
||||
dim aqua bags contain 1 muted fuchsia bag, 1 dull tan bag.
|
||||
light orange bags contain 2 bright red bags, 4 dark white bags, 1 dim chartreuse bag, 5 faded fuchsia bags.
|
||||
faded salmon bags contain 5 wavy gray bags.
|
||||
shiny yellow bags contain 2 vibrant plum bags, 3 dim teal bags, 1 plaid tan bag, 5 posh plum bags.
|
||||
vibrant beige bags contain 2 wavy lavender bags, 4 posh chartreuse bags, 3 pale teal bags, 5 wavy lime bags.
|
||||
light fuchsia bags contain 3 clear brown bags, 3 bright lavender bags.
|
||||
pale magenta bags contain 4 posh silver bags.
|
||||
dark maroon bags contain 3 drab turquoise bags.
|
||||
faded beige bags contain 1 vibrant white bag, 4 drab red bags, 1 drab lavender bag.
|
||||
bright bronze bags contain 1 pale bronze bag, 3 muted silver bags, 2 striped coral bags, 3 clear gray bags.
|
||||
light silver bags contain 3 dotted lavender bags, 2 wavy lavender bags.
|
||||
muted salmon bags contain 2 drab tan bags, 5 wavy tomato bags.
|
||||
bright black bags contain 5 plaid tan bags.
|
||||
dim chartreuse bags contain 5 muted gold bags, 5 bright blue bags, 5 faded cyan bags.
|
||||
shiny white bags contain 4 bright tan bags.
|
||||
bright red bags contain 3 dull silver bags.
|
||||
dark aqua bags contain 2 dull red bags.
|
||||
drab plum bags contain 4 muted brown bags, 5 muted plum bags.
|
||||
muted yellow bags contain 5 light purple bags, 3 dotted silver bags, 3 faded turquoise bags.
|
||||
light violet bags contain 1 pale red bag, 4 dim silver bags, 2 mirrored bronze bags.
|
||||
pale lime bags contain 4 bright lavender bags.
|
||||
pale tan bags contain 4 striped green bags, 2 dotted chartreuse bags.
|
||||
dim green bags contain 1 light lime bag, 1 shiny beige bag.
|
||||
mirrored gold bags contain 4 mirrored white bags.
|
||||
dim silver bags contain 5 pale coral bags, 3 wavy coral bags.
|
||||
dull aqua bags contain 3 posh indigo bags, 5 dotted coral bags, 1 dark salmon bag, 3 striped crimson bags.
|
||||
posh yellow bags contain 1 dark bronze bag, 2 mirrored white bags, 2 light crimson bags.
|
||||
mirrored magenta bags contain 1 bright violet bag, 2 drab lavender bags, 3 pale violet bags, 2 plaid salmon bags.
|
||||
shiny chartreuse bags contain 2 dotted purple bags, 5 wavy red bags, 3 plaid beige bags.
|
||||
light black bags contain 1 dark chartreuse bag, 3 faded tomato bags.
|
||||
clear plum bags contain 5 vibrant brown bags, 3 dim coral bags, 4 mirrored brown bags, 1 faded black bag.
|
||||
pale violet bags contain 2 dull tan bags.
|
||||
bright fuchsia bags contain 4 dull orange bags.
|
||||
dotted teal bags contain 5 bright red bags, 3 wavy red bags, 1 dull coral bag, 3 clear plum bags.
|
||||
dotted blue bags contain 2 wavy beige bags, 3 muted purple bags.
|
||||
muted gray bags contain 3 faded aqua bags, 1 shiny olive bag, 5 clear salmon bags, 1 vibrant violet bag.
|
||||
dull beige bags contain 1 wavy lavender bag, 4 dark bronze bags, 5 dull tan bags.
|
||||
drab turquoise bags contain 3 posh gray bags, 5 drab red bags.
|
||||
vibrant yellow bags contain 2 shiny aqua bags, 4 light chartreuse bags.
|
||||
posh brown bags contain 3 bright green bags, 5 posh lavender bags.
|
||||
faded gold bags contain 4 vibrant maroon bags, 4 dotted purple bags.
|
||||
dotted turquoise bags contain 5 clear plum bags, 3 muted gold bags, 4 dark violet bags.
|
||||
dotted tan bags contain 5 dim aqua bags, 4 striped violet bags.
|
||||
posh crimson bags contain 4 striped blue bags, 5 dull magenta bags, 2 bright coral bags.
|
||||
muted white bags contain 5 dull olive bags.
|
||||
vibrant teal bags contain 5 dotted turquoise bags, 1 striped tan bag, 1 drab tan bag.
|
||||
dotted yellow bags contain 3 plaid turquoise bags, 2 posh yellow bags, 4 striped blue bags, 5 posh black bags.
|
||||
posh magenta bags contain 5 mirrored black bags.
|
||||
dotted green bags contain 4 dim crimson bags, 1 shiny lavender bag, 4 bright salmon bags, 1 plaid gray bag.
|
||||
bright green bags contain 3 bright aqua bags, 3 dull maroon bags, 4 dark brown bags.
|
||||
dark gray bags contain 5 muted purple bags, 2 striped blue bags, 4 faded lavender bags.
|
||||
bright crimson bags contain 2 striped olive bags, 3 muted blue bags.
|
||||
muted cyan bags contain 3 shiny tomato bags.
|
||||
light yellow bags contain 2 striped red bags, 4 shiny crimson bags.
|
||||
pale aqua bags contain 5 shiny yellow bags, 3 dark lavender bags, 3 posh white bags.
|
||||
clear red bags contain 1 dotted silver bag, 1 dull teal bag, 1 faded maroon bag, 1 dotted salmon bag.
|
||||
pale red bags contain 2 faded gray bags.
|
||||
dotted maroon bags contain 5 posh aqua bags, 3 dull silver bags.
|
||||
dull blue bags contain 4 light crimson bags, 3 light lime bags, 1 dark orange bag, 5 light indigo bags.
|
||||
posh turquoise bags contain 1 muted gold bag, 5 striped lavender bags, 3 dull salmon bags, 5 vibrant chartreuse bags.
|
||||
striped magenta bags contain 1 posh silver bag, 5 dark brown bags.
|
||||
pale blue bags contain 2 muted gold bags, 4 vibrant brown bags, 1 light lavender bag.
|
||||
vibrant violet bags contain 5 bright red bags.
|
||||
faded fuchsia bags contain 2 light lime bags, 4 bright lime bags, 3 pale violet bags.
|
||||
shiny coral bags contain 1 clear plum bag, 5 muted chartreuse bags, 1 muted violet bag, 5 striped yellow bags.
|
||||
pale olive bags contain 4 plaid lime bags, 1 posh salmon bag.
|
||||
wavy tan bags contain 3 faded gray bags.
|
||||
faded chartreuse bags contain 3 dim coral bags, 1 mirrored bronze bag, 3 posh bronze bags.
|
||||
mirrored brown bags contain 1 faded violet bag, 4 dull maroon bags, 5 dotted magenta bags.
|
||||
clear white bags contain 5 muted magenta bags, 4 dull magenta bags, 3 pale plum bags, 4 drab indigo bags.
|
||||
drab maroon bags contain 2 clear beige bags, 3 wavy beige bags, 5 faded purple bags.
|
||||
striped silver bags contain 3 drab tomato bags.
|
||||
faded plum bags contain 1 clear teal bag, 3 bright aqua bags.
|
||||
plaid violet bags contain 2 drab violet bags, 4 muted turquoise bags, 5 muted indigo bags.
|
||||
clear black bags contain 5 muted fuchsia bags, 1 muted coral bag, 2 light black bags.
|
||||
vibrant maroon bags contain 1 dark lavender bag, 1 pale crimson bag, 4 bright indigo bags, 5 mirrored maroon bags.
|
||||
drab indigo bags contain 2 dim coral bags, 1 drab green bag, 2 shiny lavender bags.
|
||||
drab olive bags contain 2 dark aqua bags, 4 striped brown bags.
|
||||
dull crimson bags contain 3 dull cyan bags.
|
||||
wavy teal bags contain 4 striped orange bags, 2 drab cyan bags.
|
||||
dark red bags contain 2 dull maroon bags, 4 muted plum bags, 4 dull plum bags.
|
||||
striped salmon bags contain 3 bright red bags, 1 light aqua bag, 4 wavy gold bags.
|
||||
mirrored tan bags contain 5 dotted olive bags, 2 dim tomato bags, 2 mirrored tomato bags, 4 clear teal bags.
|
||||
striped white bags contain 2 pale coral bags, 2 shiny green bags.
|
||||
shiny tomato bags contain 5 pale coral bags, 5 dull beige bags.
|
||||
vibrant indigo bags contain 2 dim black bags, 4 dim blue bags, 3 dim white bags.
|
||||
wavy lavender bags contain 4 faded bronze bags, 4 muted red bags, 3 light lime bags, 4 muted gold bags.
|
||||
shiny turquoise bags contain 2 dull red bags, 5 faded gray bags, 1 muted turquoise bag.
|
||||
shiny lavender bags contain 5 bright aqua bags.
|
||||
posh tan bags contain 1 shiny yellow bag, 3 drab magenta bags.
|
||||
light green bags contain 4 bright red bags, 1 vibrant coral bag.
|
||||
drab black bags contain 5 faded tomato bags, 3 dotted chartreuse bags.
|
||||
clear chartreuse bags contain 3 wavy bronze bags, 4 plaid purple bags, 3 dark orange bags.
|
||||
dull black bags contain 1 wavy teal bag, 3 light lavender bags, 2 striped indigo bags.
|
||||
wavy black bags contain 2 clear orange bags, 4 muted purple bags.
|
||||
pale plum bags contain 1 bright coral bag, 1 drab tan bag, 1 plaid fuchsia bag, 1 dotted fuchsia bag.
|
||||
dotted violet bags contain 3 bright black bags.
|
||||
posh red bags contain 3 bright black bags.
|
||||
plaid lime bags contain 5 posh beige bags, 1 dotted turquoise bag.
|
||||
wavy aqua bags contain 1 dark yellow bag, 3 drab indigo bags.
|
||||
dim magenta bags contain 3 dark violet bags.
|
||||
drab aqua bags contain 5 posh orange bags, 1 dark silver bag, 4 plaid purple bags, 2 wavy teal bags.
|
||||
dull brown bags contain 4 light lime bags.
|
||||
striped orange bags contain 5 light crimson bags, 3 muted tan bags, 5 dotted coral bags, 3 plaid blue bags.
|
||||
muted brown bags contain 1 posh blue bag, 4 dotted magenta bags, 3 dull coral bags.
|
||||
faded blue bags contain 5 striped black bags, 1 vibrant yellow bag.
|
||||
plaid indigo bags contain 3 dark brown bags, 5 light purple bags, 4 light aqua bags, 3 light green bags.
|
||||
plaid turquoise bags contain 5 dotted teal bags.
|
||||
light turquoise bags contain 2 dull salmon bags, 5 dotted tan bags.
|
||||
dim purple bags contain 4 muted white bags, 5 drab purple bags.
|
||||
pale coral bags contain 5 posh gray bags.
|
||||
clear lime bags contain 3 dim magenta bags, 3 plaid tomato bags, 1 drab magenta bag, 3 shiny purple bags.
|
||||
dim black bags contain 3 clear gold bags, 4 muted violet bags.
|
||||
light maroon bags contain 4 muted yellow bags, 1 pale cyan bag, 2 mirrored turquoise bags, 4 dull lavender bags.
|
||||
clear magenta bags contain 2 shiny magenta bags, 2 muted chartreuse bags.
|
||||
striped bronze bags contain 5 clear tan bags, 1 drab lavender bag, 2 pale crimson bags.
|
||||
dark salmon bags contain 1 vibrant plum bag, 5 drab tan bags, 4 drab coral bags, 4 dull tan bags.
|
||||
vibrant salmon bags contain 2 muted olive bags.
|
||||
dim gold bags contain 2 dim olive bags, 5 plaid olive bags, 2 posh orange bags.
|
||||
wavy chartreuse bags contain 4 shiny yellow bags, 4 vibrant blue bags.
|
||||
vibrant brown bags contain 3 striped brown bags, 4 muted red bags, 2 shiny indigo bags.
|
||||
plaid maroon bags contain 2 muted teal bags, 2 pale yellow bags, 2 bright beige bags, 5 striped yellow bags.
|
||||
dim indigo bags contain 4 dull tomato bags, 4 clear cyan bags, 2 shiny salmon bags, 1 bright aqua bag.
|
||||
muted red bags contain 3 dull tan bags, 4 dull magenta bags, 1 bright aqua bag.
|
||||
posh beige bags contain 5 shiny black bags, 3 dotted magenta bags, 3 drab blue bags, 2 muted coral bags.
|
||||
pale fuchsia bags contain 3 dark brown bags, 5 posh gold bags.
|
||||
dark bronze bags contain 1 dim green bag, 5 posh chartreuse bags.
|
||||
dim coral bags contain 3 dull coral bags, 3 striped brown bags.
|
||||
drab crimson bags contain 2 dark bronze bags, 4 shiny indigo bags, 3 dull tan bags.
|
||||
bright indigo bags contain 3 bright blue bags.
|
||||
pale yellow bags contain 5 dim aqua bags, 1 vibrant brown bag, 2 vibrant tan bags, 3 wavy lavender bags.
|
||||
drab salmon bags contain 1 dotted indigo bag, 3 muted chartreuse bags, 5 dark olive bags.
|
||||
muted orange bags contain 4 faded lime bags, 2 dull coral bags, 5 vibrant magenta bags, 4 dull magenta bags.
|
||||
striped gold bags contain 2 dull silver bags, 5 bright lavender bags, 5 dim teal bags, 5 dark coral bags.
|
||||
posh chartreuse bags contain 3 dim teal bags, 5 light aqua bags.
|
||||
shiny blue bags contain 3 dull tan bags, 5 muted magenta bags.
|
||||
muted silver bags contain 3 wavy blue bags, 2 dim teal bags, 5 muted bronze bags.
|
||||
shiny bronze bags contain 1 light green bag, 4 vibrant magenta bags.
|
||||
wavy coral bags contain no other bags.
|
||||
shiny orange bags contain 2 muted purple bags.
|
||||
posh teal bags contain 4 clear plum bags.
|
||||
striped turquoise bags contain 3 muted indigo bags.
|
||||
dim bronze bags contain 2 shiny silver bags, 1 light silver bag, 2 dim indigo bags, 4 dim tomato bags.
|
||||
plaid white bags contain 4 drab turquoise bags.
|
||||
wavy indigo bags contain 3 clear gold bags, 5 mirrored bronze bags.
|
||||
faded teal bags contain 4 mirrored white bags.
|
||||
shiny fuchsia bags contain 3 drab indigo bags.
|
||||
dim red bags contain 3 clear bronze bags.
|
||||
dotted brown bags contain 4 wavy maroon bags, 5 drab green bags, 3 dark purple bags.
|
||||
dark tomato bags contain 3 vibrant coral bags, 5 dull coral bags, 2 drab cyan bags, 1 posh blue bag.
|
||||
clear teal bags contain 3 dark white bags.
|
||||
dark silver bags contain 3 dark cyan bags, 4 plaid salmon bags.
|
||||
wavy fuchsia bags contain 4 bright brown bags, 4 bright aqua bags, 5 light orange bags.
|
||||
light bronze bags contain 4 clear plum bags.
|
||||
striped purple bags contain 1 dim indigo bag.
|
||||
clear tomato bags contain 4 mirrored tomato bags, 3 muted indigo bags, 1 striped tan bag.
|
||||
muted turquoise bags contain 5 faded beige bags, 4 clear crimson bags, 2 bright teal bags.
|
||||
dull cyan bags contain 5 mirrored aqua bags, 2 shiny aqua bags, 3 light black bags, 4 bright coral bags.
|
||||
plaid crimson bags contain 2 mirrored teal bags, 2 dull fuchsia bags.
|
||||
shiny maroon bags contain 1 posh gold bag.
|
||||
dim white bags contain 5 striped brown bags, 2 dull magenta bags, 5 plaid tan bags.
|
||||
muted green bags contain 2 dull magenta bags, 5 clear cyan bags.
|
||||
plaid teal bags contain 2 dark tan bags, 3 pale lime bags.
|
||||
dotted lavender bags contain 2 posh aqua bags, 3 dull cyan bags.
|
||||
light salmon bags contain 5 dark silver bags.
|
||||
faded white bags contain 2 wavy maroon bags, 3 dull cyan bags.
|
||||
dull tomato bags contain 2 dim aqua bags, 4 posh lavender bags, 1 faded red bag.
|
||||
dark olive bags contain 5 clear bronze bags, 2 drab plum bags.
|
||||
pale indigo bags contain 2 mirrored beige bags, 5 wavy turquoise bags, 4 striped green bags, 2 dotted lavender bags.
|
||||
plaid purple bags contain 1 light lime bag.
|
||||
clear purple bags contain 3 vibrant white bags.
|
||||
dark yellow bags contain 2 pale olive bags, 4 pale cyan bags, 5 bright teal bags.
|
||||
muted beige bags contain 2 posh lime bags, 5 shiny gray bags, 2 dull blue bags.
|
||||
vibrant orange bags contain 5 posh crimson bags, 4 light chartreuse bags.
|
||||
light magenta bags contain 2 plaid maroon bags, 1 posh beige bag, 5 pale salmon bags.
|
||||
dotted crimson bags contain 5 dark chartreuse bags.
|
||||
striped coral bags contain 2 dim aqua bags.
|
||||
striped aqua bags contain 3 posh salmon bags, 3 dull red bags.
|
||||
mirrored salmon bags contain 5 bright red bags, 2 light green bags, 3 clear black bags, 5 posh brown bags.
|
||||
posh white bags contain 4 drab violet bags, 2 dotted silver bags.
|
||||
posh blue bags contain 4 dull maroon bags, 3 vibrant coral bags.
|
||||
dim orange bags contain 2 dull olive bags.
|
||||
shiny teal bags contain 1 faded tomato bag, 4 muted violet bags.
|
||||
mirrored maroon bags contain 3 dull blue bags.
|
||||
dark lavender bags contain 1 drab red bag, 3 shiny indigo bags, 4 faded beige bags, 1 drab turquoise bag.
|
||||
shiny olive bags contain 3 dark violet bags, 1 striped gold bag, 2 mirrored lime bags.
|
||||
bright violet bags contain 2 wavy bronze bags, 3 drab olive bags, 5 mirrored olive bags, 2 wavy lavender bags.
|
||||
clear olive bags contain 5 faded turquoise bags.
|
||||
mirrored lavender bags contain 1 light white bag, 4 light purple bags, 3 wavy lavender bags, 2 shiny lime bags.
|
||||
pale turquoise bags contain 4 dark tan bags.
|
||||
shiny salmon bags contain 1 shiny gold bag, 5 drab turquoise bags.
|
||||
vibrant gray bags contain 3 posh brown bags.
|
||||
dark indigo bags contain 1 mirrored black bag, 5 dull beige bags, 4 shiny beige bags, 3 drab lavender bags.
|
||||
light teal bags contain 5 dark olive bags, 5 vibrant chartreuse bags, 3 plaid salmon bags, 5 light yellow bags.
|
||||
clear violet bags contain 3 light crimson bags.
|
||||
clear tan bags contain 3 striped orange bags, 4 wavy lavender bags, 3 striped silver bags.
|
||||
clear bronze bags contain 2 plaid beige bags.
|
||||
clear gray bags contain 4 dotted cyan bags, 4 vibrant plum bags.
|
||||
drab cyan bags contain 1 light aqua bag, 1 drab teal bag, 3 bright orange bags, 3 dark white bags.
|
||||
plaid beige bags contain 3 dull green bags.
|
||||
wavy gold bags contain 4 shiny olive bags, 3 bright tan bags.
|
||||
clear aqua bags contain 3 posh chartreuse bags, 4 drab silver bags, 5 clear gray bags.
|
||||
bright chartreuse bags contain 2 light violet bags, 3 vibrant gray bags.
|
||||
plaid black bags contain 2 posh gray bags.
|
||||
light beige bags contain 4 dotted olive bags, 5 dull olive bags, 1 faded orange bag.
|
||||
mirrored teal bags contain 4 mirrored aqua bags.
|
||||
bright magenta bags contain 1 mirrored magenta bag, 3 bright blue bags, 1 vibrant blue bag, 2 drab gold bags.
|
||||
dim maroon bags contain 4 light bronze bags, 5 clear violet bags.
|
||||
light lime bags contain 4 plaid indigo bags.
|
||||
posh lavender bags contain 4 dark brown bags.
|
||||
clear beige bags contain 4 posh silver bags, 3 dull coral bags, 2 posh gray bags.
|
||||
drab bronze bags contain 4 plaid maroon bags.
|
||||
mirrored purple bags contain 3 dim magenta bags.
|
||||
dark magenta bags contain 4 faded maroon bags, 1 drab crimson bag, 5 dotted brown bags, 2 bright teal bags.
|
||||
dim brown bags contain 3 muted olive bags, 5 drab green bags, 1 mirrored olive bag.
|
||||
dark plum bags contain 2 vibrant tan bags.
|
||||
bright turquoise bags contain 1 mirrored aqua bag, 3 clear plum bags.
|
||||
muted black bags contain 5 faded cyan bags, 5 pale tan bags, 2 dotted chartreuse bags.
|
||||
dotted gray bags contain 3 posh plum bags.
|
||||
vibrant black bags contain 2 vibrant magenta bags, 5 faded cyan bags.
|
||||
mirrored cyan bags contain 2 clear cyan bags, 4 light aqua bags, 5 drab blue bags, 1 drab gold bag.
|
||||
wavy purple bags contain 5 striped magenta bags, 3 clear maroon bags, 1 mirrored green bag, 1 pale black bag.
|
||||
drab blue bags contain 3 mirrored lime bags, 1 mirrored blue bag.
|
||||
clear maroon bags contain 5 bright orange bags.
|
||||
shiny cyan bags contain 2 clear gray bags, 5 pale crimson bags.
|
||||
pale cyan bags contain 2 wavy turquoise bags, 5 wavy salmon bags.
|
||||
plaid gold bags contain 1 clear lavender bag, 1 bright beige bag.
|
||||
mirrored lime bags contain 2 dull tan bags, 3 shiny beige bags.
|
||||
drab green bags contain 1 vibrant yellow bag.
|
||||
dull red bags contain 5 plaid blue bags, 5 clear brown bags, 3 pale salmon bags, 2 dark orange bags.
|
||||
bright beige bags contain 4 dull silver bags, 5 vibrant brown bags, 4 drab red bags, 2 pale violet bags.
|
||||
clear silver bags contain 4 drab indigo bags, 2 clear salmon bags.
|
||||
posh bronze bags contain 5 bright indigo bags, 5 dotted purple bags, 1 dark violet bag, 2 dark orange bags.
|
||||
posh salmon bags contain 5 bright red bags, 3 striped green bags, 3 dark brown bags.
|
||||
clear cyan bags contain 5 dark chartreuse bags, 1 bright indigo bag, 4 pale yellow bags, 2 vibrant coral bags.
|
||||
mirrored blue bags contain 2 vibrant white bags.
|
||||
mirrored yellow bags contain 5 dotted gray bags, 4 dull maroon bags, 2 striped violet bags, 5 clear tomato bags.
|
||||
striped teal bags contain 2 clear black bags, 3 pale coral bags.
|
||||
faded orange bags contain 2 dark bronze bags.
|
||||
mirrored indigo bags contain 3 light tomato bags, 2 shiny crimson bags.
|
||||
pale green bags contain 4 light chartreuse bags.
|
||||
plaid cyan bags contain 4 plaid fuchsia bags, 2 shiny teal bags, 3 dotted fuchsia bags, 3 dim red bags.
|
||||
muted gold bags contain 2 dull tan bags, 1 faded bronze bag, 4 dull maroon bags.
|
||||
wavy green bags contain 5 pale coral bags, 1 dull blue bag, 4 drab blue bags, 1 striped tan bag.
|
||||
light chartreuse bags contain 4 striped brown bags, 5 plaid purple bags, 4 drab cyan bags, 3 dull plum bags.
|
||||
dotted cyan bags contain 4 shiny black bags.
|
||||
light purple bags contain no other bags.
|
||||
dotted aqua bags contain 4 light gray bags, 2 light purple bags, 5 mirrored lime bags.
|
||||
drab gold bags contain 2 bright green bags, 5 bright indigo bags.
|
||||
posh gray bags contain 5 bright orange bags, 5 bright blue bags.
|
||||
striped red bags contain 4 drab green bags, 1 clear cyan bag.
|
||||
dotted bronze bags contain 5 light orange bags.
|
||||
muted plum bags contain 2 bright black bags, 3 dotted tomato bags, 2 vibrant brown bags.
|
||||
mirrored black bags contain 3 plaid chartreuse bags, 2 shiny indigo bags, 2 shiny beige bags.
|
||||
drab lavender bags contain 5 drab cyan bags, 1 muted purple bag, 1 wavy red bag, 3 drab crimson bags.
|
||||
vibrant turquoise bags contain 3 shiny beige bags, 3 striped brown bags, 5 dim teal bags.
|
||||
muted tan bags contain 1 plaid purple bag, 3 shiny beige bags, 1 drab gold bag.
|
||||
pale beige bags contain 5 bright silver bags.
|
||||
wavy olive bags contain 4 dotted turquoise bags, 4 dull silver bags, 1 bright gold bag.
|
||||
dim olive bags contain 5 light lavender bags, 4 shiny tomato bags, 4 clear cyan bags.
|
||||
wavy salmon bags contain 4 bright aqua bags.
|
||||
dotted gold bags contain 3 shiny red bags, 3 dull fuchsia bags.
|
||||
shiny violet bags contain 3 dotted tomato bags, 1 drab coral bag.
|
||||
striped plum bags contain 4 drab beige bags, 3 clear tan bags, 5 light aqua bags, 1 shiny fuchsia bag.
|
||||
clear lavender bags contain 2 bright aqua bags, 3 dull silver bags, 3 bright green bags, 2 bright orange bags.
|
||||
faded maroon bags contain 5 dark indigo bags, 1 posh fuchsia bag.
|
||||
vibrant red bags contain 4 striped fuchsia bags, 3 drab orange bags, 1 clear brown bag, 1 plaid turquoise bag.
|
||||
dull coral bags contain 2 dim teal bags, 3 faded bronze bags.
|
||||
pale salmon bags contain 3 dull magenta bags, 1 light crimson bag.
|
||||
dotted magenta bags contain 4 dull maroon bags, 2 bright lime bags, 4 plaid indigo bags, 4 faded cyan bags.
|
||||
wavy gray bags contain 4 muted gray bags, 3 shiny magenta bags, 1 posh teal bag.
|
||||
light red bags contain 4 shiny chartreuse bags.
|
||||
dim blue bags contain 4 vibrant orange bags.
|
||||
muted bronze bags contain 5 mirrored aqua bags, 4 dim green bags.
|
||||
drab lime bags contain 1 drab cyan bag, 3 pale crimson bags, 4 bright green bags, 3 drab lavender bags.
|
||||
light white bags contain 5 bright green bags.
|
||||
bright teal bags contain 4 shiny brown bags, 4 dark silver bags.
|
||||
striped beige bags contain 2 shiny magenta bags.
|
||||
wavy magenta bags contain 5 pale bronze bags, 5 pale plum bags, 3 muted silver bags.
|
||||
dark orange bags contain 1 drab tomato bag, 3 striped brown bags, 1 dim teal bag, 5 bright beige bags.
|
||||
striped indigo bags contain 1 vibrant gold bag, 1 shiny green bag.
|
||||
clear coral bags contain 2 shiny gray bags.
|
||||
faded yellow bags contain 4 faded gold bags, 2 bright turquoise bags, 5 dark silver bags, 3 wavy coral bags.
|
||||
dim plum bags contain 1 clear purple bag, 4 light brown bags.
|
||||
mirrored turquoise bags contain 5 wavy indigo bags, 3 dark fuchsia bags, 5 plaid white bags, 2 dim turquoise bags.
|
||||
posh black bags contain 2 striped black bags, 5 dim teal bags, 3 bright silver bags, 5 posh beige bags.
|
||||
dotted fuchsia bags contain 1 faded turquoise bag, 2 shiny lavender bags, 4 posh salmon bags, 1 clear olive bag.
|
||||
faded lavender bags contain 2 striped yellow bags, 1 posh lavender bag.
|
||||
dim lime bags contain 2 wavy gray bags, 5 clear gray bags.
|
||||
vibrant bronze bags contain 3 drab tomato bags, 5 bright tan bags.
|
||||
dull plum bags contain 5 bright red bags, 4 dull magenta bags.
|
||||
dim teal bags contain 4 light purple bags, 4 plaid lavender bags, 1 dull magenta bag.
|
||||
dull yellow bags contain 4 vibrant orange bags, 1 dark tomato bag, 5 pale tan bags.
|
||||
dull green bags contain 2 bright blue bags, 5 dull red bags.
|
||||
light crimson bags contain 5 dull maroon bags, 4 muted gold bags.
|
||||
dark black bags contain 1 dim silver bag, 3 plaid magenta bags.
|
||||
bright lavender bags contain 4 muted fuchsia bags.
|
||||
drab coral bags contain 4 shiny chartreuse bags, 3 posh yellow bags, 3 wavy indigo bags.
|
||||
mirrored crimson bags contain 3 posh maroon bags, 5 striped olive bags, 3 mirrored magenta bags.
|
||||
muted coral bags contain 3 wavy violet bags, 1 dotted chartreuse bag, 1 shiny beige bag.
|
||||
vibrant gold bags contain 2 dull orange bags, 1 clear chartreuse bag.
|
||||
wavy orange bags contain 5 dark bronze bags.
|
||||
mirrored white bags contain 5 clear gold bags, 3 drab tomato bags, 4 dotted bronze bags, 3 striped orange bags.
|
||||
clear gold bags contain 3 drab indigo bags, 4 wavy violet bags, 2 shiny salmon bags, 4 light brown bags.
|
||||
shiny magenta bags contain 5 drab silver bags, 2 muted gold bags.
|
||||
dim violet bags contain 1 posh lime bag, 4 shiny orange bags, 2 posh chartreuse bags.
|
||||
striped olive bags contain 4 plaid indigo bags, 5 dim chartreuse bags, 4 clear lavender bags.
|
||||
plaid gray bags contain 3 shiny gold bags, 2 dull coral bags.
|
||||
clear crimson bags contain 4 shiny aqua bags, 3 light crimson bags, 5 dim chartreuse bags.
|
||||
drab silver bags contain 1 dim teal bag, 3 faded cyan bags, 1 shiny indigo bag.
|
||||
mirrored green bags contain 5 dotted lime bags, 4 pale cyan bags.
|
||||
bright aqua bags contain no other bags.
|
||||
bright plum bags contain 4 dim aqua bags, 2 dull crimson bags, 1 wavy maroon bag.
|
||||
vibrant lavender bags contain 1 plaid tan bag, 3 vibrant brown bags, 3 drab gold bags, 4 faded red bags.
|
||||
pale white bags contain 3 bright brown bags, 4 mirrored beige bags.
|
||||
plaid lavender bags contain 1 dull magenta bag, 2 dull silver bags, 1 shiny indigo bag.
|
||||
bright salmon bags contain 1 striped coral bag, 4 plaid lavender bags, 1 muted red bag, 1 drab red bag.
|
||||
plaid olive bags contain 5 faded turquoise bags, 4 dim green bags, 2 striped beige bags.
|
||||
wavy plum bags contain 1 clear lavender bag, 2 faded brown bags.
|
||||
clear fuchsia bags contain 1 muted bronze bag.
|
||||
wavy turquoise bags contain 5 shiny lime bags, 1 drab olive bag, 4 dim white bags, 1 dotted gray bag.
|
||||
vibrant aqua bags contain 2 faded lavender bags.
|
||||
dotted white bags contain 3 muted crimson bags, 5 mirrored white bags, 1 mirrored fuchsia bag.
|
||||
bright purple bags contain 2 dotted chartreuse bags, 4 posh cyan bags, 3 bright plum bags.
|
||||
light aqua bags contain 1 plaid lavender bag, 3 wavy coral bags, 5 shiny indigo bags.
|
||||
drab yellow bags contain 4 shiny teal bags, 2 dotted green bags, 5 vibrant silver bags, 3 dotted turquoise bags.
|
||||
mirrored olive bags contain 1 dull plum bag.
|
||||
light olive bags contain 1 shiny coral bag, 4 drab white bags, 3 dim turquoise bags, 4 dull gold bags.
|
||||
shiny indigo bags contain no other bags.
|
||||
dull gold bags contain 3 dark indigo bags.
|
||||
bright tomato bags contain 5 muted blue bags.
|
||||
faded purple bags contain 4 bright orange bags, 2 faded violet bags.
|
||||
drab magenta bags contain 3 wavy lavender bags, 2 drab cyan bags, 2 clear beige bags, 4 bright indigo bags.
|
||||
striped lime bags contain 4 light tan bags.
|
||||
light gold bags contain 2 pale plum bags.
|
||||
striped black bags contain 1 plaid salmon bag, 2 plaid beige bags, 4 dotted teal bags, 2 posh chartreuse bags.
|
||||
faded tomato bags contain 2 striped yellow bags, 4 muted red bags.
|
||||
dull fuchsia bags contain 5 dotted olive bags, 2 muted purple bags.
|
||||
pale purple bags contain 4 posh silver bags, 4 wavy yellow bags.
|
||||
bright olive bags contain 5 shiny fuchsia bags, 5 dull crimson bags, 5 drab red bags, 5 posh turquoise bags.
|
||||
vibrant fuchsia bags contain 1 vibrant beige bag, 5 shiny magenta bags.
|
||||
faded turquoise bags contain 5 light lime bags, 4 dark white bags.
|
||||
plaid orange bags contain 5 vibrant coral bags, 4 light crimson bags, 4 plaid chartreuse bags, 1 dull green bag.
|
||||
posh indigo bags contain 3 wavy green bags, 2 shiny orange bags, 5 faded violet bags, 2 dotted coral bags.
|
||||
mirrored red bags contain 4 mirrored olive bags, 1 dark silver bag, 1 dull red bag.
|
||||
dim salmon bags contain 1 striped salmon bag, 5 faded gray bags.
|
||||
dim cyan bags contain 3 wavy olive bags, 5 drab purple bags, 3 mirrored bronze bags.
|
||||
light blue bags contain 2 striped bronze bags, 4 dull white bags, 1 posh bronze bag.
|
||||
dull turquoise bags contain 4 striped red bags, 1 light lavender bag, 5 plaid bronze bags, 1 mirrored brown bag.
|
||||
vibrant coral bags contain 1 bright orange bag.
|
||||
striped cyan bags contain 2 dark white bags, 4 drab red bags, 2 plaid salmon bags.
|
||||
muted tomato bags contain 4 drab red bags, 3 vibrant silver bags, 4 clear fuchsia bags, 3 wavy white bags.
|
||||
dotted red bags contain 1 light blue bag.
|
||||
dark beige bags contain 2 posh lime bags, 3 striped black bags.
|
||||
dark cyan bags contain 1 dim chartreuse bag, 2 shiny beige bags, 4 dotted magenta bags, 4 light chartreuse bags.
|
||||
dull lime bags contain 3 muted chartreuse bags.
|
||||
light brown bags contain 3 mirrored brown bags.
|
||||
vibrant magenta bags contain 1 dim green bag.
|
||||
shiny brown bags contain 5 bright brown bags, 3 faded cyan bags, 5 clear tan bags, 2 plaid maroon bags.
|
||||
drab purple bags contain 1 shiny indigo bag, 4 striped yellow bags.
|
51
2020/d08/ex1/ex1.py
Executable file
51
2020/d08/ex1/ex1.py
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import sys
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def run(code: List[Tuple[str, int]]) -> int:
|
||||
accumulator = 0
|
||||
rip = 0
|
||||
|
||||
def acc(val: int) -> None:
|
||||
nonlocal accumulator
|
||||
nonlocal rip
|
||||
accumulator += val
|
||||
rip += 1
|
||||
|
||||
def nop(val: int) -> None:
|
||||
nonlocal rip
|
||||
rip += 1
|
||||
|
||||
def jmp(val: int) -> None:
|
||||
nonlocal rip
|
||||
rip += val
|
||||
|
||||
instrs = {
|
||||
"acc": acc,
|
||||
"jmp": jmp,
|
||||
"nop": nop,
|
||||
}
|
||||
seen = set()
|
||||
|
||||
while rip not in seen:
|
||||
seen |= {rip}
|
||||
func = instrs[code[rip][0]]
|
||||
func(code[rip][1])
|
||||
|
||||
return accumulator
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return run([(line[:3], int(line[3:])) for line in raw])
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
675
2020/d08/ex1/input
Normal file
675
2020/d08/ex1/input
Normal file
|
@ -0,0 +1,675 @@
|
|||
acc -8
|
||||
jmp +5
|
||||
acc +0
|
||||
acc +44
|
||||
acc +42
|
||||
jmp +324
|
||||
acc -17
|
||||
jmp +1
|
||||
acc -17
|
||||
jmp +51
|
||||
acc -13
|
||||
acc +4
|
||||
jmp +1
|
||||
nop +608
|
||||
jmp +274
|
||||
acc -17
|
||||
jmp +169
|
||||
acc +28
|
||||
nop +508
|
||||
jmp +1
|
||||
jmp +570
|
||||
acc +22
|
||||
acc -14
|
||||
jmp +377
|
||||
acc -13
|
||||
acc +27
|
||||
jmp +474
|
||||
acc -5
|
||||
jmp +1
|
||||
acc +12
|
||||
jmp +37
|
||||
jmp +184
|
||||
acc +36
|
||||
acc +32
|
||||
acc -8
|
||||
jmp +465
|
||||
acc -13
|
||||
acc +18
|
||||
jmp +169
|
||||
acc +20
|
||||
acc +26
|
||||
acc +23
|
||||
jmp +333
|
||||
jmp +584
|
||||
acc +9
|
||||
acc +28
|
||||
acc +28
|
||||
nop +571
|
||||
jmp +143
|
||||
acc +39
|
||||
acc +39
|
||||
acc -16
|
||||
jmp +361
|
||||
acc +48
|
||||
acc +3
|
||||
acc +15
|
||||
nop +4
|
||||
jmp +504
|
||||
acc +6
|
||||
jmp +285
|
||||
acc +26
|
||||
acc +33
|
||||
jmp +1
|
||||
acc +36
|
||||
jmp +577
|
||||
acc +36
|
||||
jmp +6
|
||||
nop +498
|
||||
acc +42
|
||||
jmp +496
|
||||
acc +10
|
||||
jmp +74
|
||||
acc +17
|
||||
acc +16
|
||||
acc +30
|
||||
jmp +254
|
||||
acc -3
|
||||
acc +16
|
||||
acc -2
|
||||
nop +106
|
||||
jmp +541
|
||||
acc -15
|
||||
jmp +579
|
||||
jmp +165
|
||||
acc +22
|
||||
acc -6
|
||||
acc +29
|
||||
acc -19
|
||||
jmp +342
|
||||
acc -19
|
||||
jmp +340
|
||||
acc +13
|
||||
acc +25
|
||||
acc +29
|
||||
jmp +269
|
||||
acc -14
|
||||
acc +27
|
||||
acc +41
|
||||
acc +49
|
||||
jmp +181
|
||||
nop +350
|
||||
jmp +1
|
||||
nop +437
|
||||
acc +34
|
||||
jmp +494
|
||||
acc +19
|
||||
acc +2
|
||||
acc +44
|
||||
jmp +558
|
||||
acc +10
|
||||
jmp +44
|
||||
nop +4
|
||||
nop -80
|
||||
nop +540
|
||||
jmp +16
|
||||
acc +28
|
||||
jmp +14
|
||||
acc +13
|
||||
nop +399
|
||||
acc +29
|
||||
nop -60
|
||||
jmp -6
|
||||
acc +41
|
||||
acc +30
|
||||
jmp +232
|
||||
acc +28
|
||||
nop +495
|
||||
acc +15
|
||||
acc +48
|
||||
jmp +157
|
||||
nop +483
|
||||
jmp -59
|
||||
acc +5
|
||||
acc +30
|
||||
acc +30
|
||||
acc +2
|
||||
jmp +349
|
||||
acc +11
|
||||
acc +27
|
||||
acc +1
|
||||
jmp +367
|
||||
acc +8
|
||||
acc +45
|
||||
acc +11
|
||||
jmp +171
|
||||
jmp -113
|
||||
acc +48
|
||||
jmp -38
|
||||
acc +12
|
||||
jmp +145
|
||||
acc +8
|
||||
nop +29
|
||||
nop +319
|
||||
jmp +154
|
||||
nop +166
|
||||
jmp +395
|
||||
nop +15
|
||||
jmp +237
|
||||
acc +22
|
||||
acc +3
|
||||
acc +42
|
||||
acc +1
|
||||
jmp +288
|
||||
jmp -63
|
||||
nop +489
|
||||
acc +33
|
||||
jmp +247
|
||||
jmp +1
|
||||
acc -8
|
||||
acc +9
|
||||
jmp +413
|
||||
acc -17
|
||||
acc +3
|
||||
acc +3
|
||||
jmp +432
|
||||
nop -17
|
||||
acc +36
|
||||
nop +198
|
||||
acc +45
|
||||
jmp +109
|
||||
nop +242
|
||||
acc +40
|
||||
acc +11
|
||||
jmp +448
|
||||
jmp +437
|
||||
acc +3
|
||||
acc +49
|
||||
acc +27
|
||||
jmp +221
|
||||
nop +158
|
||||
jmp +143
|
||||
acc +50
|
||||
jmp -70
|
||||
acc +46
|
||||
acc +8
|
||||
acc +35
|
||||
acc -3
|
||||
jmp +104
|
||||
acc +11
|
||||
acc +0
|
||||
jmp +34
|
||||
nop +132
|
||||
jmp +425
|
||||
jmp +219
|
||||
acc -12
|
||||
acc +48
|
||||
jmp +21
|
||||
jmp +434
|
||||
acc +30
|
||||
acc +1
|
||||
acc +40
|
||||
jmp +435
|
||||
jmp +132
|
||||
acc +40
|
||||
jmp +236
|
||||
jmp +179
|
||||
jmp -149
|
||||
acc +25
|
||||
acc +40
|
||||
acc -9
|
||||
acc +49
|
||||
jmp +445
|
||||
nop +399
|
||||
acc -14
|
||||
nop +374
|
||||
acc +0
|
||||
jmp +152
|
||||
acc +39
|
||||
nop +322
|
||||
acc +49
|
||||
nop +117
|
||||
jmp -19
|
||||
acc +24
|
||||
jmp +385
|
||||
acc +17
|
||||
acc +39
|
||||
acc +44
|
||||
acc -8
|
||||
jmp -58
|
||||
acc -18
|
||||
nop -76
|
||||
jmp +66
|
||||
acc +14
|
||||
jmp +427
|
||||
acc +11
|
||||
acc +47
|
||||
acc +9
|
||||
jmp +1
|
||||
acc +42
|
||||
jmp -7
|
||||
acc -16
|
||||
acc -13
|
||||
jmp +409
|
||||
acc +1
|
||||
acc +35
|
||||
acc +34
|
||||
jmp +371
|
||||
acc +24
|
||||
acc +46
|
||||
acc -4
|
||||
jmp +367
|
||||
acc +19
|
||||
acc +27
|
||||
acc -8
|
||||
acc +41
|
||||
jmp -184
|
||||
nop -185
|
||||
acc +23
|
||||
acc -8
|
||||
acc +35
|
||||
jmp -9
|
||||
acc -7
|
||||
nop -101
|
||||
nop +121
|
||||
acc +37
|
||||
jmp -72
|
||||
acc +24
|
||||
jmp +1
|
||||
nop -124
|
||||
jmp +163
|
||||
acc +37
|
||||
acc -12
|
||||
jmp +331
|
||||
acc -12
|
||||
acc +1
|
||||
jmp +232
|
||||
jmp -233
|
||||
jmp -72
|
||||
acc +28
|
||||
jmp +169
|
||||
acc +43
|
||||
acc +18
|
||||
nop +108
|
||||
jmp -184
|
||||
acc -4
|
||||
acc -10
|
||||
nop +317
|
||||
acc +48
|
||||
jmp +173
|
||||
nop +45
|
||||
jmp -73
|
||||
acc +35
|
||||
jmp +198
|
||||
acc -15
|
||||
acc +46
|
||||
acc +31
|
||||
jmp +41
|
||||
nop +169
|
||||
jmp +1
|
||||
nop -92
|
||||
nop -271
|
||||
jmp -113
|
||||
jmp +1
|
||||
nop -42
|
||||
jmp +42
|
||||
nop -283
|
||||
acc +22
|
||||
nop +200
|
||||
jmp -17
|
||||
jmp +1
|
||||
acc +49
|
||||
nop +35
|
||||
nop -185
|
||||
jmp +298
|
||||
acc +1
|
||||
jmp +1
|
||||
nop +301
|
||||
acc +19
|
||||
jmp -34
|
||||
jmp +163
|
||||
jmp +1
|
||||
acc +49
|
||||
jmp -115
|
||||
jmp -62
|
||||
acc +8
|
||||
acc +5
|
||||
acc -6
|
||||
jmp -146
|
||||
acc -4
|
||||
nop -202
|
||||
acc +47
|
||||
jmp -114
|
||||
acc +8
|
||||
jmp +57
|
||||
acc +37
|
||||
jmp +61
|
||||
jmp +267
|
||||
acc +2
|
||||
acc +28
|
||||
nop -20
|
||||
jmp -186
|
||||
acc +24
|
||||
nop +269
|
||||
acc +48
|
||||
acc +45
|
||||
jmp -22
|
||||
acc +11
|
||||
acc +36
|
||||
jmp -267
|
||||
acc +7
|
||||
nop -45
|
||||
nop -231
|
||||
jmp +32
|
||||
nop +220
|
||||
acc +19
|
||||
jmp -250
|
||||
acc +33
|
||||
jmp -169
|
||||
acc +45
|
||||
acc -13
|
||||
acc +0
|
||||
acc +44
|
||||
jmp +6
|
||||
acc +42
|
||||
jmp +84
|
||||
acc +48
|
||||
jmp -332
|
||||
jmp +213
|
||||
acc -16
|
||||
acc +31
|
||||
acc +17
|
||||
acc +3
|
||||
jmp -75
|
||||
jmp +1
|
||||
acc +11
|
||||
acc +4
|
||||
jmp -271
|
||||
acc -12
|
||||
nop +97
|
||||
nop +11
|
||||
jmp -43
|
||||
acc +30
|
||||
jmp +1
|
||||
jmp +49
|
||||
jmp -379
|
||||
nop -51
|
||||
acc +0
|
||||
acc -8
|
||||
nop -191
|
||||
jmp -346
|
||||
jmp -255
|
||||
acc +2
|
||||
acc +21
|
||||
acc -16
|
||||
nop +217
|
||||
jmp -30
|
||||
acc +31
|
||||
jmp -270
|
||||
jmp -324
|
||||
jmp +130
|
||||
acc +49
|
||||
nop +179
|
||||
jmp -37
|
||||
acc +11
|
||||
acc +15
|
||||
acc +29
|
||||
acc +17
|
||||
jmp -237
|
||||
acc +47
|
||||
acc -13
|
||||
acc +6
|
||||
jmp +169
|
||||
nop +54
|
||||
acc -12
|
||||
jmp -233
|
||||
nop +33
|
||||
acc +17
|
||||
acc +14
|
||||
acc +21
|
||||
jmp -275
|
||||
acc -8
|
||||
acc +1
|
||||
nop +229
|
||||
jmp +1
|
||||
jmp +119
|
||||
jmp -193
|
||||
nop +217
|
||||
jmp +95
|
||||
acc -2
|
||||
acc +1
|
||||
acc +41
|
||||
jmp -332
|
||||
acc +44
|
||||
nop -343
|
||||
acc +23
|
||||
jmp -165
|
||||
acc +7
|
||||
acc -12
|
||||
nop -339
|
||||
jmp +9
|
||||
nop -390
|
||||
acc -17
|
||||
acc +43
|
||||
jmp -138
|
||||
nop -247
|
||||
acc +42
|
||||
acc +0
|
||||
jmp +170
|
||||
acc +48
|
||||
jmp -139
|
||||
acc +6
|
||||
acc +13
|
||||
acc +35
|
||||
jmp -85
|
||||
nop -117
|
||||
jmp -307
|
||||
acc +25
|
||||
acc -10
|
||||
acc -14
|
||||
acc +0
|
||||
jmp -355
|
||||
jmp +102
|
||||
acc -8
|
||||
acc +47
|
||||
acc +36
|
||||
jmp +42
|
||||
acc +33
|
||||
acc +17
|
||||
acc +46
|
||||
jmp -331
|
||||
jmp +1
|
||||
acc -11
|
||||
jmp +1
|
||||
acc +27
|
||||
jmp +147
|
||||
acc -14
|
||||
nop -28
|
||||
acc +32
|
||||
jmp -482
|
||||
acc +11
|
||||
nop -390
|
||||
jmp -485
|
||||
acc -12
|
||||
acc +37
|
||||
acc +33
|
||||
acc +28
|
||||
jmp -32
|
||||
acc +42
|
||||
acc -11
|
||||
jmp -460
|
||||
acc +36
|
||||
acc +6
|
||||
acc +39
|
||||
jmp +80
|
||||
nop +123
|
||||
acc -13
|
||||
jmp -97
|
||||
acc +25
|
||||
acc +46
|
||||
acc +13
|
||||
nop -450
|
||||
jmp +84
|
||||
acc +3
|
||||
nop -260
|
||||
jmp +1
|
||||
acc +22
|
||||
jmp -510
|
||||
acc -4
|
||||
acc +17
|
||||
acc -19
|
||||
jmp -420
|
||||
acc -14
|
||||
acc +26
|
||||
acc +29
|
||||
acc +17
|
||||
jmp -458
|
||||
acc -10
|
||||
acc +23
|
||||
nop -2
|
||||
jmp -196
|
||||
acc -5
|
||||
jmp -416
|
||||
acc +49
|
||||
jmp -165
|
||||
acc +4
|
||||
acc +7
|
||||
acc +20
|
||||
nop -217
|
||||
jmp +103
|
||||
jmp +5
|
||||
acc -1
|
||||
acc +2
|
||||
jmp +1
|
||||
jmp +84
|
||||
acc -14
|
||||
jmp -518
|
||||
jmp +1
|
||||
acc +30
|
||||
acc +21
|
||||
jmp -202
|
||||
nop -18
|
||||
jmp -344
|
||||
jmp -88
|
||||
nop -472
|
||||
acc -5
|
||||
acc +13
|
||||
jmp -295
|
||||
nop -315
|
||||
acc +41
|
||||
nop -317
|
||||
jmp -299
|
||||
nop +105
|
||||
jmp -86
|
||||
acc +7
|
||||
jmp -226
|
||||
nop -277
|
||||
acc +21
|
||||
acc +13
|
||||
acc +47
|
||||
jmp -283
|
||||
acc -11
|
||||
acc -1
|
||||
jmp -408
|
||||
acc +47
|
||||
nop -553
|
||||
acc +37
|
||||
acc -11
|
||||
jmp -468
|
||||
acc +43
|
||||
nop -299
|
||||
acc +40
|
||||
acc +2
|
||||
jmp -275
|
||||
acc +24
|
||||
acc -14
|
||||
acc +13
|
||||
acc +36
|
||||
jmp -249
|
||||
acc +35
|
||||
jmp -45
|
||||
acc +47
|
||||
acc +31
|
||||
acc -19
|
||||
jmp -151
|
||||
jmp -33
|
||||
acc +6
|
||||
jmp -160
|
||||
jmp -553
|
||||
acc +25
|
||||
jmp +1
|
||||
nop -267
|
||||
jmp -430
|
||||
acc +23
|
||||
nop +63
|
||||
acc +37
|
||||
jmp -434
|
||||
nop -579
|
||||
jmp +11
|
||||
acc +25
|
||||
acc -17
|
||||
acc +22
|
||||
acc +27
|
||||
jmp +15
|
||||
jmp -546
|
||||
acc -4
|
||||
acc +41
|
||||
acc +0
|
||||
jmp -261
|
||||
acc +20
|
||||
jmp -404
|
||||
jmp -408
|
||||
acc +26
|
||||
jmp -464
|
||||
acc +34
|
||||
nop -80
|
||||
acc -12
|
||||
jmp -43
|
||||
jmp -410
|
||||
acc -13
|
||||
acc -3
|
||||
jmp -310
|
||||
nop -433
|
||||
acc -7
|
||||
acc -11
|
||||
acc +9
|
||||
jmp -29
|
||||
nop -564
|
||||
acc -5
|
||||
acc -16
|
||||
acc +36
|
||||
jmp -587
|
||||
jmp -115
|
||||
acc +24
|
||||
acc +35
|
||||
nop -638
|
||||
jmp -573
|
||||
acc +31
|
||||
acc +14
|
||||
jmp -609
|
||||
acc +25
|
||||
acc -10
|
||||
acc +18
|
||||
jmp -308
|
||||
acc +25
|
||||
acc +33
|
||||
acc +21
|
||||
acc -12
|
||||
jmp -172
|
||||
nop -37
|
||||
acc +12
|
||||
jmp -316
|
||||
acc +41
|
||||
acc +14
|
||||
jmp -415
|
||||
acc +40
|
||||
jmp -112
|
||||
jmp -613
|
||||
acc +26
|
||||
nop -151
|
||||
jmp -471
|
||||
acc +50
|
||||
acc +16
|
||||
nop -119
|
||||
acc +46
|
||||
jmp +1
|
62
2020/d08/ex2/ex2.py
Executable file
62
2020/d08/ex2/ex2.py
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def run(code: List[Tuple[str, int]]) -> Tuple[int, bool]:
|
||||
accumulator = 0
|
||||
rip = 0
|
||||
|
||||
def acc(val: int) -> None:
|
||||
nonlocal accumulator
|
||||
nonlocal rip
|
||||
accumulator += val
|
||||
rip += 1
|
||||
|
||||
def nop(val: int) -> None:
|
||||
nonlocal rip
|
||||
rip += 1
|
||||
|
||||
def jmp(val: int) -> None:
|
||||
nonlocal rip
|
||||
rip += val
|
||||
|
||||
instrs = {
|
||||
"acc": acc,
|
||||
"jmp": jmp,
|
||||
"nop": nop,
|
||||
}
|
||||
seen = set()
|
||||
|
||||
while rip not in seen and rip < len(code):
|
||||
seen |= {rip}
|
||||
func = instrs[code[rip][0]]
|
||||
func(code[rip][1])
|
||||
|
||||
return accumulator, rip == len(code)
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
code = [(line[:3], int(line[3:])) for line in raw]
|
||||
lut = {"jmp": "nop", "nop": "jmp"}
|
||||
for i in range(len(code)):
|
||||
if code[i][0] not in lut:
|
||||
continue
|
||||
new_code = deepcopy(code)
|
||||
new_code[i] = lut[new_code[i][0]], new_code[i][1]
|
||||
val, halted = run(new_code)
|
||||
if halted:
|
||||
return val
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
675
2020/d08/ex2/input
Normal file
675
2020/d08/ex2/input
Normal file
|
@ -0,0 +1,675 @@
|
|||
acc -8
|
||||
jmp +5
|
||||
acc +0
|
||||
acc +44
|
||||
acc +42
|
||||
jmp +324
|
||||
acc -17
|
||||
jmp +1
|
||||
acc -17
|
||||
jmp +51
|
||||
acc -13
|
||||
acc +4
|
||||
jmp +1
|
||||
nop +608
|
||||
jmp +274
|
||||
acc -17
|
||||
jmp +169
|
||||
acc +28
|
||||
nop +508
|
||||
jmp +1
|
||||
jmp +570
|
||||
acc +22
|
||||
acc -14
|
||||
jmp +377
|
||||
acc -13
|
||||
acc +27
|
||||
jmp +474
|
||||
acc -5
|
||||
jmp +1
|
||||
acc +12
|
||||
jmp +37
|
||||
jmp +184
|
||||
acc +36
|
||||
acc +32
|
||||
acc -8
|
||||
jmp +465
|
||||
acc -13
|
||||
acc +18
|
||||
jmp +169
|
||||
acc +20
|
||||
acc +26
|
||||
acc +23
|
||||
jmp +333
|
||||
jmp +584
|
||||
acc +9
|
||||
acc +28
|
||||
acc +28
|
||||
nop +571
|
||||
jmp +143
|
||||
acc +39
|
||||
acc +39
|
||||
acc -16
|
||||
jmp +361
|
||||
acc +48
|
||||
acc +3
|
||||
acc +15
|
||||
nop +4
|
||||
jmp +504
|
||||
acc +6
|
||||
jmp +285
|
||||
acc +26
|
||||
acc +33
|
||||
jmp +1
|
||||
acc +36
|
||||
jmp +577
|
||||
acc +36
|
||||
jmp +6
|
||||
nop +498
|
||||
acc +42
|
||||
jmp +496
|
||||
acc +10
|
||||
jmp +74
|
||||
acc +17
|
||||
acc +16
|
||||
acc +30
|
||||
jmp +254
|
||||
acc -3
|
||||
acc +16
|
||||
acc -2
|
||||
nop +106
|
||||
jmp +541
|
||||
acc -15
|
||||
jmp +579
|
||||
jmp +165
|
||||
acc +22
|
||||
acc -6
|
||||
acc +29
|
||||
acc -19
|
||||
jmp +342
|
||||
acc -19
|
||||
jmp +340
|
||||
acc +13
|
||||
acc +25
|
||||
acc +29
|
||||
jmp +269
|
||||
acc -14
|
||||
acc +27
|
||||
acc +41
|
||||
acc +49
|
||||
jmp +181
|
||||
nop +350
|
||||
jmp +1
|
||||
nop +437
|
||||
acc +34
|
||||
jmp +494
|
||||
acc +19
|
||||
acc +2
|
||||
acc +44
|
||||
jmp +558
|
||||
acc +10
|
||||
jmp +44
|
||||
nop +4
|
||||
nop -80
|
||||
nop +540
|
||||
jmp +16
|
||||
acc +28
|
||||
jmp +14
|
||||
acc +13
|
||||
nop +399
|
||||
acc +29
|
||||
nop -60
|
||||
jmp -6
|
||||
acc +41
|
||||
acc +30
|
||||
jmp +232
|
||||
acc +28
|
||||
nop +495
|
||||
acc +15
|
||||
acc +48
|
||||
jmp +157
|
||||
nop +483
|
||||
jmp -59
|
||||
acc +5
|
||||
acc +30
|
||||
acc +30
|
||||
acc +2
|
||||
jmp +349
|
||||
acc +11
|
||||
acc +27
|
||||
acc +1
|
||||
jmp +367
|
||||
acc +8
|
||||
acc +45
|
||||
acc +11
|
||||
jmp +171
|
||||
jmp -113
|
||||
acc +48
|
||||
jmp -38
|
||||
acc +12
|
||||
jmp +145
|
||||
acc +8
|
||||
nop +29
|
||||
nop +319
|
||||
jmp +154
|
||||
nop +166
|
||||
jmp +395
|
||||
nop +15
|
||||
jmp +237
|
||||
acc +22
|
||||
acc +3
|
||||
acc +42
|
||||
acc +1
|
||||
jmp +288
|
||||
jmp -63
|
||||
nop +489
|
||||
acc +33
|
||||
jmp +247
|
||||
jmp +1
|
||||
acc -8
|
||||
acc +9
|
||||
jmp +413
|
||||
acc -17
|
||||
acc +3
|
||||
acc +3
|
||||
jmp +432
|
||||
nop -17
|
||||
acc +36
|
||||
nop +198
|
||||
acc +45
|
||||
jmp +109
|
||||
nop +242
|
||||
acc +40
|
||||
acc +11
|
||||
jmp +448
|
||||
jmp +437
|
||||
acc +3
|
||||
acc +49
|
||||
acc +27
|
||||
jmp +221
|
||||
nop +158
|
||||
jmp +143
|
||||
acc +50
|
||||
jmp -70
|
||||
acc +46
|
||||
acc +8
|
||||
acc +35
|
||||
acc -3
|
||||
jmp +104
|
||||
acc +11
|
||||
acc +0
|
||||
jmp +34
|
||||
nop +132
|
||||
jmp +425
|
||||
jmp +219
|
||||
acc -12
|
||||
acc +48
|
||||
jmp +21
|
||||
jmp +434
|
||||
acc +30
|
||||
acc +1
|
||||
acc +40
|
||||
jmp +435
|
||||
jmp +132
|
||||
acc +40
|
||||
jmp +236
|
||||
jmp +179
|
||||
jmp -149
|
||||
acc +25
|
||||
acc +40
|
||||
acc -9
|
||||
acc +49
|
||||
jmp +445
|
||||
nop +399
|
||||
acc -14
|
||||
nop +374
|
||||
acc +0
|
||||
jmp +152
|
||||
acc +39
|
||||
nop +322
|
||||
acc +49
|
||||
nop +117
|
||||
jmp -19
|
||||
acc +24
|
||||
jmp +385
|
||||
acc +17
|
||||
acc +39
|
||||
acc +44
|
||||
acc -8
|
||||
jmp -58
|
||||
acc -18
|
||||
nop -76
|
||||
jmp +66
|
||||
acc +14
|
||||
jmp +427
|
||||
acc +11
|
||||
acc +47
|
||||
acc +9
|
||||
jmp +1
|
||||
acc +42
|
||||
jmp -7
|
||||
acc -16
|
||||
acc -13
|
||||
jmp +409
|
||||
acc +1
|
||||
acc +35
|
||||
acc +34
|
||||
jmp +371
|
||||
acc +24
|
||||
acc +46
|
||||
acc -4
|
||||
jmp +367
|
||||
acc +19
|
||||
acc +27
|
||||
acc -8
|
||||
acc +41
|
||||
jmp -184
|
||||
nop -185
|
||||
acc +23
|
||||
acc -8
|
||||
acc +35
|
||||
jmp -9
|
||||
acc -7
|
||||
nop -101
|
||||
nop +121
|
||||
acc +37
|
||||
jmp -72
|
||||
acc +24
|
||||
jmp +1
|
||||
nop -124
|
||||
jmp +163
|
||||
acc +37
|
||||
acc -12
|
||||
jmp +331
|
||||
acc -12
|
||||
acc +1
|
||||
jmp +232
|
||||
jmp -233
|
||||
jmp -72
|
||||
acc +28
|
||||
jmp +169
|
||||
acc +43
|
||||
acc +18
|
||||
nop +108
|
||||
jmp -184
|
||||
acc -4
|
||||
acc -10
|
||||
nop +317
|
||||
acc +48
|
||||
jmp +173
|
||||
nop +45
|
||||
jmp -73
|
||||
acc +35
|
||||
jmp +198
|
||||
acc -15
|
||||
acc +46
|
||||
acc +31
|
||||
jmp +41
|
||||
nop +169
|
||||
jmp +1
|
||||
nop -92
|
||||
nop -271
|
||||
jmp -113
|
||||
jmp +1
|
||||
nop -42
|
||||
jmp +42
|
||||
nop -283
|
||||
acc +22
|
||||
nop +200
|
||||
jmp -17
|
||||
jmp +1
|
||||
acc +49
|
||||
nop +35
|
||||
nop -185
|
||||
jmp +298
|
||||
acc +1
|
||||
jmp +1
|
||||
nop +301
|
||||
acc +19
|
||||
jmp -34
|
||||
jmp +163
|
||||
jmp +1
|
||||
acc +49
|
||||
jmp -115
|
||||
jmp -62
|
||||
acc +8
|
||||
acc +5
|
||||
acc -6
|
||||
jmp -146
|
||||
acc -4
|
||||
nop -202
|
||||
acc +47
|
||||
jmp -114
|
||||
acc +8
|
||||
jmp +57
|
||||
acc +37
|
||||
jmp +61
|
||||
jmp +267
|
||||
acc +2
|
||||
acc +28
|
||||
nop -20
|
||||
jmp -186
|
||||
acc +24
|
||||
nop +269
|
||||
acc +48
|
||||
acc +45
|
||||
jmp -22
|
||||
acc +11
|
||||
acc +36
|
||||
jmp -267
|
||||
acc +7
|
||||
nop -45
|
||||
nop -231
|
||||
jmp +32
|
||||
nop +220
|
||||
acc +19
|
||||
jmp -250
|
||||
acc +33
|
||||
jmp -169
|
||||
acc +45
|
||||
acc -13
|
||||
acc +0
|
||||
acc +44
|
||||
jmp +6
|
||||
acc +42
|
||||
jmp +84
|
||||
acc +48
|
||||
jmp -332
|
||||
jmp +213
|
||||
acc -16
|
||||
acc +31
|
||||
acc +17
|
||||
acc +3
|
||||
jmp -75
|
||||
jmp +1
|
||||
acc +11
|
||||
acc +4
|
||||
jmp -271
|
||||
acc -12
|
||||
nop +97
|
||||
nop +11
|
||||
jmp -43
|
||||
acc +30
|
||||
jmp +1
|
||||
jmp +49
|
||||
jmp -379
|
||||
nop -51
|
||||
acc +0
|
||||
acc -8
|
||||
nop -191
|
||||
jmp -346
|
||||
jmp -255
|
||||
acc +2
|
||||
acc +21
|
||||
acc -16
|
||||
nop +217
|
||||
jmp -30
|
||||
acc +31
|
||||
jmp -270
|
||||
jmp -324
|
||||
jmp +130
|
||||
acc +49
|
||||
nop +179
|
||||
jmp -37
|
||||
acc +11
|
||||
acc +15
|
||||
acc +29
|
||||
acc +17
|
||||
jmp -237
|
||||
acc +47
|
||||
acc -13
|
||||
acc +6
|
||||
jmp +169
|
||||
nop +54
|
||||
acc -12
|
||||
jmp -233
|
||||
nop +33
|
||||
acc +17
|
||||
acc +14
|
||||
acc +21
|
||||
jmp -275
|
||||
acc -8
|
||||
acc +1
|
||||
nop +229
|
||||
jmp +1
|
||||
jmp +119
|
||||
jmp -193
|
||||
nop +217
|
||||
jmp +95
|
||||
acc -2
|
||||
acc +1
|
||||
acc +41
|
||||
jmp -332
|
||||
acc +44
|
||||
nop -343
|
||||
acc +23
|
||||
jmp -165
|
||||
acc +7
|
||||
acc -12
|
||||
nop -339
|
||||
jmp +9
|
||||
nop -390
|
||||
acc -17
|
||||
acc +43
|
||||
jmp -138
|
||||
nop -247
|
||||
acc +42
|
||||
acc +0
|
||||
jmp +170
|
||||
acc +48
|
||||
jmp -139
|
||||
acc +6
|
||||
acc +13
|
||||
acc +35
|
||||
jmp -85
|
||||
nop -117
|
||||
jmp -307
|
||||
acc +25
|
||||
acc -10
|
||||
acc -14
|
||||
acc +0
|
||||
jmp -355
|
||||
jmp +102
|
||||
acc -8
|
||||
acc +47
|
||||
acc +36
|
||||
jmp +42
|
||||
acc +33
|
||||
acc +17
|
||||
acc +46
|
||||
jmp -331
|
||||
jmp +1
|
||||
acc -11
|
||||
jmp +1
|
||||
acc +27
|
||||
jmp +147
|
||||
acc -14
|
||||
nop -28
|
||||
acc +32
|
||||
jmp -482
|
||||
acc +11
|
||||
nop -390
|
||||
jmp -485
|
||||
acc -12
|
||||
acc +37
|
||||
acc +33
|
||||
acc +28
|
||||
jmp -32
|
||||
acc +42
|
||||
acc -11
|
||||
jmp -460
|
||||
acc +36
|
||||
acc +6
|
||||
acc +39
|
||||
jmp +80
|
||||
nop +123
|
||||
acc -13
|
||||
jmp -97
|
||||
acc +25
|
||||
acc +46
|
||||
acc +13
|
||||
nop -450
|
||||
jmp +84
|
||||
acc +3
|
||||
nop -260
|
||||
jmp +1
|
||||
acc +22
|
||||
jmp -510
|
||||
acc -4
|
||||
acc +17
|
||||
acc -19
|
||||
jmp -420
|
||||
acc -14
|
||||
acc +26
|
||||
acc +29
|
||||
acc +17
|
||||
jmp -458
|
||||
acc -10
|
||||
acc +23
|
||||
nop -2
|
||||
jmp -196
|
||||
acc -5
|
||||
jmp -416
|
||||
acc +49
|
||||
jmp -165
|
||||
acc +4
|
||||
acc +7
|
||||
acc +20
|
||||
nop -217
|
||||
jmp +103
|
||||
jmp +5
|
||||
acc -1
|
||||
acc +2
|
||||
jmp +1
|
||||
jmp +84
|
||||
acc -14
|
||||
jmp -518
|
||||
jmp +1
|
||||
acc +30
|
||||
acc +21
|
||||
jmp -202
|
||||
nop -18
|
||||
jmp -344
|
||||
jmp -88
|
||||
nop -472
|
||||
acc -5
|
||||
acc +13
|
||||
jmp -295
|
||||
nop -315
|
||||
acc +41
|
||||
nop -317
|
||||
jmp -299
|
||||
nop +105
|
||||
jmp -86
|
||||
acc +7
|
||||
jmp -226
|
||||
nop -277
|
||||
acc +21
|
||||
acc +13
|
||||
acc +47
|
||||
jmp -283
|
||||
acc -11
|
||||
acc -1
|
||||
jmp -408
|
||||
acc +47
|
||||
nop -553
|
||||
acc +37
|
||||
acc -11
|
||||
jmp -468
|
||||
acc +43
|
||||
nop -299
|
||||
acc +40
|
||||
acc +2
|
||||
jmp -275
|
||||
acc +24
|
||||
acc -14
|
||||
acc +13
|
||||
acc +36
|
||||
jmp -249
|
||||
acc +35
|
||||
jmp -45
|
||||
acc +47
|
||||
acc +31
|
||||
acc -19
|
||||
jmp -151
|
||||
jmp -33
|
||||
acc +6
|
||||
jmp -160
|
||||
jmp -553
|
||||
acc +25
|
||||
jmp +1
|
||||
nop -267
|
||||
jmp -430
|
||||
acc +23
|
||||
nop +63
|
||||
acc +37
|
||||
jmp -434
|
||||
nop -579
|
||||
jmp +11
|
||||
acc +25
|
||||
acc -17
|
||||
acc +22
|
||||
acc +27
|
||||
jmp +15
|
||||
jmp -546
|
||||
acc -4
|
||||
acc +41
|
||||
acc +0
|
||||
jmp -261
|
||||
acc +20
|
||||
jmp -404
|
||||
jmp -408
|
||||
acc +26
|
||||
jmp -464
|
||||
acc +34
|
||||
nop -80
|
||||
acc -12
|
||||
jmp -43
|
||||
jmp -410
|
||||
acc -13
|
||||
acc -3
|
||||
jmp -310
|
||||
nop -433
|
||||
acc -7
|
||||
acc -11
|
||||
acc +9
|
||||
jmp -29
|
||||
nop -564
|
||||
acc -5
|
||||
acc -16
|
||||
acc +36
|
||||
jmp -587
|
||||
jmp -115
|
||||
acc +24
|
||||
acc +35
|
||||
nop -638
|
||||
jmp -573
|
||||
acc +31
|
||||
acc +14
|
||||
jmp -609
|
||||
acc +25
|
||||
acc -10
|
||||
acc +18
|
||||
jmp -308
|
||||
acc +25
|
||||
acc +33
|
||||
acc +21
|
||||
acc -12
|
||||
jmp -172
|
||||
nop -37
|
||||
acc +12
|
||||
jmp -316
|
||||
acc +41
|
||||
acc +14
|
||||
jmp -415
|
||||
acc +40
|
||||
jmp -112
|
||||
jmp -613
|
||||
acc +26
|
||||
nop -151
|
||||
jmp -471
|
||||
acc +50
|
||||
acc +16
|
||||
nop -119
|
||||
acc +46
|
||||
jmp +1
|
32
2020/d09/ex1/ex1.py
Executable file
32
2020/d09/ex1/ex1.py
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def find_invalid(nums: List[int]) -> int:
|
||||
for i in range(25, len(nums)):
|
||||
num = nums[i]
|
||||
found = False
|
||||
for lhs, rhs in itertools.combinations(nums[i - 25 : i], 2):
|
||||
if lhs + rhs == num:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
return num
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return find_invalid([int(line) for line in raw])
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1000
2020/d09/ex1/input
Normal file
1000
2020/d09/ex1/input
Normal file
File diff suppressed because it is too large
Load diff
42
2020/d09/ex2/ex2.py
Executable file
42
2020/d09/ex2/ex2.py
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def find_invalid(nums: List[int]) -> int:
|
||||
for i in range(25, len(nums)):
|
||||
num = nums[i]
|
||||
found = False
|
||||
for lhs, rhs in itertools.combinations(nums[i - 25 : i], 2):
|
||||
if lhs + rhs == num:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
return num
|
||||
assert False # Sanity check
|
||||
|
||||
|
||||
def find_weakness(nums: List[int], invalid: int) -> int:
|
||||
for i in range(len(nums) - 2):
|
||||
for j in range(i + 2, len(nums)):
|
||||
if sum(nums[i:j]) == invalid:
|
||||
return min(nums[i:j]) + max(nums[i:j])
|
||||
assert False # Sanity check((
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
nums = [int(line) for line in raw]
|
||||
invalid = find_invalid(nums)
|
||||
return find_weakness(nums, invalid)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1000
2020/d09/ex2/input
Normal file
1000
2020/d09/ex2/input
Normal file
File diff suppressed because it is too large
Load diff
32
2020/d10/ex1/ex1.py
Executable file
32
2020/d10/ex1/ex1.py
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def make_chain(adapters: List[int]) -> int:
|
||||
adapters = sorted(adapters)
|
||||
output = 0
|
||||
device = adapters[-1] + 3
|
||||
jolts: Dict[int, int] = defaultdict(int)
|
||||
for adapter in adapters:
|
||||
delt = adapter - output
|
||||
jolts[delt] += 1
|
||||
output = adapter
|
||||
jolts[device - output] += 1
|
||||
|
||||
return jolts[1] * jolts[3]
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return make_chain([int(line) for line in raw])
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
101
2020/d10/ex1/input
Normal file
101
2020/d10/ex1/input
Normal file
|
@ -0,0 +1,101 @@
|
|||
144
|
||||
10
|
||||
75
|
||||
3
|
||||
36
|
||||
80
|
||||
143
|
||||
59
|
||||
111
|
||||
133
|
||||
1
|
||||
112
|
||||
23
|
||||
62
|
||||
101
|
||||
137
|
||||
41
|
||||
24
|
||||
8
|
||||
121
|
||||
35
|
||||
105
|
||||
161
|
||||
69
|
||||
52
|
||||
21
|
||||
55
|
||||
29
|
||||
135
|
||||
142
|
||||
38
|
||||
108
|
||||
141
|
||||
115
|
||||
68
|
||||
7
|
||||
98
|
||||
82
|
||||
9
|
||||
72
|
||||
118
|
||||
27
|
||||
153
|
||||
140
|
||||
61
|
||||
90
|
||||
158
|
||||
102
|
||||
28
|
||||
134
|
||||
91
|
||||
2
|
||||
17
|
||||
81
|
||||
31
|
||||
15
|
||||
120
|
||||
20
|
||||
34
|
||||
56
|
||||
4
|
||||
44
|
||||
74
|
||||
14
|
||||
147
|
||||
11
|
||||
49
|
||||
128
|
||||
16
|
||||
99
|
||||
66
|
||||
47
|
||||
125
|
||||
155
|
||||
130
|
||||
37
|
||||
67
|
||||
54
|
||||
60
|
||||
48
|
||||
136
|
||||
89
|
||||
119
|
||||
154
|
||||
122
|
||||
129
|
||||
163
|
||||
73
|
||||
100
|
||||
85
|
||||
95
|
||||
30
|
||||
76
|
||||
162
|
||||
22
|
||||
79
|
||||
88
|
||||
150
|
||||
53
|
||||
63
|
||||
92
|
39
2020/d10/ex2/ex2.py
Executable file
39
2020/d10/ex2/ex2.py
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def make_chain(adapters: List[int]) -> int:
|
||||
adapters += [0, max(adapters) + 3]
|
||||
adapters = sorted(adapters)
|
||||
jolts: Dict[int, int] = {}
|
||||
N = len(adapters)
|
||||
|
||||
def rec(index: int) -> int:
|
||||
if (res := jolts.get(index)) is not None:
|
||||
return res
|
||||
if index == N - 1:
|
||||
return 1
|
||||
total = sum(
|
||||
rec(i)
|
||||
for i in range(index + 1, min(N, index + 4))
|
||||
if (adapters[i] - adapters[index]) <= 3
|
||||
)
|
||||
jolts[index] = total
|
||||
return total
|
||||
|
||||
return rec(0)
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return make_chain([int(line) for line in raw])
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
101
2020/d10/ex2/input
Normal file
101
2020/d10/ex2/input
Normal file
|
@ -0,0 +1,101 @@
|
|||
144
|
||||
10
|
||||
75
|
||||
3
|
||||
36
|
||||
80
|
||||
143
|
||||
59
|
||||
111
|
||||
133
|
||||
1
|
||||
112
|
||||
23
|
||||
62
|
||||
101
|
||||
137
|
||||
41
|
||||
24
|
||||
8
|
||||
121
|
||||
35
|
||||
105
|
||||
161
|
||||
69
|
||||
52
|
||||
21
|
||||
55
|
||||
29
|
||||
135
|
||||
142
|
||||
38
|
||||
108
|
||||
141
|
||||
115
|
||||
68
|
||||
7
|
||||
98
|
||||
82
|
||||
9
|
||||
72
|
||||
118
|
||||
27
|
||||
153
|
||||
140
|
||||
61
|
||||
90
|
||||
158
|
||||
102
|
||||
28
|
||||
134
|
||||
91
|
||||
2
|
||||
17
|
||||
81
|
||||
31
|
||||
15
|
||||
120
|
||||
20
|
||||
34
|
||||
56
|
||||
4
|
||||
44
|
||||
74
|
||||
14
|
||||
147
|
||||
11
|
||||
49
|
||||
128
|
||||
16
|
||||
99
|
||||
66
|
||||
47
|
||||
125
|
||||
155
|
||||
130
|
||||
37
|
||||
67
|
||||
54
|
||||
60
|
||||
48
|
||||
136
|
||||
89
|
||||
119
|
||||
154
|
||||
122
|
||||
129
|
||||
163
|
||||
73
|
||||
100
|
||||
85
|
||||
95
|
||||
30
|
||||
76
|
||||
162
|
||||
22
|
||||
79
|
||||
88
|
||||
150
|
||||
53
|
||||
63
|
||||
92
|
45
2020/d11/ex1/ex1.py
Executable file
45
2020/d11/ex1/ex1.py
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from typing import Iterator, List, Tuple
|
||||
|
||||
Grid = List[List[str]]
|
||||
|
||||
|
||||
def update(grid: Grid) -> Grid:
|
||||
def neightbours(x: int, y: int) -> Iterator[Tuple[int, int]]:
|
||||
for dx, dy in itertools.product(range(-1, 2), range(-1, 2)):
|
||||
if dx == 0 and dy == 0:
|
||||
continue
|
||||
|
||||
new_x, new_y = x + dx, y + dy
|
||||
if 0 <= new_x < len(grid) and 0 <= new_y < len(grid[0]):
|
||||
yield new_x, new_y
|
||||
|
||||
new_grid = deepcopy(grid)
|
||||
|
||||
for x, y in itertools.product(range(len(grid)), range(len(grid[0]))):
|
||||
num_alive = sum(grid[nx][ny] == "#" for nx, ny in neightbours(x, y))
|
||||
if num_alive == 0 and grid[x][y] == "L":
|
||||
new_grid[x][y] = "#"
|
||||
elif num_alive >= 4 and grid[x][y] == "#":
|
||||
new_grid[x][y] = "L"
|
||||
|
||||
return new_grid
|
||||
|
||||
|
||||
def solve(grid: Grid) -> int:
|
||||
while (new_grid := update(grid)) != grid:
|
||||
grid = new_grid
|
||||
return sum(sum(pos == "#" for pos in line) for line in grid)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve([[line[i] for i in range(len(line))] for line in input]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
91
2020/d11/ex1/input
Normal file
91
2020/d11/ex1/input
Normal file
|
@ -0,0 +1,91 @@
|
|||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL..LLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLL.LLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
...L.L......L...L..L...L..LL.....L.....L..LLLL..L.LL......LL....L..L.L..L....L.LL....LL..L..L
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLL..LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL..LLLLLLLLLLLLLLLLL.LLLLLLLL.LLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLL.LLLLLLLLLLLLL
|
||||
LLLL.LLLLL.LLLL.LLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
.....L.LLLL....LL..L...LLL.L.LL..LL.L........L....LL...L...L...L.LL....LL...L..L.....LL.L....
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LL.LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LL.LLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL..LLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL..LLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLL.LL.LLLLLLLLLL
|
||||
...L......L....L....L......L.L.....L..L.L.L..L.L...LLL.....LLLL.L.......LL.LLL.L.LL....L.....
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LL.LLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.L.LLLL.LLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LL.L.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
...LL..........L..LLLLL...L.L..........L........L.LL..L..L.LLL.L..L.L.....LL...LL....L..L.L..
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLL.LLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLL..LLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLL.LLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLL.LLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL..LLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLL..L.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
..LLLL.LL....LLL..L...L..L..L.......L..L...L.L...L..LL.L.L.L.L...L...L.L.L.L.L......LL...L..L
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLL.LLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLL.LLL.LLLLLLLL.L.LLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLLL.LLLLLL..LLLLLL.LLL
|
||||
..L...L...L...L..L....L...LL.L.L.L..LL...........LLL.L......L..L.....LL..L..LLL........L....L
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLL.LL.LLLL.LLLLLLL.L.LLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLL.L.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LL.L.LLLLL
|
||||
..L.L.LL....L....L..L....L.L...L..L..L.L.....L..L...L.LL.....L...............L..............L
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LL.L.LLLL.LLL.LLLL.LLLLL.LL.LLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LL.L.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLL.LL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
L.L.....L.L.L.LL.L......LLL.....L.L.L........L....LL.......L....L.....L....LL..L...LLL......L
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLL.L.LLLL.LLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL..LLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLL.LLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
...L...L.....L....L.L..........L..L.L..L..L..LL.L..L.......L.......L....L....L...LLL..L..L..L
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLL.LLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
..LLL....L.LL....L..............LLL......LL.LLL.....LL..L.L..L........L......L...L.LL..LL..L.
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLL..LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
L.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLL...LLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL..LLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
L...L.LL......L...LLLLLL.L.L.L...L.L..L..L.LL....L......LL..L...LLL....L...LL......L.........
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLL..LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLL.LLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
48
2020/d11/ex2/ex2.py
Executable file
48
2020/d11/ex2/ex2.py
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from copy import deepcopy
|
||||
from typing import Iterator, List, Tuple
|
||||
|
||||
Grid = List[List[str]]
|
||||
|
||||
|
||||
def update(grid: Grid) -> Grid:
|
||||
def neightbours(x: int, y: int) -> Iterator[Tuple[int, int]]:
|
||||
for dx, dy in itertools.product(range(-1, 2), range(-1, 2)):
|
||||
if dx == 0 and dy == 0:
|
||||
continue
|
||||
|
||||
new_x, new_y = x + dx, y + dy
|
||||
while 0 <= new_x < len(grid) and 0 <= new_y < len(grid[0]):
|
||||
if grid[new_x][new_y] in "L#":
|
||||
yield new_x, new_y
|
||||
break
|
||||
new_x, new_y = new_x + dx, new_y + dy
|
||||
|
||||
new_grid = deepcopy(grid)
|
||||
|
||||
for x, y in itertools.product(range(len(grid)), range(len(grid[0]))):
|
||||
num_alive = sum(grid[nx][ny] == "#" for nx, ny in neightbours(x, y))
|
||||
if num_alive == 0 and grid[x][y] == "L":
|
||||
new_grid[x][y] = "#"
|
||||
elif num_alive >= 5 and grid[x][y] == "#":
|
||||
new_grid[x][y] = "L"
|
||||
|
||||
return new_grid
|
||||
|
||||
|
||||
def solve(grid: Grid) -> int:
|
||||
while (new_grid := update(grid)) != grid:
|
||||
grid = new_grid
|
||||
return sum(sum(pos == "#" for pos in line) for line in grid)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve([[line[i] for i in range(len(line))] for line in input]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
91
2020/d11/ex2/input
Normal file
91
2020/d11/ex2/input
Normal file
|
@ -0,0 +1,91 @@
|
|||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL..LLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LL.LLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLL.LLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
...L.L......L...L..L...L..LL.....L.....L..LLLL..L.LL......LL....L..L.L..L....L.LL....LL..L..L
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLL..LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL..LLLLLLLLLLLLLLLLL.LLLLLLLL.LLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLL.LLLLLLLLLLLLL
|
||||
LLLL.LLLLL.LLLL.LLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
.....L.LLLL....LL..L...LLL.L.LL..LL.L........L....LL...L...L...L.LL....LL...L..L.....LL.L....
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LL.LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LL.LLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL..LLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLL.LLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL..LLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLL.LL.LLLLLLLLLL
|
||||
...L......L....L....L......L.L.....L..L.L.L..L.L...LLL.....LLLL.L.......LL.LLL.L.LL....L.....
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LL.LLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.L.LLLL.LLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LL.L.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
...LL..........L..LLLLL...L.L..........L........L.LL..L..L.LLL.L..L.L.....LL...LL....L..L.L..
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLL.LLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLL..LLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLL.LLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLL.LLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL..LLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLL..L.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
..LLLL.LL....LLL..L...L..L..L.......L..L...L.L...L..LL.L.L.L.L...L...L.L.L.L.L......LL...L..L
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLL.LLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLL.LLL.LLLLLLLL.L.LLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLLL.LLLLLL..LLLLLL.LLL
|
||||
..L...L...L...L..L....L...LL.L.L.L..LL...........LLL.L......L..L.....LL..L..LLL........L....L
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLL.LL.LLLL.LLLLLLL.L.LLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLL.L.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LL.L.LLLLL
|
||||
..L.L.LL....L....L..L....L.L...L..L..L.L.....L..L...L.LL.....L...............L..............L
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LL.L.LLLL.LLL.LLLL.LLLLL.LL.LLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LL.L.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLL.LL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
L.L.....L.L.L.LL.L......LLL.....L.L.L........L....LL.......L....L.....L....LL..L...LLL......L
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLL.L.LLLL.LLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL..LLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLL.LLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
...L...L.....L....L.L..........L..L.L..L..L..LL.L..L.......L.......L....L....L...LLL..L..L..L
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLL.LLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
..LLL....L.LL....L..............LLL......LL.LLL.....LL..L.L..L........L......L...L.LL..LL..L.
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLL..LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
L.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLL.LLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLL...LLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLLLLLLLLLLLL..LLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLL.LLLL.LLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
||||
L...L.LL......L...LLLLLL.L.L.L...L.L..L..L.LL....L......LL..L...LLL....L...LL......L.........
|
||||
LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLL
|
||||
LLLLLLLLLL.LLL..LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLL.LLLLLL.LLLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLL.LLLL
|
||||
LLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLL.LLLLLLLLLL
|
53
2020/d12/ex1/ex1.py
Executable file
53
2020/d12/ex1/ex1.py
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import List, Tuple
|
||||
|
||||
Positiom = Tuple[str, int, int]
|
||||
Instruction = Tuple[str, int]
|
||||
|
||||
ORIENTATIONS = ["N", "W", "S", "E"]
|
||||
MOVES = {
|
||||
"N": (1, 0),
|
||||
"W": (0, -1),
|
||||
"S": (-1, 0),
|
||||
"E": (0, 1),
|
||||
}
|
||||
|
||||
|
||||
def move_ship(pos: Positiom, instr: Instruction) -> Positiom:
|
||||
if instr[0] == "L":
|
||||
assert instr[1] % 90 == 0 # Sanity check
|
||||
delt = instr[1] // 90
|
||||
orientation = ORIENTATIONS[
|
||||
(ORIENTATIONS.index(pos[0]) + delt) % len(ORIENTATIONS)
|
||||
]
|
||||
return (orientation, *pos[1:])
|
||||
elif instr[0] == "R":
|
||||
assert instr[1] % 90 == 0 # Sanity check
|
||||
delt = instr[1] // 90
|
||||
orientation = ORIENTATIONS[ORIENTATIONS.index(pos[0]) - delt]
|
||||
return (orientation, *pos[1:])
|
||||
else:
|
||||
dx, dy = MOVES[pos[0] if instr[0] == "F" else instr[0]]
|
||||
x, y = pos[1], pos[2]
|
||||
x += dx * instr[1]
|
||||
y += dy * instr[1]
|
||||
return (pos[0], x, y)
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
instructions = [(i[0], int(i[1:])) for i in raw]
|
||||
ship = ("E", 0, 0)
|
||||
for i in instructions:
|
||||
ship = move_ship(ship, i)
|
||||
return abs(ship[1]) + abs(ship[2])
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
785
2020/d12/ex1/input
Normal file
785
2020/d12/ex1/input
Normal file
|
@ -0,0 +1,785 @@
|
|||
N2
|
||||
F85
|
||||
L90
|
||||
W5
|
||||
R90
|
||||
F56
|
||||
F16
|
||||
F98
|
||||
W4
|
||||
S3
|
||||
F92
|
||||
N3
|
||||
W2
|
||||
N3
|
||||
E2
|
||||
S4
|
||||
W1
|
||||
N2
|
||||
F7
|
||||
N2
|
||||
E3
|
||||
S1
|
||||
L90
|
||||
N2
|
||||
E2
|
||||
F13
|
||||
E5
|
||||
S4
|
||||
R90
|
||||
N2
|
||||
W4
|
||||
F55
|
||||
W3
|
||||
N1
|
||||
F93
|
||||
L90
|
||||
N3
|
||||
F72
|
||||
E4
|
||||
W1
|
||||
N2
|
||||
F76
|
||||
S5
|
||||
L90
|
||||
F44
|
||||
N2
|
||||
F81
|
||||
S1
|
||||
F28
|
||||
R270
|
||||
E5
|
||||
N4
|
||||
E5
|
||||
F23
|
||||
R270
|
||||
F53
|
||||
N2
|
||||
L90
|
||||
E5
|
||||
R180
|
||||
N1
|
||||
F99
|
||||
N3
|
||||
E2
|
||||
R180
|
||||
W5
|
||||
F70
|
||||
W5
|
||||
R180
|
||||
F9
|
||||
S1
|
||||
R90
|
||||
S1
|
||||
F58
|
||||
N3
|
||||
N4
|
||||
R180
|
||||
N3
|
||||
R90
|
||||
S5
|
||||
F6
|
||||
E3
|
||||
N4
|
||||
F38
|
||||
W4
|
||||
R180
|
||||
F53
|
||||
R180
|
||||
E2
|
||||
R90
|
||||
W4
|
||||
L180
|
||||
F13
|
||||
N3
|
||||
F80
|
||||
W1
|
||||
R270
|
||||
E2
|
||||
S1
|
||||
F24
|
||||
E5
|
||||
F1
|
||||
S3
|
||||
F34
|
||||
R90
|
||||
F54
|
||||
E4
|
||||
F59
|
||||
E4
|
||||
R180
|
||||
F88
|
||||
R90
|
||||
S1
|
||||
R90
|
||||
F6
|
||||
R90
|
||||
N1
|
||||
F89
|
||||
W3
|
||||
F9
|
||||
L180
|
||||
W1
|
||||
F47
|
||||
R180
|
||||
N2
|
||||
W1
|
||||
F28
|
||||
F73
|
||||
S1
|
||||
F27
|
||||
E2
|
||||
F82
|
||||
W3
|
||||
F38
|
||||
E4
|
||||
L90
|
||||
E4
|
||||
F64
|
||||
W5
|
||||
W3
|
||||
S2
|
||||
L180
|
||||
F22
|
||||
L90
|
||||
F10
|
||||
L90
|
||||
F64
|
||||
E4
|
||||
N4
|
||||
F21
|
||||
S4
|
||||
E3
|
||||
N5
|
||||
F71
|
||||
N3
|
||||
F93
|
||||
N2
|
||||
R90
|
||||
E4
|
||||
F64
|
||||
E1
|
||||
L90
|
||||
F37
|
||||
E5
|
||||
F96
|
||||
W2
|
||||
N4
|
||||
E2
|
||||
R90
|
||||
S1
|
||||
R90
|
||||
W1
|
||||
R180
|
||||
E2
|
||||
S2
|
||||
R90
|
||||
W3
|
||||
S2
|
||||
F94
|
||||
W2
|
||||
L180
|
||||
S2
|
||||
E4
|
||||
F54
|
||||
N2
|
||||
E4
|
||||
S3
|
||||
L180
|
||||
W2
|
||||
N1
|
||||
W2
|
||||
R90
|
||||
F54
|
||||
L180
|
||||
N2
|
||||
F87
|
||||
E2
|
||||
F23
|
||||
W3
|
||||
R180
|
||||
W4
|
||||
S3
|
||||
F93
|
||||
E5
|
||||
R90
|
||||
N4
|
||||
R90
|
||||
S4
|
||||
E3
|
||||
S3
|
||||
F31
|
||||
R90
|
||||
F89
|
||||
E3
|
||||
F73
|
||||
S5
|
||||
F97
|
||||
W1
|
||||
L180
|
||||
F52
|
||||
E3
|
||||
F68
|
||||
R90
|
||||
S2
|
||||
S5
|
||||
F26
|
||||
L180
|
||||
F12
|
||||
E2
|
||||
F83
|
||||
F9
|
||||
N2
|
||||
R90
|
||||
F99
|
||||
R90
|
||||
S4
|
||||
E5
|
||||
R90
|
||||
S4
|
||||
F84
|
||||
W4
|
||||
E5
|
||||
R90
|
||||
F42
|
||||
W4
|
||||
F94
|
||||
W1
|
||||
R270
|
||||
S3
|
||||
E5
|
||||
F23
|
||||
F38
|
||||
W2
|
||||
W1
|
||||
N5
|
||||
E2
|
||||
L180
|
||||
N1
|
||||
F26
|
||||
L90
|
||||
F5
|
||||
R90
|
||||
N5
|
||||
R180
|
||||
F25
|
||||
L90
|
||||
S1
|
||||
N3
|
||||
F62
|
||||
S1
|
||||
F77
|
||||
N3
|
||||
E3
|
||||
L90
|
||||
F93
|
||||
W3
|
||||
E3
|
||||
N2
|
||||
F14
|
||||
N5
|
||||
F80
|
||||
S2
|
||||
L90
|
||||
N4
|
||||
W2
|
||||
L180
|
||||
F81
|
||||
R180
|
||||
N4
|
||||
F8
|
||||
W4
|
||||
S4
|
||||
R90
|
||||
F34
|
||||
W2
|
||||
L180
|
||||
F49
|
||||
S4
|
||||
E4
|
||||
R90
|
||||
W2
|
||||
F75
|
||||
R90
|
||||
S5
|
||||
E4
|
||||
L90
|
||||
N3
|
||||
W4
|
||||
R90
|
||||
N4
|
||||
E3
|
||||
F62
|
||||
R90
|
||||
E4
|
||||
N2
|
||||
W3
|
||||
N1
|
||||
R90
|
||||
F75
|
||||
E1
|
||||
L180
|
||||
S3
|
||||
W1
|
||||
N2
|
||||
W5
|
||||
N3
|
||||
F70
|
||||
L90
|
||||
W1
|
||||
S2
|
||||
L270
|
||||
E5
|
||||
F21
|
||||
S3
|
||||
W3
|
||||
R90
|
||||
F3
|
||||
N3
|
||||
F85
|
||||
E5
|
||||
R90
|
||||
F8
|
||||
W2
|
||||
S3
|
||||
W4
|
||||
F38
|
||||
N5
|
||||
F54
|
||||
L90
|
||||
W3
|
||||
R90
|
||||
E5
|
||||
F2
|
||||
S5
|
||||
F79
|
||||
N4
|
||||
E2
|
||||
R180
|
||||
W2
|
||||
N1
|
||||
R90
|
||||
F57
|
||||
W4
|
||||
S1
|
||||
F27
|
||||
E5
|
||||
F31
|
||||
R90
|
||||
F11
|
||||
S5
|
||||
W4
|
||||
N3
|
||||
W1
|
||||
S1
|
||||
F93
|
||||
N3
|
||||
L180
|
||||
E1
|
||||
F63
|
||||
E2
|
||||
R180
|
||||
F99
|
||||
N3
|
||||
E3
|
||||
N3
|
||||
W5
|
||||
F66
|
||||
E5
|
||||
R90
|
||||
S1
|
||||
L90
|
||||
N1
|
||||
R90
|
||||
W5
|
||||
R90
|
||||
L90
|
||||
E4
|
||||
R270
|
||||
W3
|
||||
N5
|
||||
R90
|
||||
S5
|
||||
F8
|
||||
F93
|
||||
E3
|
||||
N4
|
||||
F48
|
||||
W1
|
||||
R180
|
||||
N1
|
||||
R90
|
||||
W3
|
||||
R180
|
||||
F3
|
||||
R180
|
||||
F8
|
||||
N4
|
||||
E1
|
||||
F34
|
||||
N1
|
||||
F33
|
||||
N4
|
||||
R90
|
||||
L180
|
||||
E3
|
||||
F35
|
||||
S5
|
||||
F64
|
||||
L90
|
||||
E4
|
||||
F30
|
||||
R90
|
||||
L90
|
||||
E5
|
||||
N4
|
||||
R180
|
||||
S2
|
||||
W3
|
||||
R90
|
||||
F35
|
||||
L180
|
||||
E2
|
||||
S3
|
||||
E5
|
||||
L90
|
||||
N5
|
||||
R90
|
||||
R90
|
||||
N4
|
||||
E5
|
||||
F34
|
||||
W5
|
||||
W4
|
||||
L90
|
||||
E2
|
||||
N2
|
||||
S5
|
||||
F85
|
||||
S5
|
||||
F98
|
||||
W1
|
||||
S3
|
||||
F7
|
||||
E2
|
||||
S4
|
||||
F27
|
||||
L180
|
||||
F30
|
||||
L90
|
||||
W1
|
||||
F87
|
||||
W1
|
||||
E2
|
||||
E2
|
||||
N3
|
||||
F64
|
||||
E4
|
||||
F31
|
||||
L270
|
||||
S3
|
||||
W2
|
||||
F60
|
||||
S2
|
||||
E1
|
||||
L180
|
||||
F2
|
||||
W3
|
||||
S3
|
||||
E3
|
||||
R180
|
||||
F12
|
||||
L180
|
||||
E1
|
||||
R90
|
||||
L180
|
||||
F60
|
||||
R90
|
||||
E4
|
||||
R180
|
||||
E3
|
||||
S1
|
||||
E3
|
||||
S1
|
||||
F86
|
||||
R90
|
||||
E1
|
||||
S4
|
||||
F47
|
||||
N4
|
||||
E4
|
||||
N4
|
||||
W4
|
||||
R90
|
||||
S3
|
||||
F81
|
||||
S1
|
||||
E1
|
||||
L270
|
||||
S2
|
||||
L90
|
||||
E5
|
||||
F62
|
||||
W4
|
||||
F78
|
||||
L90
|
||||
F18
|
||||
S5
|
||||
R180
|
||||
S1
|
||||
R270
|
||||
S3
|
||||
W5
|
||||
F3
|
||||
N1
|
||||
R90
|
||||
N4
|
||||
F59
|
||||
N1
|
||||
W4
|
||||
R90
|
||||
E3
|
||||
N3
|
||||
N4
|
||||
L90
|
||||
W5
|
||||
S2
|
||||
L90
|
||||
N2
|
||||
W1
|
||||
L180
|
||||
F49
|
||||
N4
|
||||
F14
|
||||
L180
|
||||
N2
|
||||
F43
|
||||
S3
|
||||
F84
|
||||
E3
|
||||
R180
|
||||
S4
|
||||
W1
|
||||
F90
|
||||
F58
|
||||
W3
|
||||
F18
|
||||
E5
|
||||
L90
|
||||
F72
|
||||
W1
|
||||
N1
|
||||
R90
|
||||
S3
|
||||
F79
|
||||
E4
|
||||
S4
|
||||
F31
|
||||
N4
|
||||
F66
|
||||
L90
|
||||
W1
|
||||
N2
|
||||
E4
|
||||
F74
|
||||
W1
|
||||
N2
|
||||
E5
|
||||
S5
|
||||
L90
|
||||
E3
|
||||
F71
|
||||
N3
|
||||
R90
|
||||
N4
|
||||
E2
|
||||
N2
|
||||
F83
|
||||
L90
|
||||
W4
|
||||
F64
|
||||
L90
|
||||
W1
|
||||
S2
|
||||
E4
|
||||
F48
|
||||
S3
|
||||
W5
|
||||
L90
|
||||
E5
|
||||
S1
|
||||
L180
|
||||
E4
|
||||
N4
|
||||
F40
|
||||
E4
|
||||
R270
|
||||
F85
|
||||
E4
|
||||
R90
|
||||
L90
|
||||
S1
|
||||
R270
|
||||
W1
|
||||
R180
|
||||
F72
|
||||
S2
|
||||
R90
|
||||
F63
|
||||
R180
|
||||
F93
|
||||
E4
|
||||
S4
|
||||
R90
|
||||
W3
|
||||
R90
|
||||
F10
|
||||
E4
|
||||
F93
|
||||
R180
|
||||
E1
|
||||
E3
|
||||
R90
|
||||
W1
|
||||
L180
|
||||
F83
|
||||
W4
|
||||
F41
|
||||
W4
|
||||
R90
|
||||
F1
|
||||
L90
|
||||
W4
|
||||
L90
|
||||
N4
|
||||
R180
|
||||
S5
|
||||
F63
|
||||
S2
|
||||
E4
|
||||
R90
|
||||
F90
|
||||
E5
|
||||
S2
|
||||
L90
|
||||
F64
|
||||
R90
|
||||
L90
|
||||
N1
|
||||
E4
|
||||
F20
|
||||
W3
|
||||
N4
|
||||
R90
|
||||
W5
|
||||
N1
|
||||
E5
|
||||
W4
|
||||
R90
|
||||
N1
|
||||
F72
|
||||
S5
|
||||
F78
|
||||
S2
|
||||
R180
|
||||
N4
|
||||
L180
|
||||
N5
|
||||
F22
|
||||
W4
|
||||
R180
|
||||
F19
|
||||
W3
|
||||
L90
|
||||
E4
|
||||
F27
|
||||
W5
|
||||
S4
|
||||
E4
|
||||
F34
|
||||
N4
|
||||
F40
|
||||
N3
|
||||
R90
|
||||
L90
|
||||
S2
|
||||
W1
|
||||
R90
|
||||
E3
|
||||
R90
|
||||
N1
|
||||
W4
|
||||
F93
|
||||
N5
|
||||
L90
|
||||
F7
|
||||
E1
|
||||
L90
|
||||
W4
|
||||
N3
|
||||
E5
|
||||
F62
|
||||
R90
|
||||
W4
|
||||
L90
|
||||
S3
|
||||
E4
|
||||
L270
|
||||
S3
|
||||
W5
|
||||
S2
|
||||
F30
|
||||
N2
|
||||
F70
|
||||
S5
|
||||
W1
|
||||
S3
|
||||
R90
|
||||
E4
|
||||
S5
|
||||
L90
|
||||
S2
|
||||
R90
|
||||
W1
|
||||
L90
|
||||
W5
|
||||
F8
|
||||
R90
|
||||
N4
|
||||
L180
|
||||
N5
|
||||
L90
|
||||
N3
|
||||
F30
|
||||
W2
|
||||
F39
|
||||
E3
|
||||
F17
|
||||
W3
|
||||
S1
|
||||
F48
|
||||
E1
|
||||
R90
|
||||
F35
|
||||
W2
|
||||
L180
|
||||
S1
|
||||
L90
|
||||
E5
|
||||
S1
|
||||
R90
|
||||
E2
|
||||
S5
|
||||
W2
|
||||
N1
|
||||
E3
|
||||
F100
|
||||
S2
|
||||
E4
|
||||
L90
|
||||
W5
|
||||
R90
|
||||
F81
|
||||
S4
|
||||
R90
|
||||
F80
|
69
2020/d12/ex2/ex2.py
Executable file
69
2020/d12/ex2/ex2.py
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Tuple
|
||||
|
||||
Instruction = Tuple[str, int]
|
||||
Position = Tuple[int, int]
|
||||
|
||||
|
||||
@dataclass
|
||||
class Ship:
|
||||
pos: Position
|
||||
rel_waypoint: Position
|
||||
|
||||
|
||||
ORIENTATIONS = ["N", "W", "S", "E"]
|
||||
MOVES = {
|
||||
"N": (1, 0),
|
||||
"W": (0, -1),
|
||||
"S": (-1, 0),
|
||||
"E": (0, 1),
|
||||
}
|
||||
|
||||
|
||||
def move_ship(pos: Ship, instr: Instruction) -> Ship:
|
||||
if instr[0] == "L":
|
||||
assert instr[1] % 90 == 0
|
||||
turns = instr[1] // 90
|
||||
x, y = pos.rel_waypoint
|
||||
for __ in range(turns):
|
||||
x, y = y, -x
|
||||
return Ship(pos.pos, (x, y))
|
||||
elif instr[0] == "R":
|
||||
assert instr[1] % 90 == 0
|
||||
turns = instr[1] // 90
|
||||
x, y = pos.rel_waypoint
|
||||
for __ in range(turns):
|
||||
x, y = -y, x
|
||||
return Ship(pos.pos, (x, y))
|
||||
elif instr[0] == "F":
|
||||
dx, dy = pos.rel_waypoint
|
||||
x, y = pos.pos
|
||||
x += dx * instr[1]
|
||||
y += dy * instr[1]
|
||||
return Ship((x, y), pos.rel_waypoint)
|
||||
else:
|
||||
dx, dy = MOVES[instr[0]]
|
||||
x, y = pos.rel_waypoint
|
||||
x += dx * instr[1]
|
||||
y += dy * instr[1]
|
||||
return Ship(pos.pos, (x, y))
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
instructions = [(i[0], int(i[1:])) for i in raw]
|
||||
ship = Ship((0, 0), (1, 10))
|
||||
for i in instructions:
|
||||
ship = move_ship(ship, i)
|
||||
return sum(abs(c) for c in ship.pos)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
785
2020/d12/ex2/input
Normal file
785
2020/d12/ex2/input
Normal file
|
@ -0,0 +1,785 @@
|
|||
N2
|
||||
F85
|
||||
L90
|
||||
W5
|
||||
R90
|
||||
F56
|
||||
F16
|
||||
F98
|
||||
W4
|
||||
S3
|
||||
F92
|
||||
N3
|
||||
W2
|
||||
N3
|
||||
E2
|
||||
S4
|
||||
W1
|
||||
N2
|
||||
F7
|
||||
N2
|
||||
E3
|
||||
S1
|
||||
L90
|
||||
N2
|
||||
E2
|
||||
F13
|
||||
E5
|
||||
S4
|
||||
R90
|
||||
N2
|
||||
W4
|
||||
F55
|
||||
W3
|
||||
N1
|
||||
F93
|
||||
L90
|
||||
N3
|
||||
F72
|
||||
E4
|
||||
W1
|
||||
N2
|
||||
F76
|
||||
S5
|
||||
L90
|
||||
F44
|
||||
N2
|
||||
F81
|
||||
S1
|
||||
F28
|
||||
R270
|
||||
E5
|
||||
N4
|
||||
E5
|
||||
F23
|
||||
R270
|
||||
F53
|
||||
N2
|
||||
L90
|
||||
E5
|
||||
R180
|
||||
N1
|
||||
F99
|
||||
N3
|
||||
E2
|
||||
R180
|
||||
W5
|
||||
F70
|
||||
W5
|
||||
R180
|
||||
F9
|
||||
S1
|
||||
R90
|
||||
S1
|
||||
F58
|
||||
N3
|
||||
N4
|
||||
R180
|
||||
N3
|
||||
R90
|
||||
S5
|
||||
F6
|
||||
E3
|
||||
N4
|
||||
F38
|
||||
W4
|
||||
R180
|
||||
F53
|
||||
R180
|
||||
E2
|
||||
R90
|
||||
W4
|
||||
L180
|
||||
F13
|
||||
N3
|
||||
F80
|
||||
W1
|
||||
R270
|
||||
E2
|
||||
S1
|
||||
F24
|
||||
E5
|
||||
F1
|
||||
S3
|
||||
F34
|
||||
R90
|
||||
F54
|
||||
E4
|
||||
F59
|
||||
E4
|
||||
R180
|
||||
F88
|
||||
R90
|
||||
S1
|
||||
R90
|
||||
F6
|
||||
R90
|
||||
N1
|
||||
F89
|
||||
W3
|
||||
F9
|
||||
L180
|
||||
W1
|
||||
F47
|
||||
R180
|
||||
N2
|
||||
W1
|
||||
F28
|
||||
F73
|
||||
S1
|
||||
F27
|
||||
E2
|
||||
F82
|
||||
W3
|
||||
F38
|
||||
E4
|
||||
L90
|
||||
E4
|
||||
F64
|
||||
W5
|
||||
W3
|
||||
S2
|
||||
L180
|
||||
F22
|
||||
L90
|
||||
F10
|
||||
L90
|
||||
F64
|
||||
E4
|
||||
N4
|
||||
F21
|
||||
S4
|
||||
E3
|
||||
N5
|
||||
F71
|
||||
N3
|
||||
F93
|
||||
N2
|
||||
R90
|
||||
E4
|
||||
F64
|
||||
E1
|
||||
L90
|
||||
F37
|
||||
E5
|
||||
F96
|
||||
W2
|
||||
N4
|
||||
E2
|
||||
R90
|
||||
S1
|
||||
R90
|
||||
W1
|
||||
R180
|
||||
E2
|
||||
S2
|
||||
R90
|
||||
W3
|
||||
S2
|
||||
F94
|
||||
W2
|
||||
L180
|
||||
S2
|
||||
E4
|
||||
F54
|
||||
N2
|
||||
E4
|
||||
S3
|
||||
L180
|
||||
W2
|
||||
N1
|
||||
W2
|
||||
R90
|
||||
F54
|
||||
L180
|
||||
N2
|
||||
F87
|
||||
E2
|
||||
F23
|
||||
W3
|
||||
R180
|
||||
W4
|
||||
S3
|
||||
F93
|
||||
E5
|
||||
R90
|
||||
N4
|
||||
R90
|
||||
S4
|
||||
E3
|
||||
S3
|
||||
F31
|
||||
R90
|
||||
F89
|
||||
E3
|
||||
F73
|
||||
S5
|
||||
F97
|
||||
W1
|
||||
L180
|
||||
F52
|
||||
E3
|
||||
F68
|
||||
R90
|
||||
S2
|
||||
S5
|
||||
F26
|
||||
L180
|
||||
F12
|
||||
E2
|
||||
F83
|
||||
F9
|
||||
N2
|
||||
R90
|
||||
F99
|
||||
R90
|
||||
S4
|
||||
E5
|
||||
R90
|
||||
S4
|
||||
F84
|
||||
W4
|
||||
E5
|
||||
R90
|
||||
F42
|
||||
W4
|
||||
F94
|
||||
W1
|
||||
R270
|
||||
S3
|
||||
E5
|
||||
F23
|
||||
F38
|
||||
W2
|
||||
W1
|
||||
N5
|
||||
E2
|
||||
L180
|
||||
N1
|
||||
F26
|
||||
L90
|
||||
F5
|
||||
R90
|
||||
N5
|
||||
R180
|
||||
F25
|
||||
L90
|
||||
S1
|
||||
N3
|
||||
F62
|
||||
S1
|
||||
F77
|
||||
N3
|
||||
E3
|
||||
L90
|
||||
F93
|
||||
W3
|
||||
E3
|
||||
N2
|
||||
F14
|
||||
N5
|
||||
F80
|
||||
S2
|
||||
L90
|
||||
N4
|
||||
W2
|
||||
L180
|
||||
F81
|
||||
R180
|
||||
N4
|
||||
F8
|
||||
W4
|
||||
S4
|
||||
R90
|
||||
F34
|
||||
W2
|
||||
L180
|
||||
F49
|
||||
S4
|
||||
E4
|
||||
R90
|
||||
W2
|
||||
F75
|
||||
R90
|
||||
S5
|
||||
E4
|
||||
L90
|
||||
N3
|
||||
W4
|
||||
R90
|
||||
N4
|
||||
E3
|
||||
F62
|
||||
R90
|
||||
E4
|
||||
N2
|
||||
W3
|
||||
N1
|
||||
R90
|
||||
F75
|
||||
E1
|
||||
L180
|
||||
S3
|
||||
W1
|
||||
N2
|
||||
W5
|
||||
N3
|
||||
F70
|
||||
L90
|
||||
W1
|
||||
S2
|
||||
L270
|
||||
E5
|
||||
F21
|
||||
S3
|
||||
W3
|
||||
R90
|
||||
F3
|
||||
N3
|
||||
F85
|
||||
E5
|
||||
R90
|
||||
F8
|
||||
W2
|
||||
S3
|
||||
W4
|
||||
F38
|
||||
N5
|
||||
F54
|
||||
L90
|
||||
W3
|
||||
R90
|
||||
E5
|
||||
F2
|
||||
S5
|
||||
F79
|
||||
N4
|
||||
E2
|
||||
R180
|
||||
W2
|
||||
N1
|
||||
R90
|
||||
F57
|
||||
W4
|
||||
S1
|
||||
F27
|
||||
E5
|
||||
F31
|
||||
R90
|
||||
F11
|
||||
S5
|
||||
W4
|
||||
N3
|
||||
W1
|
||||
S1
|
||||
F93
|
||||
N3
|
||||
L180
|
||||
E1
|
||||
F63
|
||||
E2
|
||||
R180
|
||||
F99
|
||||
N3
|
||||
E3
|
||||
N3
|
||||
W5
|
||||
F66
|
||||
E5
|
||||
R90
|
||||
S1
|
||||
L90
|
||||
N1
|
||||
R90
|
||||
W5
|
||||
R90
|
||||
L90
|
||||
E4
|
||||
R270
|
||||
W3
|
||||
N5
|
||||
R90
|
||||
S5
|
||||
F8
|
||||
F93
|
||||
E3
|
||||
N4
|
||||
F48
|
||||
W1
|
||||
R180
|
||||
N1
|
||||
R90
|
||||
W3
|
||||
R180
|
||||
F3
|
||||
R180
|
||||
F8
|
||||
N4
|
||||
E1
|
||||
F34
|
||||
N1
|
||||
F33
|
||||
N4
|
||||
R90
|
||||
L180
|
||||
E3
|
||||
F35
|
||||
S5
|
||||
F64
|
||||
L90
|
||||
E4
|
||||
F30
|
||||
R90
|
||||
L90
|
||||
E5
|
||||
N4
|
||||
R180
|
||||
S2
|
||||
W3
|
||||
R90
|
||||
F35
|
||||
L180
|
||||
E2
|
||||
S3
|
||||
E5
|
||||
L90
|
||||
N5
|
||||
R90
|
||||
R90
|
||||
N4
|
||||
E5
|
||||
F34
|
||||
W5
|
||||
W4
|
||||
L90
|
||||
E2
|
||||
N2
|
||||
S5
|
||||
F85
|
||||
S5
|
||||
F98
|
||||
W1
|
||||
S3
|
||||
F7
|
||||
E2
|
||||
S4
|
||||
F27
|
||||
L180
|
||||
F30
|
||||
L90
|
||||
W1
|
||||
F87
|
||||
W1
|
||||
E2
|
||||
E2
|
||||
N3
|
||||
F64
|
||||
E4
|
||||
F31
|
||||
L270
|
||||
S3
|
||||
W2
|
||||
F60
|
||||
S2
|
||||
E1
|
||||
L180
|
||||
F2
|
||||
W3
|
||||
S3
|
||||
E3
|
||||
R180
|
||||
F12
|
||||
L180
|
||||
E1
|
||||
R90
|
||||
L180
|
||||
F60
|
||||
R90
|
||||
E4
|
||||
R180
|
||||
E3
|
||||
S1
|
||||
E3
|
||||
S1
|
||||
F86
|
||||
R90
|
||||
E1
|
||||
S4
|
||||
F47
|
||||
N4
|
||||
E4
|
||||
N4
|
||||
W4
|
||||
R90
|
||||
S3
|
||||
F81
|
||||
S1
|
||||
E1
|
||||
L270
|
||||
S2
|
||||
L90
|
||||
E5
|
||||
F62
|
||||
W4
|
||||
F78
|
||||
L90
|
||||
F18
|
||||
S5
|
||||
R180
|
||||
S1
|
||||
R270
|
||||
S3
|
||||
W5
|
||||
F3
|
||||
N1
|
||||
R90
|
||||
N4
|
||||
F59
|
||||
N1
|
||||
W4
|
||||
R90
|
||||
E3
|
||||
N3
|
||||
N4
|
||||
L90
|
||||
W5
|
||||
S2
|
||||
L90
|
||||
N2
|
||||
W1
|
||||
L180
|
||||
F49
|
||||
N4
|
||||
F14
|
||||
L180
|
||||
N2
|
||||
F43
|
||||
S3
|
||||
F84
|
||||
E3
|
||||
R180
|
||||
S4
|
||||
W1
|
||||
F90
|
||||
F58
|
||||
W3
|
||||
F18
|
||||
E5
|
||||
L90
|
||||
F72
|
||||
W1
|
||||
N1
|
||||
R90
|
||||
S3
|
||||
F79
|
||||
E4
|
||||
S4
|
||||
F31
|
||||
N4
|
||||
F66
|
||||
L90
|
||||
W1
|
||||
N2
|
||||
E4
|
||||
F74
|
||||
W1
|
||||
N2
|
||||
E5
|
||||
S5
|
||||
L90
|
||||
E3
|
||||
F71
|
||||
N3
|
||||
R90
|
||||
N4
|
||||
E2
|
||||
N2
|
||||
F83
|
||||
L90
|
||||
W4
|
||||
F64
|
||||
L90
|
||||
W1
|
||||
S2
|
||||
E4
|
||||
F48
|
||||
S3
|
||||
W5
|
||||
L90
|
||||
E5
|
||||
S1
|
||||
L180
|
||||
E4
|
||||
N4
|
||||
F40
|
||||
E4
|
||||
R270
|
||||
F85
|
||||
E4
|
||||
R90
|
||||
L90
|
||||
S1
|
||||
R270
|
||||
W1
|
||||
R180
|
||||
F72
|
||||
S2
|
||||
R90
|
||||
F63
|
||||
R180
|
||||
F93
|
||||
E4
|
||||
S4
|
||||
R90
|
||||
W3
|
||||
R90
|
||||
F10
|
||||
E4
|
||||
F93
|
||||
R180
|
||||
E1
|
||||
E3
|
||||
R90
|
||||
W1
|
||||
L180
|
||||
F83
|
||||
W4
|
||||
F41
|
||||
W4
|
||||
R90
|
||||
F1
|
||||
L90
|
||||
W4
|
||||
L90
|
||||
N4
|
||||
R180
|
||||
S5
|
||||
F63
|
||||
S2
|
||||
E4
|
||||
R90
|
||||
F90
|
||||
E5
|
||||
S2
|
||||
L90
|
||||
F64
|
||||
R90
|
||||
L90
|
||||
N1
|
||||
E4
|
||||
F20
|
||||
W3
|
||||
N4
|
||||
R90
|
||||
W5
|
||||
N1
|
||||
E5
|
||||
W4
|
||||
R90
|
||||
N1
|
||||
F72
|
||||
S5
|
||||
F78
|
||||
S2
|
||||
R180
|
||||
N4
|
||||
L180
|
||||
N5
|
||||
F22
|
||||
W4
|
||||
R180
|
||||
F19
|
||||
W3
|
||||
L90
|
||||
E4
|
||||
F27
|
||||
W5
|
||||
S4
|
||||
E4
|
||||
F34
|
||||
N4
|
||||
F40
|
||||
N3
|
||||
R90
|
||||
L90
|
||||
S2
|
||||
W1
|
||||
R90
|
||||
E3
|
||||
R90
|
||||
N1
|
||||
W4
|
||||
F93
|
||||
N5
|
||||
L90
|
||||
F7
|
||||
E1
|
||||
L90
|
||||
W4
|
||||
N3
|
||||
E5
|
||||
F62
|
||||
R90
|
||||
W4
|
||||
L90
|
||||
S3
|
||||
E4
|
||||
L270
|
||||
S3
|
||||
W5
|
||||
S2
|
||||
F30
|
||||
N2
|
||||
F70
|
||||
S5
|
||||
W1
|
||||
S3
|
||||
R90
|
||||
E4
|
||||
S5
|
||||
L90
|
||||
S2
|
||||
R90
|
||||
W1
|
||||
L90
|
||||
W5
|
||||
F8
|
||||
R90
|
||||
N4
|
||||
L180
|
||||
N5
|
||||
L90
|
||||
N3
|
||||
F30
|
||||
W2
|
||||
F39
|
||||
E3
|
||||
F17
|
||||
W3
|
||||
S1
|
||||
F48
|
||||
E1
|
||||
R90
|
||||
F35
|
||||
W2
|
||||
L180
|
||||
S1
|
||||
L90
|
||||
E5
|
||||
S1
|
||||
R90
|
||||
E2
|
||||
S5
|
||||
W2
|
||||
N1
|
||||
E3
|
||||
F100
|
||||
S2
|
||||
E4
|
||||
L90
|
||||
W5
|
||||
R90
|
||||
F81
|
||||
S4
|
||||
R90
|
||||
F80
|
31
2020/d13/ex1/ex1.py
Executable file
31
2020/d13/ex1/ex1.py
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import math
|
||||
import sys
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
def find_first_factor(earliest: int, timings: List[int]) -> Tuple[int, int]:
|
||||
timings = sorted(timings)
|
||||
for t in itertools.count(earliest):
|
||||
for n in timings:
|
||||
if t % n == 0:
|
||||
return t - earliest, n
|
||||
|
||||
assert False # Make Mypy happy
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return math.prod(
|
||||
find_first_factor(int(raw[0]), [int(i) for i in raw[1].split(",") if i != "x"])
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2
2020/d13/ex1/input
Normal file
2
2020/d13/ex1/input
Normal file
|
@ -0,0 +1,2 @@
|
|||
1002462
|
||||
37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,601,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,x,17,x,x,x,x,x,23,x,x,x,x,x,29,x,443,x,x,x,x,x,x,x,x,x,x,x,x,13
|
45
2020/d13/ex2/ex2.py
Executable file
45
2020/d13/ex2/ex2.py
Executable file
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import math
|
||||
import sys
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
def run_contest(timings: List[int]) -> int:
|
||||
# https://rosettacode.org/wiki/Chinese_remainder_theorem#Python_3.6
|
||||
def mul_inv(a: int, b: int) -> int:
|
||||
b0 = b
|
||||
x0, x1 = 0, 1
|
||||
if b == 1:
|
||||
return 1
|
||||
while a > 1:
|
||||
q = a // b
|
||||
a, b = b, a % b
|
||||
x0, x1 = x1 - q * x0, x0
|
||||
if x1 < 0:
|
||||
x1 += b0
|
||||
return x1
|
||||
|
||||
def chinese_remainder(residue_mapping: Dict[int, int]) -> int:
|
||||
res = 0
|
||||
prod = math.prod(residue_mapping)
|
||||
for n_i, a_i in residue_mapping.items():
|
||||
p = prod // n_i
|
||||
res += a_i * mul_inv(p, n_i) * p
|
||||
return res % prod
|
||||
|
||||
residues = {t: -i for (i, t) in enumerate(timings) if t > 0}
|
||||
return chinese_remainder(residues)
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return run_contest([int(i) if i != "x" else -1 for i in raw[1].split(",")])
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2
2020/d13/ex2/input
Normal file
2
2020/d13/ex2/input
Normal file
|
@ -0,0 +1,2 @@
|
|||
1002462
|
||||
37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,601,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,x,17,x,x,x,x,x,23,x,x,x,x,x,29,x,443,x,x,x,x,x,x,x,x,x,x,x,x,13
|
44
2020/d14/ex1/ex1.py
Executable file
44
2020/d14/ex1/ex1.py
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
import re
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
@dataclass
|
||||
class Mask:
|
||||
ones: int
|
||||
zeros: int
|
||||
|
||||
|
||||
Memory = Dict[int, int]
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
mask = Mask(
|
||||
0,
|
||||
(2 << 36) - 1,
|
||||
)
|
||||
mem_pattern = re.compile("mem\\[([0-9]+)\\] = ([0-9]+)")
|
||||
mask_pattern = re.compile("mask = ([01X]+)")
|
||||
mem: Memory = {}
|
||||
for instr in raw:
|
||||
if (mem_match := mem_pattern.match(instr)) is not None:
|
||||
addr, val = int(mem_match.group(1)), int(mem_match.group(2))
|
||||
val |= mask.ones
|
||||
val &= mask.zeros
|
||||
mem[addr] = val
|
||||
elif (mask_match := mask_pattern.match(instr)) is not None:
|
||||
ones = int(mask_match.group(1).replace("X", "0"), 2)
|
||||
zeros = int(mask_match.group(1).replace("X", "1"), 2)
|
||||
mask = Mask(ones, zeros)
|
||||
return sum(mem.values())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
575
2020/d14/ex1/input
Normal file
575
2020/d14/ex1/input
Normal file
|
@ -0,0 +1,575 @@
|
|||
mask = 110100X1X01011X01X0X000111X00XX1010X
|
||||
mem[29267] = 4155
|
||||
mem[6177] = 494929
|
||||
mem[47500] = 15063410
|
||||
mask = 11110X000010XX10X11X00X11010X0X00101
|
||||
mem[10164] = 73599
|
||||
mem[61707] = 15191
|
||||
mem[53825] = 69618638
|
||||
mem[15953] = 10067309
|
||||
mem[39889] = 10761258
|
||||
mask = 11XXX0XX001X01101111X001000X01X10000
|
||||
mem[6917] = 2088
|
||||
mem[10383] = 52991144
|
||||
mem[14304] = 84876
|
||||
mem[6464] = 14167
|
||||
mask = X11X0X00001010101XX101100X011X000XX1
|
||||
mem[58256] = 51753803
|
||||
mem[2919] = 21619
|
||||
mask = 111100X00010101011X1XXXXX01X000001X1
|
||||
mem[13063] = 6587
|
||||
mem[28673] = 3893
|
||||
mem[53317] = 236744
|
||||
mem[64240] = 29367045
|
||||
mask = XX11101X0011X01X1111X001X1X000101110
|
||||
mem[59497] = 6945823
|
||||
mem[44552] = 193130494
|
||||
mem[15034] = 10641
|
||||
mem[25467] = 17061678
|
||||
mask = X11110X11X11X000110110010110011X0001
|
||||
mem[22485] = 90244
|
||||
mem[38996] = 221133
|
||||
mem[15034] = 12927587
|
||||
mem[4425] = 31960477
|
||||
mem[18544] = 51522085
|
||||
mask = 111100100010X0101XX1110100000XXX0001
|
||||
mem[53765] = 1528530
|
||||
mem[18576] = 68702
|
||||
mem[6484] = 170802
|
||||
mem[62813] = 857
|
||||
mask = 1X1101010X1X111X110101X1010100010010
|
||||
mem[34688] = 36117345
|
||||
mem[12832] = 14851833
|
||||
mem[12097] = 43
|
||||
mem[63931] = 875829
|
||||
mask = 10XXX01100101010X1X111010000101101X1
|
||||
mem[33582] = 28611764
|
||||
mem[53969] = 2641
|
||||
mem[53107] = 99965
|
||||
mem[40648] = 1834153
|
||||
mem[55768] = 974
|
||||
mem[52274] = 7634
|
||||
mask = 111010X10010111X1111X0XXX00110110001
|
||||
mem[43784] = 12232
|
||||
mem[23109] = 11403
|
||||
mem[18521] = 145694
|
||||
mem[12479] = 621
|
||||
mask = XX000011001000101111XX101X1X10101X11
|
||||
mem[22233] = 30348
|
||||
mem[7554] = 346199
|
||||
mem[1904] = 12735
|
||||
mem[23360] = 73797
|
||||
mem[22803] = 62630115
|
||||
mask = 1110X0X0X010X01011X10110001X00XX0110
|
||||
mem[17347] = 310008019
|
||||
mem[39889] = 8179468
|
||||
mem[57304] = 861379
|
||||
mem[2513] = 10343
|
||||
mask = 1111X00100101X1X110101111111010000XX
|
||||
mem[49939] = 39353857
|
||||
mem[48794] = 4266
|
||||
mem[16061] = 2768
|
||||
mem[7728] = 103608
|
||||
mem[17473] = 8980
|
||||
mask = 1001XXX10X0X11X0010100001100X0110101
|
||||
mem[21497] = 412878
|
||||
mem[49939] = 429971
|
||||
mem[3405] = 20518
|
||||
mem[6160] = 51622
|
||||
mem[43784] = 179922643
|
||||
mask = 101100X1001X10XX1101X00XX0101000100X
|
||||
mem[52378] = 1530
|
||||
mem[11326] = 121760772
|
||||
mem[58232] = 164870285
|
||||
mem[21604] = 17658898
|
||||
mem[56257] = 373
|
||||
mem[37783] = 7760640
|
||||
mem[3927] = 427054839
|
||||
mask = 1111XXX10010X11X110101011X10XX10000X
|
||||
mem[18153] = 234818
|
||||
mem[56755] = 531
|
||||
mem[50940] = 4428
|
||||
mem[14849] = 2185318
|
||||
mask = 10110001X0101010X101010X10000X110001
|
||||
mem[53880] = 33275
|
||||
mem[61621] = 40021
|
||||
mem[10319] = 9468
|
||||
mem[34607] = 1186
|
||||
mem[43043] = 51628146
|
||||
mem[14912] = 2626679
|
||||
mem[4627] = 377
|
||||
mask = 111X0X00XXX01110011X10001X1110010101
|
||||
mem[39892] = 6297
|
||||
mem[13182] = 4721
|
||||
mem[41736] = 497649
|
||||
mem[40923] = 905
|
||||
mask = 1X1X00110010011X1110X0001X10011XXX00
|
||||
mem[27118] = 898
|
||||
mem[59800] = 499005720
|
||||
mask = 11X00101001011100X01X01XX100XX010110
|
||||
mem[56505] = 23945612
|
||||
mem[13987] = 14200131
|
||||
mem[30557] = 10396
|
||||
mask = 1110000100X1X01X011111X001101011010X
|
||||
mem[22942] = 642242
|
||||
mem[43083] = 787
|
||||
mem[55307] = 818610470
|
||||
mem[13145] = 35815
|
||||
mask = 00101X01001010X011111101X1001X010101
|
||||
mem[34] = 928
|
||||
mem[45041] = 12613
|
||||
mem[20825] = 18260
|
||||
mem[33068] = 34949
|
||||
mem[51299] = 1228577
|
||||
mask = X11X0001101X001X11010001110X00X01X11
|
||||
mem[5587] = 3120
|
||||
mem[49934] = 166656215
|
||||
mem[12068] = 15929077
|
||||
mem[51471] = 225039
|
||||
mem[35781] = 703735
|
||||
mem[2227] = 788305092
|
||||
mem[30564] = 4758296
|
||||
mask = 1111X1X000100X10X10010011XX011010110
|
||||
mem[44917] = 195410918
|
||||
mem[33352] = 480672
|
||||
mem[18755] = 6376
|
||||
mask = X1X1010000100010XXX0XXX011X011010000
|
||||
mem[48717] = 6124
|
||||
mem[6213] = 13466626
|
||||
mem[33804] = 41450
|
||||
mem[42319] = 1001042
|
||||
mem[32039] = 22800
|
||||
mem[37805] = 3719
|
||||
mem[21650] = 5310058
|
||||
mask = 1X110X0X00101X10110100111X10000X00X1
|
||||
mem[64021] = 527213
|
||||
mem[54049] = 2076239
|
||||
mem[23361] = 10197597
|
||||
mem[29280] = 28451017
|
||||
mem[3136] = 46819
|
||||
mem[21711] = 62402971
|
||||
mask = 1X01000100X01110X101000101000XX10X01
|
||||
mem[20911] = 1251
|
||||
mem[3136] = 84
|
||||
mem[27425] = 174128253
|
||||
mem[20825] = 20910
|
||||
mem[36929] = 13761934
|
||||
mem[44528] = 983
|
||||
mask = 1111X000001X001X11111XX1X00X0110000X
|
||||
mem[516] = 6216446
|
||||
mem[33582] = 140720
|
||||
mem[11248] = 208955105
|
||||
mem[42641] = 4364
|
||||
mask = 101X1X10101X10001XXX0001111100011X11
|
||||
mem[38531] = 39598
|
||||
mem[46500] = 52608117
|
||||
mem[43473] = 96876
|
||||
mem[14304] = 59167889
|
||||
mem[53240] = 15525
|
||||
mask = X001100X00X01110111X1101010X00101111
|
||||
mem[14918] = 2357
|
||||
mem[6160] = 1208519
|
||||
mem[34729] = 1611506
|
||||
mem[51158] = 2346
|
||||
mask = 111X00100000101011010111001110XXX1X0
|
||||
mem[28673] = 331536
|
||||
mem[43917] = 324
|
||||
mem[45633] = 398602
|
||||
mem[49398] = 1861
|
||||
mem[1376] = 625904
|
||||
mask = 01101X00001010100101100X101X10X00011
|
||||
mem[28094] = 8805622
|
||||
mem[30532] = 3723
|
||||
mem[4708] = 14406
|
||||
mem[9094] = 50623
|
||||
mem[61707] = 73798
|
||||
mem[4885] = 224
|
||||
mask = 11X1000X001011X011010X01010XX10X0001
|
||||
mem[7236] = 865782
|
||||
mem[15953] = 487381549
|
||||
mask = XX1011000010X11X010X11111100X11100XX
|
||||
mem[18078] = 16242735
|
||||
mem[5995] = 18850
|
||||
mem[9604] = 839527
|
||||
mem[47055] = 216488
|
||||
mem[4059] = 554189
|
||||
mem[12823] = 346
|
||||
mask = 111100010010111X1X01X1110001X001X000
|
||||
mem[936] = 6429561
|
||||
mem[40513] = 1695095
|
||||
mem[60924] = 252
|
||||
mem[55142] = 557439
|
||||
mask = 10111010X010X0X01XX1100111010X1X1X00
|
||||
mem[38842] = 738
|
||||
mem[30409] = 10094059
|
||||
mem[303] = 98943
|
||||
mem[8017] = 251227
|
||||
mask = X1X0X00100100010X101001100110001X100
|
||||
mem[57304] = 1975648
|
||||
mem[56257] = 1580
|
||||
mem[45571] = 14800
|
||||
mask = 0XX00011001000X0X1111X11101X101X1000
|
||||
mem[43189] = 4422
|
||||
mem[40391] = 167654070
|
||||
mask = 1110X01100100X10111XX01X1000XX01100X
|
||||
mem[33804] = 1018
|
||||
mem[29496] = 93900747
|
||||
mem[9245] = 138506
|
||||
mem[62151] = 674748
|
||||
mem[4762] = 434956
|
||||
mem[37596] = 103373
|
||||
mem[27932] = 5730935
|
||||
mask = 0111X0000010101X111X01001010101110X0
|
||||
mem[36174] = 5162986
|
||||
mem[33114] = 3116668
|
||||
mem[64325] = 3171
|
||||
mem[6917] = 5566099
|
||||
mem[30076] = 176956
|
||||
mem[14847] = 60238674
|
||||
mask = 1110100X00100010XXX1X110000000001X01
|
||||
mem[2546] = 7549354
|
||||
mem[22803] = 386154
|
||||
mem[28386] = 86719
|
||||
mask = 11110100X00011X011X10X0011011010X100
|
||||
mem[52611] = 131
|
||||
mem[47628] = 266
|
||||
mem[22198] = 764
|
||||
mem[4444] = 406
|
||||
mem[20006] = 3520555
|
||||
mask = 10111X101010X000100110011100X01X1010
|
||||
mem[15300] = 345854040
|
||||
mem[49359] = 38235897
|
||||
mem[38614] = 54370972
|
||||
mem[18472] = 94915
|
||||
mem[36746] = 697
|
||||
mask = 11111011X011101X111X10100100000X0111
|
||||
mem[29295] = 943139945
|
||||
mem[9245] = 1505677
|
||||
mem[14391] = 3398
|
||||
mask = 1001X1X1X1001X10010100001X01XX11X101
|
||||
mem[14613] = 15025
|
||||
mem[58121] = 1912
|
||||
mem[300] = 37310097
|
||||
mask = X011001X001010XX11X1100X00XXX0011110
|
||||
mem[17438] = 69372377
|
||||
mem[39932] = 850
|
||||
mem[53370] = 7579742
|
||||
mem[49975] = 2831104
|
||||
mem[37777] = 2859
|
||||
mem[49238] = 508
|
||||
mem[57733] = 3881
|
||||
mask = 11110010001010X011X1X1X11XX00XX101X0
|
||||
mem[29112] = 64162
|
||||
mem[9687] = 10115647
|
||||
mem[8456] = 404111433
|
||||
mem[23461] = 21916957
|
||||
mem[49272] = 29938
|
||||
mem[20911] = 3016
|
||||
mem[45508] = 27114
|
||||
mask = X11010X000101X10X1X10X1XXX0110000111
|
||||
mem[17094] = 1379888
|
||||
mem[19615] = 633
|
||||
mem[43148] = 125580
|
||||
mem[12097] = 33116239
|
||||
mem[34723] = 9358
|
||||
mask = X111X010010X101011110X00011111000101
|
||||
mem[63053] = 691425156
|
||||
mem[24475] = 286162
|
||||
mem[54863] = 76914
|
||||
mem[58008] = 1422
|
||||
mem[24141] = 657
|
||||
mem[34729] = 49841
|
||||
mask = 1110XXXXX0X011100X0101X1010X10001100
|
||||
mem[14613] = 4510
|
||||
mem[47926] = 39745
|
||||
mem[8475] = 327407289
|
||||
mem[22599] = 699202
|
||||
mem[53880] = 822
|
||||
mem[56755] = 1267566
|
||||
mask = 1X1110X1101X100011X110X01X0001110XX1
|
||||
mem[8272] = 301
|
||||
mem[65364] = 3792396
|
||||
mem[38614] = 591
|
||||
mem[10929] = 4608
|
||||
mem[30304] = 2186
|
||||
mask = 1110000110X0001011010011110000X0X01X
|
||||
mem[12247] = 1533938
|
||||
mem[24376] = 12421
|
||||
mem[16168] = 17660
|
||||
mask = 001000000010101X11X101X00001X00XX0X0
|
||||
mem[606] = 2029
|
||||
mem[55307] = 598939
|
||||
mem[26724] = 59403185
|
||||
mask = 11X10XX000X01X101X01010110000X00000X
|
||||
mem[4022] = 39755
|
||||
mem[39281] = 801343
|
||||
mem[46388] = 161
|
||||
mem[21585] = 11357692
|
||||
mem[45828] = 28056
|
||||
mask = 11111X11101111001101XX11X1010X00X11X
|
||||
mem[47755] = 3034
|
||||
mem[42293] = 208825
|
||||
mem[29700] = 38238
|
||||
mem[22485] = 1319489
|
||||
mask = 110100X0001X101X11010011100X000X0101
|
||||
mem[3549] = 18335450
|
||||
mem[58890] = 2676627
|
||||
mem[58022] = 17558
|
||||
mem[54581] = 2533100
|
||||
mem[10929] = 280423870
|
||||
mem[63555] = 2319
|
||||
mem[2546] = 926
|
||||
mask = 1110X011001XXX101111X1110001X110X001
|
||||
mem[23536] = 4353
|
||||
mem[59601] = 798347
|
||||
mem[20671] = 389086
|
||||
mask = 111100X000101010110101001XX1XX11X110
|
||||
mem[1922] = 27551122
|
||||
mem[19645] = 370473454
|
||||
mem[32150] = 214932
|
||||
mem[22144] = 2339
|
||||
mask = 111000100110X01X1101101XX01111010X00
|
||||
mem[35424] = 110774
|
||||
mem[57733] = 531999
|
||||
mem[45139] = 30278097
|
||||
mem[21648] = 16240
|
||||
mask = 1010X00100X00010111101001X0X00X10010
|
||||
mem[58367] = 71950736
|
||||
mem[855] = 21617593
|
||||
mem[27425] = 1287663
|
||||
mem[45595] = 1472271
|
||||
mem[37043] = 1635315
|
||||
mask = 111X00X1001X110011010010X0001100000X
|
||||
mem[7355] = 208029905
|
||||
mem[52551] = 6755
|
||||
mem[49542] = 11911
|
||||
mem[44588] = 377151
|
||||
mem[64240] = 61021
|
||||
mem[8017] = 3572
|
||||
mask = 0X101000001011X011X101X0000X0000X011
|
||||
mem[47482] = 1568110
|
||||
mem[28053] = 707
|
||||
mem[60195] = 1645
|
||||
mask = 11110000001X101011X1101010110X00011X
|
||||
mem[27869] = 17384703
|
||||
mem[17643] = 2734129
|
||||
mem[12802] = 3774302
|
||||
mem[64154] = 916
|
||||
mask = X111X00X0010110011010X01111001010XX1
|
||||
mem[64313] = 102372
|
||||
mem[1522] = 15753175
|
||||
mem[40584] = 728098
|
||||
mem[4315] = 227246865
|
||||
mem[55272] = 7469
|
||||
mem[15889] = 7541958
|
||||
mem[2464] = 371279
|
||||
mask = XX01X011X01011101101X00XX10X00110100
|
||||
mem[5157] = 275
|
||||
mem[12864] = 4756
|
||||
mem[31054] = 1960
|
||||
mem[52498] = 2797835
|
||||
mem[62151] = 4302055
|
||||
mask = 0X1X00X000101X1X1111010X000101X00110
|
||||
mem[10919] = 612216
|
||||
mem[15357] = 629148
|
||||
mem[52500] = 9503
|
||||
mem[17094] = 7855156
|
||||
mem[6652] = 34492510
|
||||
mem[10426] = 726153
|
||||
mask = 010X00110010001X1111101XXX01X0X00101
|
||||
mem[12974] = 9133
|
||||
mem[14108] = 3766
|
||||
mem[24429] = 1803969
|
||||
mem[55142] = 36626772
|
||||
mem[34019] = 473252
|
||||
mem[33604] = 206855588
|
||||
mask = XX1010X10010X01011X11X0011X01011XX11
|
||||
mem[60027] = 841211
|
||||
mem[21538] = 91609915
|
||||
mem[6123] = 97596
|
||||
mem[50346] = 1087
|
||||
mem[40221] = 644
|
||||
mem[8944] = 551344
|
||||
mask = 111000X0001XX0100111111001100X00000X
|
||||
mem[35547] = 950205
|
||||
mem[3312] = 880
|
||||
mem[48780] = 112556701
|
||||
mem[4531] = 126242
|
||||
mem[39889] = 1541
|
||||
mem[24463] = 9010512
|
||||
mask = 11XX101X1X101X001X0111X101000X1X0001
|
||||
mem[64081] = 140604
|
||||
mem[59066] = 420736
|
||||
mem[48653] = 54226
|
||||
mem[32039] = 128940
|
||||
mem[35847] = 5
|
||||
mask = 1001XX01X000111011X1X101000X0X0X1011
|
||||
mem[58689] = 43170762
|
||||
mem[12832] = 298144839
|
||||
mem[1474] = 132921
|
||||
mem[48057] = 37242
|
||||
mem[50871] = 3602555
|
||||
mem[56611] = 31214078
|
||||
mask = 101X000100X011X01101XX10011X0XX1X011
|
||||
mem[7317] = 2861082
|
||||
mem[59424] = 214468
|
||||
mask = 10X110111011101010110X10111001100XX1
|
||||
mem[19313] = 2195784
|
||||
mem[38614] = 1263318
|
||||
mem[26637] = 54905795
|
||||
mem[8165] = 209848
|
||||
mem[2919] = 173
|
||||
mem[928] = 7285
|
||||
mask = 1011101XX011XX1X10111000011010X11111
|
||||
mem[55792] = 11794686
|
||||
mem[48675] = 377
|
||||
mem[6484] = 857
|
||||
mem[60951] = 523305753
|
||||
mem[40488] = 713
|
||||
mem[61858] = 12068
|
||||
mask = 1110X1XX0010111X01011111X000X0X1011X
|
||||
mem[65124] = 178147455
|
||||
mem[15914] = 3503977
|
||||
mem[35424] = 232628
|
||||
mask = 11X0XXX100100010X1X101001XX100110001
|
||||
mem[14344] = 2670
|
||||
mem[20825] = 27980258
|
||||
mem[2792] = 447228346
|
||||
mem[29177] = 822367210
|
||||
mem[30651] = 1658444
|
||||
mem[14099] = 389
|
||||
mask = 110001X1X010X110X101X011X100X1X10110
|
||||
mem[54275] = 15249248
|
||||
mem[3293] = 9475932
|
||||
mem[8835] = 864371828
|
||||
mem[45269] = 3632
|
||||
mem[19645] = 580157
|
||||
mask = 101X101XX01X10X01X1110X0110X1011011X
|
||||
mem[40765] = 53494316
|
||||
mem[35543] = 11261002
|
||||
mem[13933] = 768
|
||||
mem[38594] = 464498
|
||||
mem[64240] = 22406
|
||||
mask = 110100010X10111011X100X1010001X1X1X0
|
||||
mem[20911] = 225
|
||||
mem[12748] = 621
|
||||
mem[29907] = 363502
|
||||
mem[14613] = 3957288
|
||||
mem[64313] = 389459
|
||||
mem[21648] = 2008398
|
||||
mask = 111X101X00X0X010X1110110X00011X1X011
|
||||
mem[33134] = 1049991943
|
||||
mem[25205] = 4126902
|
||||
mask = 1X10101001101X1011X100X00X1X1101X100
|
||||
mem[18755] = 713
|
||||
mem[38650] = 119518
|
||||
mem[33804] = 3211485
|
||||
mem[14609] = 10752655
|
||||
mem[59822] = 234204205
|
||||
mask = 1X1XX0111X1X11001101100X110100X0X010
|
||||
mem[44041] = 255408886
|
||||
mem[62469] = 22090167
|
||||
mem[12247] = 1760642
|
||||
mask = 1110101000001X101X11010010XX110001XX
|
||||
mem[30389] = 29125
|
||||
mem[10833] = 1979
|
||||
mask = 11111010111X1X001001111X1X1000010001
|
||||
mem[20949] = 90971
|
||||
mem[16774] = 9470584
|
||||
mem[56713] = 73907316
|
||||
mem[9264] = 36226
|
||||
mem[60287] = 571
|
||||
mem[25303] = 16376
|
||||
mask = X1010X0XX01000X0001000X0X0010000X110
|
||||
mem[59573] = 60076
|
||||
mem[14516] = 1634251
|
||||
mem[36459] = 843815961
|
||||
mem[3293] = 265
|
||||
mask = 01010100001X00101100X0X0111X11001101
|
||||
mem[28480] = 437785448
|
||||
mem[29724] = 28414900
|
||||
mem[22867] = 14233982
|
||||
mem[45019] = 1644931
|
||||
mask = 111XX0100XX0101011X1011X001X11X101X0
|
||||
mem[28545] = 461
|
||||
mem[14609] = 3934
|
||||
mem[50765] = 103069037
|
||||
mem[12832] = 1926345
|
||||
mem[36929] = 1633120
|
||||
mem[33372] = 23156328
|
||||
mask = X11X000000XX11X011X1XX0110000X000001
|
||||
mem[12748] = 2069634
|
||||
mem[35456] = 8101313
|
||||
mem[21508] = 243298359
|
||||
mask = X1X01001011X001001010110101100X10011
|
||||
mem[27953] = 3450
|
||||
mem[22680] = 50713870
|
||||
mem[55768] = 182841527
|
||||
mem[29021] = 70952
|
||||
mem[59553] = 38886
|
||||
mem[45283] = 84846018
|
||||
mem[29849] = 66463
|
||||
mask = 100XX1111X0011100X01000X010000000101
|
||||
mem[53280] = 2165
|
||||
mem[551] = 556704
|
||||
mem[3512] = 16238
|
||||
mem[2868] = 27158838
|
||||
mem[23659] = 245809
|
||||
mask = 1110X001X010X0101X01110100000X10111X
|
||||
mem[36789] = 51664764
|
||||
mem[33348] = 1689925
|
||||
mem[19745] = 849985
|
||||
mem[7335] = 3678
|
||||
mem[25634] = 2206
|
||||
mem[13782] = 1985
|
||||
mask = 11110000X0100110XX11X0110100X0110001
|
||||
mem[18372] = 193162
|
||||
mem[5878] = 7411977
|
||||
mem[30564] = 89127
|
||||
mem[45210] = 64823202
|
||||
mem[22016] = 3987667
|
||||
mem[7092] = 370183817
|
||||
mem[64313] = 2487681
|
||||
mask = 10X0000100100X101X1X1101110000X0X011
|
||||
mem[6160] = 9833
|
||||
mem[26168] = 120117155
|
||||
mem[13319] = 18180
|
||||
mask = 1X01X001X0X01X1011110001100X0110X100
|
||||
mem[29267] = 385
|
||||
mem[13597] = 535380132
|
||||
mem[58085] = 3408333
|
||||
mem[46178] = 246464
|
||||
mem[64848] = 140510
|
||||
mem[19733] = 322520311
|
||||
mask = 1101101110XX1000X001101110000000X1X0
|
||||
mem[56355] = 894
|
||||
mem[13795] = 13763
|
||||
mem[38247] = 1412147
|
||||
mem[46043] = 10668
|
||||
mem[9370] = 8326048
|
||||
mem[27470] = 524
|
||||
mask = 111010010X1000100X01X1XX10XX0XX10000
|
||||
mem[45269] = 129135
|
||||
mem[33483] = 11595926
|
||||
mem[9827] = 18572496
|
||||
mem[27939] = 32963714
|
||||
mem[48103] = 89693846
|
||||
mask = X11XX111001001101101010101000X000101
|
||||
mem[12666] = 61469
|
||||
mem[40505] = 14463
|
||||
mem[49277] = 118992
|
||||
mem[16161] = 105
|
||||
mem[23321] = 183700
|
||||
mem[48653] = 930591910
|
||||
mask = 111X00100X0X1010110100001X011X1X00X0
|
||||
mem[59706] = 227615179
|
||||
mem[21221] = 1424545
|
||||
mem[54816] = 37682162
|
||||
mem[57789] = 91718
|
||||
mem[25191] = 3615219
|
||||
mem[10390] = 240
|
||||
mask = 1110X0XX001XX010X1110110001011010X01
|
||||
mem[60974] = 5579328
|
||||
mem[61131] = 337545
|
||||
mem[16774] = 2030
|
||||
mem[6637] = 5249
|
56
2020/d14/ex2/ex2.py
Executable file
56
2020/d14/ex2/ex2.py
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python
|
||||
import itertools
|
||||
import re
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from typing import Dict, Iterator, List
|
||||
|
||||
|
||||
@dataclass
|
||||
class Mask:
|
||||
ones: int
|
||||
zeros: int
|
||||
|
||||
|
||||
Memory = Dict[int, int]
|
||||
|
||||
|
||||
def gen_floats(xs: int) -> Iterator[int]:
|
||||
x_positions = [i for i in range(36) if (1 << i) & xs]
|
||||
|
||||
return (
|
||||
sum(1 << x_positions[i] for i, v in enumerate(val) if v == 1)
|
||||
for val in itertools.product([0, 1], repeat=len(x_positions))
|
||||
)
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
mask = Mask(
|
||||
0,
|
||||
(2 << 36) - 1,
|
||||
)
|
||||
mem_pattern = re.compile("mem\\[([0-9]+)\\] = ([0-9]+)")
|
||||
mask_pattern = re.compile("mask = ([01X]+)")
|
||||
mem: Memory = {}
|
||||
for instr in raw:
|
||||
if (mem_match := mem_pattern.match(instr)) is not None:
|
||||
addr, val = int(mem_match.group(1)), int(mem_match.group(2))
|
||||
addr |= mask.ones
|
||||
xs = ~mask.ones & mask.zeros
|
||||
addr &= ~xs # Put floating bits to 0
|
||||
for x in gen_floats(xs):
|
||||
mem[addr | x] = val
|
||||
elif (mask_match := mask_pattern.match(instr)) is not None:
|
||||
ones = int(mask_match.group(1).replace("X", "0"), 2)
|
||||
zeros = int(mask_match.group(1).replace("X", "1"), 2)
|
||||
mask = Mask(ones, zeros)
|
||||
return sum(mem.values())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
575
2020/d14/ex2/input
Normal file
575
2020/d14/ex2/input
Normal file
|
@ -0,0 +1,575 @@
|
|||
mask = 110100X1X01011X01X0X000111X00XX1010X
|
||||
mem[29267] = 4155
|
||||
mem[6177] = 494929
|
||||
mem[47500] = 15063410
|
||||
mask = 11110X000010XX10X11X00X11010X0X00101
|
||||
mem[10164] = 73599
|
||||
mem[61707] = 15191
|
||||
mem[53825] = 69618638
|
||||
mem[15953] = 10067309
|
||||
mem[39889] = 10761258
|
||||
mask = 11XXX0XX001X01101111X001000X01X10000
|
||||
mem[6917] = 2088
|
||||
mem[10383] = 52991144
|
||||
mem[14304] = 84876
|
||||
mem[6464] = 14167
|
||||
mask = X11X0X00001010101XX101100X011X000XX1
|
||||
mem[58256] = 51753803
|
||||
mem[2919] = 21619
|
||||
mask = 111100X00010101011X1XXXXX01X000001X1
|
||||
mem[13063] = 6587
|
||||
mem[28673] = 3893
|
||||
mem[53317] = 236744
|
||||
mem[64240] = 29367045
|
||||
mask = XX11101X0011X01X1111X001X1X000101110
|
||||
mem[59497] = 6945823
|
||||
mem[44552] = 193130494
|
||||
mem[15034] = 10641
|
||||
mem[25467] = 17061678
|
||||
mask = X11110X11X11X000110110010110011X0001
|
||||
mem[22485] = 90244
|
||||
mem[38996] = 221133
|
||||
mem[15034] = 12927587
|
||||
mem[4425] = 31960477
|
||||
mem[18544] = 51522085
|
||||
mask = 111100100010X0101XX1110100000XXX0001
|
||||
mem[53765] = 1528530
|
||||
mem[18576] = 68702
|
||||
mem[6484] = 170802
|
||||
mem[62813] = 857
|
||||
mask = 1X1101010X1X111X110101X1010100010010
|
||||
mem[34688] = 36117345
|
||||
mem[12832] = 14851833
|
||||
mem[12097] = 43
|
||||
mem[63931] = 875829
|
||||
mask = 10XXX01100101010X1X111010000101101X1
|
||||
mem[33582] = 28611764
|
||||
mem[53969] = 2641
|
||||
mem[53107] = 99965
|
||||
mem[40648] = 1834153
|
||||
mem[55768] = 974
|
||||
mem[52274] = 7634
|
||||
mask = 111010X10010111X1111X0XXX00110110001
|
||||
mem[43784] = 12232
|
||||
mem[23109] = 11403
|
||||
mem[18521] = 145694
|
||||
mem[12479] = 621
|
||||
mask = XX000011001000101111XX101X1X10101X11
|
||||
mem[22233] = 30348
|
||||
mem[7554] = 346199
|
||||
mem[1904] = 12735
|
||||
mem[23360] = 73797
|
||||
mem[22803] = 62630115
|
||||
mask = 1110X0X0X010X01011X10110001X00XX0110
|
||||
mem[17347] = 310008019
|
||||
mem[39889] = 8179468
|
||||
mem[57304] = 861379
|
||||
mem[2513] = 10343
|
||||
mask = 1111X00100101X1X110101111111010000XX
|
||||
mem[49939] = 39353857
|
||||
mem[48794] = 4266
|
||||
mem[16061] = 2768
|
||||
mem[7728] = 103608
|
||||
mem[17473] = 8980
|
||||
mask = 1001XXX10X0X11X0010100001100X0110101
|
||||
mem[21497] = 412878
|
||||
mem[49939] = 429971
|
||||
mem[3405] = 20518
|
||||
mem[6160] = 51622
|
||||
mem[43784] = 179922643
|
||||
mask = 101100X1001X10XX1101X00XX0101000100X
|
||||
mem[52378] = 1530
|
||||
mem[11326] = 121760772
|
||||
mem[58232] = 164870285
|
||||
mem[21604] = 17658898
|
||||
mem[56257] = 373
|
||||
mem[37783] = 7760640
|
||||
mem[3927] = 427054839
|
||||
mask = 1111XXX10010X11X110101011X10XX10000X
|
||||
mem[18153] = 234818
|
||||
mem[56755] = 531
|
||||
mem[50940] = 4428
|
||||
mem[14849] = 2185318
|
||||
mask = 10110001X0101010X101010X10000X110001
|
||||
mem[53880] = 33275
|
||||
mem[61621] = 40021
|
||||
mem[10319] = 9468
|
||||
mem[34607] = 1186
|
||||
mem[43043] = 51628146
|
||||
mem[14912] = 2626679
|
||||
mem[4627] = 377
|
||||
mask = 111X0X00XXX01110011X10001X1110010101
|
||||
mem[39892] = 6297
|
||||
mem[13182] = 4721
|
||||
mem[41736] = 497649
|
||||
mem[40923] = 905
|
||||
mask = 1X1X00110010011X1110X0001X10011XXX00
|
||||
mem[27118] = 898
|
||||
mem[59800] = 499005720
|
||||
mask = 11X00101001011100X01X01XX100XX010110
|
||||
mem[56505] = 23945612
|
||||
mem[13987] = 14200131
|
||||
mem[30557] = 10396
|
||||
mask = 1110000100X1X01X011111X001101011010X
|
||||
mem[22942] = 642242
|
||||
mem[43083] = 787
|
||||
mem[55307] = 818610470
|
||||
mem[13145] = 35815
|
||||
mask = 00101X01001010X011111101X1001X010101
|
||||
mem[34] = 928
|
||||
mem[45041] = 12613
|
||||
mem[20825] = 18260
|
||||
mem[33068] = 34949
|
||||
mem[51299] = 1228577
|
||||
mask = X11X0001101X001X11010001110X00X01X11
|
||||
mem[5587] = 3120
|
||||
mem[49934] = 166656215
|
||||
mem[12068] = 15929077
|
||||
mem[51471] = 225039
|
||||
mem[35781] = 703735
|
||||
mem[2227] = 788305092
|
||||
mem[30564] = 4758296
|
||||
mask = 1111X1X000100X10X10010011XX011010110
|
||||
mem[44917] = 195410918
|
||||
mem[33352] = 480672
|
||||
mem[18755] = 6376
|
||||
mask = X1X1010000100010XXX0XXX011X011010000
|
||||
mem[48717] = 6124
|
||||
mem[6213] = 13466626
|
||||
mem[33804] = 41450
|
||||
mem[42319] = 1001042
|
||||
mem[32039] = 22800
|
||||
mem[37805] = 3719
|
||||
mem[21650] = 5310058
|
||||
mask = 1X110X0X00101X10110100111X10000X00X1
|
||||
mem[64021] = 527213
|
||||
mem[54049] = 2076239
|
||||
mem[23361] = 10197597
|
||||
mem[29280] = 28451017
|
||||
mem[3136] = 46819
|
||||
mem[21711] = 62402971
|
||||
mask = 1X01000100X01110X101000101000XX10X01
|
||||
mem[20911] = 1251
|
||||
mem[3136] = 84
|
||||
mem[27425] = 174128253
|
||||
mem[20825] = 20910
|
||||
mem[36929] = 13761934
|
||||
mem[44528] = 983
|
||||
mask = 1111X000001X001X11111XX1X00X0110000X
|
||||
mem[516] = 6216446
|
||||
mem[33582] = 140720
|
||||
mem[11248] = 208955105
|
||||
mem[42641] = 4364
|
||||
mask = 101X1X10101X10001XXX0001111100011X11
|
||||
mem[38531] = 39598
|
||||
mem[46500] = 52608117
|
||||
mem[43473] = 96876
|
||||
mem[14304] = 59167889
|
||||
mem[53240] = 15525
|
||||
mask = X001100X00X01110111X1101010X00101111
|
||||
mem[14918] = 2357
|
||||
mem[6160] = 1208519
|
||||
mem[34729] = 1611506
|
||||
mem[51158] = 2346
|
||||
mask = 111X00100000101011010111001110XXX1X0
|
||||
mem[28673] = 331536
|
||||
mem[43917] = 324
|
||||
mem[45633] = 398602
|
||||
mem[49398] = 1861
|
||||
mem[1376] = 625904
|
||||
mask = 01101X00001010100101100X101X10X00011
|
||||
mem[28094] = 8805622
|
||||
mem[30532] = 3723
|
||||
mem[4708] = 14406
|
||||
mem[9094] = 50623
|
||||
mem[61707] = 73798
|
||||
mem[4885] = 224
|
||||
mask = 11X1000X001011X011010X01010XX10X0001
|
||||
mem[7236] = 865782
|
||||
mem[15953] = 487381549
|
||||
mask = XX1011000010X11X010X11111100X11100XX
|
||||
mem[18078] = 16242735
|
||||
mem[5995] = 18850
|
||||
mem[9604] = 839527
|
||||
mem[47055] = 216488
|
||||
mem[4059] = 554189
|
||||
mem[12823] = 346
|
||||
mask = 111100010010111X1X01X1110001X001X000
|
||||
mem[936] = 6429561
|
||||
mem[40513] = 1695095
|
||||
mem[60924] = 252
|
||||
mem[55142] = 557439
|
||||
mask = 10111010X010X0X01XX1100111010X1X1X00
|
||||
mem[38842] = 738
|
||||
mem[30409] = 10094059
|
||||
mem[303] = 98943
|
||||
mem[8017] = 251227
|
||||
mask = X1X0X00100100010X101001100110001X100
|
||||
mem[57304] = 1975648
|
||||
mem[56257] = 1580
|
||||
mem[45571] = 14800
|
||||
mask = 0XX00011001000X0X1111X11101X101X1000
|
||||
mem[43189] = 4422
|
||||
mem[40391] = 167654070
|
||||
mask = 1110X01100100X10111XX01X1000XX01100X
|
||||
mem[33804] = 1018
|
||||
mem[29496] = 93900747
|
||||
mem[9245] = 138506
|
||||
mem[62151] = 674748
|
||||
mem[4762] = 434956
|
||||
mem[37596] = 103373
|
||||
mem[27932] = 5730935
|
||||
mask = 0111X0000010101X111X01001010101110X0
|
||||
mem[36174] = 5162986
|
||||
mem[33114] = 3116668
|
||||
mem[64325] = 3171
|
||||
mem[6917] = 5566099
|
||||
mem[30076] = 176956
|
||||
mem[14847] = 60238674
|
||||
mask = 1110100X00100010XXX1X110000000001X01
|
||||
mem[2546] = 7549354
|
||||
mem[22803] = 386154
|
||||
mem[28386] = 86719
|
||||
mask = 11110100X00011X011X10X0011011010X100
|
||||
mem[52611] = 131
|
||||
mem[47628] = 266
|
||||
mem[22198] = 764
|
||||
mem[4444] = 406
|
||||
mem[20006] = 3520555
|
||||
mask = 10111X101010X000100110011100X01X1010
|
||||
mem[15300] = 345854040
|
||||
mem[49359] = 38235897
|
||||
mem[38614] = 54370972
|
||||
mem[18472] = 94915
|
||||
mem[36746] = 697
|
||||
mask = 11111011X011101X111X10100100000X0111
|
||||
mem[29295] = 943139945
|
||||
mem[9245] = 1505677
|
||||
mem[14391] = 3398
|
||||
mask = 1001X1X1X1001X10010100001X01XX11X101
|
||||
mem[14613] = 15025
|
||||
mem[58121] = 1912
|
||||
mem[300] = 37310097
|
||||
mask = X011001X001010XX11X1100X00XXX0011110
|
||||
mem[17438] = 69372377
|
||||
mem[39932] = 850
|
||||
mem[53370] = 7579742
|
||||
mem[49975] = 2831104
|
||||
mem[37777] = 2859
|
||||
mem[49238] = 508
|
||||
mem[57733] = 3881
|
||||
mask = 11110010001010X011X1X1X11XX00XX101X0
|
||||
mem[29112] = 64162
|
||||
mem[9687] = 10115647
|
||||
mem[8456] = 404111433
|
||||
mem[23461] = 21916957
|
||||
mem[49272] = 29938
|
||||
mem[20911] = 3016
|
||||
mem[45508] = 27114
|
||||
mask = X11010X000101X10X1X10X1XXX0110000111
|
||||
mem[17094] = 1379888
|
||||
mem[19615] = 633
|
||||
mem[43148] = 125580
|
||||
mem[12097] = 33116239
|
||||
mem[34723] = 9358
|
||||
mask = X111X010010X101011110X00011111000101
|
||||
mem[63053] = 691425156
|
||||
mem[24475] = 286162
|
||||
mem[54863] = 76914
|
||||
mem[58008] = 1422
|
||||
mem[24141] = 657
|
||||
mem[34729] = 49841
|
||||
mask = 1110XXXXX0X011100X0101X1010X10001100
|
||||
mem[14613] = 4510
|
||||
mem[47926] = 39745
|
||||
mem[8475] = 327407289
|
||||
mem[22599] = 699202
|
||||
mem[53880] = 822
|
||||
mem[56755] = 1267566
|
||||
mask = 1X1110X1101X100011X110X01X0001110XX1
|
||||
mem[8272] = 301
|
||||
mem[65364] = 3792396
|
||||
mem[38614] = 591
|
||||
mem[10929] = 4608
|
||||
mem[30304] = 2186
|
||||
mask = 1110000110X0001011010011110000X0X01X
|
||||
mem[12247] = 1533938
|
||||
mem[24376] = 12421
|
||||
mem[16168] = 17660
|
||||
mask = 001000000010101X11X101X00001X00XX0X0
|
||||
mem[606] = 2029
|
||||
mem[55307] = 598939
|
||||
mem[26724] = 59403185
|
||||
mask = 11X10XX000X01X101X01010110000X00000X
|
||||
mem[4022] = 39755
|
||||
mem[39281] = 801343
|
||||
mem[46388] = 161
|
||||
mem[21585] = 11357692
|
||||
mem[45828] = 28056
|
||||
mask = 11111X11101111001101XX11X1010X00X11X
|
||||
mem[47755] = 3034
|
||||
mem[42293] = 208825
|
||||
mem[29700] = 38238
|
||||
mem[22485] = 1319489
|
||||
mask = 110100X0001X101X11010011100X000X0101
|
||||
mem[3549] = 18335450
|
||||
mem[58890] = 2676627
|
||||
mem[58022] = 17558
|
||||
mem[54581] = 2533100
|
||||
mem[10929] = 280423870
|
||||
mem[63555] = 2319
|
||||
mem[2546] = 926
|
||||
mask = 1110X011001XXX101111X1110001X110X001
|
||||
mem[23536] = 4353
|
||||
mem[59601] = 798347
|
||||
mem[20671] = 389086
|
||||
mask = 111100X000101010110101001XX1XX11X110
|
||||
mem[1922] = 27551122
|
||||
mem[19645] = 370473454
|
||||
mem[32150] = 214932
|
||||
mem[22144] = 2339
|
||||
mask = 111000100110X01X1101101XX01111010X00
|
||||
mem[35424] = 110774
|
||||
mem[57733] = 531999
|
||||
mem[45139] = 30278097
|
||||
mem[21648] = 16240
|
||||
mask = 1010X00100X00010111101001X0X00X10010
|
||||
mem[58367] = 71950736
|
||||
mem[855] = 21617593
|
||||
mem[27425] = 1287663
|
||||
mem[45595] = 1472271
|
||||
mem[37043] = 1635315
|
||||
mask = 111X00X1001X110011010010X0001100000X
|
||||
mem[7355] = 208029905
|
||||
mem[52551] = 6755
|
||||
mem[49542] = 11911
|
||||
mem[44588] = 377151
|
||||
mem[64240] = 61021
|
||||
mem[8017] = 3572
|
||||
mask = 0X101000001011X011X101X0000X0000X011
|
||||
mem[47482] = 1568110
|
||||
mem[28053] = 707
|
||||
mem[60195] = 1645
|
||||
mask = 11110000001X101011X1101010110X00011X
|
||||
mem[27869] = 17384703
|
||||
mem[17643] = 2734129
|
||||
mem[12802] = 3774302
|
||||
mem[64154] = 916
|
||||
mask = X111X00X0010110011010X01111001010XX1
|
||||
mem[64313] = 102372
|
||||
mem[1522] = 15753175
|
||||
mem[40584] = 728098
|
||||
mem[4315] = 227246865
|
||||
mem[55272] = 7469
|
||||
mem[15889] = 7541958
|
||||
mem[2464] = 371279
|
||||
mask = XX01X011X01011101101X00XX10X00110100
|
||||
mem[5157] = 275
|
||||
mem[12864] = 4756
|
||||
mem[31054] = 1960
|
||||
mem[52498] = 2797835
|
||||
mem[62151] = 4302055
|
||||
mask = 0X1X00X000101X1X1111010X000101X00110
|
||||
mem[10919] = 612216
|
||||
mem[15357] = 629148
|
||||
mem[52500] = 9503
|
||||
mem[17094] = 7855156
|
||||
mem[6652] = 34492510
|
||||
mem[10426] = 726153
|
||||
mask = 010X00110010001X1111101XXX01X0X00101
|
||||
mem[12974] = 9133
|
||||
mem[14108] = 3766
|
||||
mem[24429] = 1803969
|
||||
mem[55142] = 36626772
|
||||
mem[34019] = 473252
|
||||
mem[33604] = 206855588
|
||||
mask = XX1010X10010X01011X11X0011X01011XX11
|
||||
mem[60027] = 841211
|
||||
mem[21538] = 91609915
|
||||
mem[6123] = 97596
|
||||
mem[50346] = 1087
|
||||
mem[40221] = 644
|
||||
mem[8944] = 551344
|
||||
mask = 111000X0001XX0100111111001100X00000X
|
||||
mem[35547] = 950205
|
||||
mem[3312] = 880
|
||||
mem[48780] = 112556701
|
||||
mem[4531] = 126242
|
||||
mem[39889] = 1541
|
||||
mem[24463] = 9010512
|
||||
mask = 11XX101X1X101X001X0111X101000X1X0001
|
||||
mem[64081] = 140604
|
||||
mem[59066] = 420736
|
||||
mem[48653] = 54226
|
||||
mem[32039] = 128940
|
||||
mem[35847] = 5
|
||||
mask = 1001XX01X000111011X1X101000X0X0X1011
|
||||
mem[58689] = 43170762
|
||||
mem[12832] = 298144839
|
||||
mem[1474] = 132921
|
||||
mem[48057] = 37242
|
||||
mem[50871] = 3602555
|
||||
mem[56611] = 31214078
|
||||
mask = 101X000100X011X01101XX10011X0XX1X011
|
||||
mem[7317] = 2861082
|
||||
mem[59424] = 214468
|
||||
mask = 10X110111011101010110X10111001100XX1
|
||||
mem[19313] = 2195784
|
||||
mem[38614] = 1263318
|
||||
mem[26637] = 54905795
|
||||
mem[8165] = 209848
|
||||
mem[2919] = 173
|
||||
mem[928] = 7285
|
||||
mask = 1011101XX011XX1X10111000011010X11111
|
||||
mem[55792] = 11794686
|
||||
mem[48675] = 377
|
||||
mem[6484] = 857
|
||||
mem[60951] = 523305753
|
||||
mem[40488] = 713
|
||||
mem[61858] = 12068
|
||||
mask = 1110X1XX0010111X01011111X000X0X1011X
|
||||
mem[65124] = 178147455
|
||||
mem[15914] = 3503977
|
||||
mem[35424] = 232628
|
||||
mask = 11X0XXX100100010X1X101001XX100110001
|
||||
mem[14344] = 2670
|
||||
mem[20825] = 27980258
|
||||
mem[2792] = 447228346
|
||||
mem[29177] = 822367210
|
||||
mem[30651] = 1658444
|
||||
mem[14099] = 389
|
||||
mask = 110001X1X010X110X101X011X100X1X10110
|
||||
mem[54275] = 15249248
|
||||
mem[3293] = 9475932
|
||||
mem[8835] = 864371828
|
||||
mem[45269] = 3632
|
||||
mem[19645] = 580157
|
||||
mask = 101X101XX01X10X01X1110X0110X1011011X
|
||||
mem[40765] = 53494316
|
||||
mem[35543] = 11261002
|
||||
mem[13933] = 768
|
||||
mem[38594] = 464498
|
||||
mem[64240] = 22406
|
||||
mask = 110100010X10111011X100X1010001X1X1X0
|
||||
mem[20911] = 225
|
||||
mem[12748] = 621
|
||||
mem[29907] = 363502
|
||||
mem[14613] = 3957288
|
||||
mem[64313] = 389459
|
||||
mem[21648] = 2008398
|
||||
mask = 111X101X00X0X010X1110110X00011X1X011
|
||||
mem[33134] = 1049991943
|
||||
mem[25205] = 4126902
|
||||
mask = 1X10101001101X1011X100X00X1X1101X100
|
||||
mem[18755] = 713
|
||||
mem[38650] = 119518
|
||||
mem[33804] = 3211485
|
||||
mem[14609] = 10752655
|
||||
mem[59822] = 234204205
|
||||
mask = 1X1XX0111X1X11001101100X110100X0X010
|
||||
mem[44041] = 255408886
|
||||
mem[62469] = 22090167
|
||||
mem[12247] = 1760642
|
||||
mask = 1110101000001X101X11010010XX110001XX
|
||||
mem[30389] = 29125
|
||||
mem[10833] = 1979
|
||||
mask = 11111010111X1X001001111X1X1000010001
|
||||
mem[20949] = 90971
|
||||
mem[16774] = 9470584
|
||||
mem[56713] = 73907316
|
||||
mem[9264] = 36226
|
||||
mem[60287] = 571
|
||||
mem[25303] = 16376
|
||||
mask = X1010X0XX01000X0001000X0X0010000X110
|
||||
mem[59573] = 60076
|
||||
mem[14516] = 1634251
|
||||
mem[36459] = 843815961
|
||||
mem[3293] = 265
|
||||
mask = 01010100001X00101100X0X0111X11001101
|
||||
mem[28480] = 437785448
|
||||
mem[29724] = 28414900
|
||||
mem[22867] = 14233982
|
||||
mem[45019] = 1644931
|
||||
mask = 111XX0100XX0101011X1011X001X11X101X0
|
||||
mem[28545] = 461
|
||||
mem[14609] = 3934
|
||||
mem[50765] = 103069037
|
||||
mem[12832] = 1926345
|
||||
mem[36929] = 1633120
|
||||
mem[33372] = 23156328
|
||||
mask = X11X000000XX11X011X1XX0110000X000001
|
||||
mem[12748] = 2069634
|
||||
mem[35456] = 8101313
|
||||
mem[21508] = 243298359
|
||||
mask = X1X01001011X001001010110101100X10011
|
||||
mem[27953] = 3450
|
||||
mem[22680] = 50713870
|
||||
mem[55768] = 182841527
|
||||
mem[29021] = 70952
|
||||
mem[59553] = 38886
|
||||
mem[45283] = 84846018
|
||||
mem[29849] = 66463
|
||||
mask = 100XX1111X0011100X01000X010000000101
|
||||
mem[53280] = 2165
|
||||
mem[551] = 556704
|
||||
mem[3512] = 16238
|
||||
mem[2868] = 27158838
|
||||
mem[23659] = 245809
|
||||
mask = 1110X001X010X0101X01110100000X10111X
|
||||
mem[36789] = 51664764
|
||||
mem[33348] = 1689925
|
||||
mem[19745] = 849985
|
||||
mem[7335] = 3678
|
||||
mem[25634] = 2206
|
||||
mem[13782] = 1985
|
||||
mask = 11110000X0100110XX11X0110100X0110001
|
||||
mem[18372] = 193162
|
||||
mem[5878] = 7411977
|
||||
mem[30564] = 89127
|
||||
mem[45210] = 64823202
|
||||
mem[22016] = 3987667
|
||||
mem[7092] = 370183817
|
||||
mem[64313] = 2487681
|
||||
mask = 10X0000100100X101X1X1101110000X0X011
|
||||
mem[6160] = 9833
|
||||
mem[26168] = 120117155
|
||||
mem[13319] = 18180
|
||||
mask = 1X01X001X0X01X1011110001100X0110X100
|
||||
mem[29267] = 385
|
||||
mem[13597] = 535380132
|
||||
mem[58085] = 3408333
|
||||
mem[46178] = 246464
|
||||
mem[64848] = 140510
|
||||
mem[19733] = 322520311
|
||||
mask = 1101101110XX1000X001101110000000X1X0
|
||||
mem[56355] = 894
|
||||
mem[13795] = 13763
|
||||
mem[38247] = 1412147
|
||||
mem[46043] = 10668
|
||||
mem[9370] = 8326048
|
||||
mem[27470] = 524
|
||||
mask = 111010010X1000100X01X1XX10XX0XX10000
|
||||
mem[45269] = 129135
|
||||
mem[33483] = 11595926
|
||||
mem[9827] = 18572496
|
||||
mem[27939] = 32963714
|
||||
mem[48103] = 89693846
|
||||
mask = X11XX111001001101101010101000X000101
|
||||
mem[12666] = 61469
|
||||
mem[40505] = 14463
|
||||
mem[49277] = 118992
|
||||
mem[16161] = 105
|
||||
mem[23321] = 183700
|
||||
mem[48653] = 930591910
|
||||
mask = 111X00100X0X1010110100001X011X1X00X0
|
||||
mem[59706] = 227615179
|
||||
mem[21221] = 1424545
|
||||
mem[54816] = 37682162
|
||||
mem[57789] = 91718
|
||||
mem[25191] = 3615219
|
||||
mem[10390] = 240
|
||||
mask = 1110X0XX001XX010X1110110001011010X01
|
||||
mem[60974] = 5579328
|
||||
mem[61131] = 337545
|
||||
mem[16774] = 2030
|
||||
mem[6637] = 5249
|
40
2020/d15/ex1/ex1.py
Executable file
40
2020/d15/ex1/ex1.py
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python
|
||||
import itertools
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import Dict, Iterator, List
|
||||
|
||||
|
||||
def nth(iterable: Iterator[int], n: int) -> int:
|
||||
return next(itertools.islice(iterable, n, None))
|
||||
|
||||
|
||||
def spoken(spoken: List[int]) -> Iterator[int]:
|
||||
turn = 0
|
||||
turns: Dict[int, List[int]] = defaultdict(list)
|
||||
for last in spoken:
|
||||
turn += 1
|
||||
turns[last].append(turn)
|
||||
yield last
|
||||
while True:
|
||||
if len(last_turn := turns[last]) < 2:
|
||||
last = 0
|
||||
else:
|
||||
last = last_turn[-1] - last_turn[-2]
|
||||
turn += 1
|
||||
turns[last].append(turn)
|
||||
yield last
|
||||
|
||||
|
||||
def solve(nums: List[int]) -> int:
|
||||
return nth(spoken(nums), 2020 - 1)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
assert len(input) == 1
|
||||
print(solve([int(i) for i in input[0].split(",")]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2020/d15/ex1/input
Normal file
1
2020/d15/ex1/input
Normal file
|
@ -0,0 +1 @@
|
|||
0,13,1,16,6,17
|
40
2020/d15/ex2/ex2.py
Executable file
40
2020/d15/ex2/ex2.py
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python
|
||||
import itertools
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from typing import Dict, Iterator, List
|
||||
|
||||
|
||||
def nth(iterable: Iterator[int], n: int) -> int:
|
||||
return next(itertools.islice(iterable, n, None))
|
||||
|
||||
|
||||
def spoken(spoken: List[int]) -> Iterator[int]:
|
||||
turn = 0
|
||||
turns: Dict[int, List[int]] = defaultdict(list)
|
||||
for last in spoken:
|
||||
turn += 1
|
||||
turns[last].append(turn)
|
||||
yield last
|
||||
while True:
|
||||
if len(last_turn := turns[last]) < 2:
|
||||
last = 0
|
||||
else:
|
||||
last = last_turn[-1] - last_turn[-2]
|
||||
turn += 1
|
||||
turns[last].append(turn)
|
||||
yield last
|
||||
|
||||
|
||||
def solve(nums: List[int]) -> int:
|
||||
return nth(spoken(nums), 30000000 - 1)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
assert len(input) == 1
|
||||
print(solve([int(i) for i in input[0].split(",")]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1
2020/d15/ex2/input
Normal file
1
2020/d15/ex2/input
Normal file
|
@ -0,0 +1 @@
|
|||
0,13,1,16,6,17
|
59
2020/d16/ex1/ex1.py
Executable file
59
2020/d16/ex1/ex1.py
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
from typing import Dict, List, Set, Tuple
|
||||
|
||||
Ranges = Dict[str, Set[int]]
|
||||
Ticket = List[int]
|
||||
|
||||
|
||||
def parse(raw: List[str]) -> Tuple[Ranges, List[Ticket]]:
|
||||
def extract_field_info(line: str) -> Tuple[str, Set[int]]:
|
||||
field, rest = line.split(":")
|
||||
ranges: Set[int] = set()
|
||||
for r in rest.strip().split(" or "):
|
||||
lhs, rhs = r.split("-")
|
||||
ranges |= set(range(int(lhs), int(rhs) + 1))
|
||||
return field, ranges
|
||||
|
||||
def parse_tickets(line: str) -> Ticket:
|
||||
return [int(i) for i in line.split(",")]
|
||||
|
||||
ranges: Ranges = {}
|
||||
tickets: List[Ticket] = []
|
||||
|
||||
should_parse_tickets = False
|
||||
for line in raw:
|
||||
if line == "":
|
||||
should_parse_tickets = True
|
||||
continue
|
||||
if "ticket" in line:
|
||||
continue
|
||||
if should_parse_tickets:
|
||||
tickets.append(parse_tickets(line))
|
||||
else:
|
||||
field, field_ranges = extract_field_info(line)
|
||||
ranges[field] = field_ranges
|
||||
|
||||
return ranges, tickets
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
ranges, tickets = parse(raw)
|
||||
sum = 0
|
||||
|
||||
for ticket in tickets[1:]:
|
||||
for val in ticket:
|
||||
if any(val in r for r in ranges.values()):
|
||||
continue
|
||||
sum += val
|
||||
|
||||
return sum
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
264
2020/d16/ex1/input
Normal file
264
2020/d16/ex1/input
Normal file
|
@ -0,0 +1,264 @@
|
|||
departure location: 44-709 or 728-964
|
||||
departure station: 42-259 or 269-974
|
||||
departure platform: 39-690 or 701-954
|
||||
departure track: 49-909 or 924-965
|
||||
departure date: 48-759 or 779-957
|
||||
departure time: 38-115 or 121-965
|
||||
arrival location: 32-808 or 818-949
|
||||
arrival station: 45-418 or 439-949
|
||||
arrival platform: 35-877 or 894-962
|
||||
arrival track: 26-866 or 872-958
|
||||
class: 32-727 or 736-969
|
||||
duration: 35-446 or 460-968
|
||||
price: 26-545 or 571-961
|
||||
route: 35-207 or 223-960
|
||||
row: 43-156 or 165-955
|
||||
seat: 26-172 or 181-966
|
||||
train: 49-582 or 606-952
|
||||
type: 36-279 or 303-968
|
||||
wagon: 26-657 or 672-959
|
||||
zone: 36-621 or 637-963
|
||||
|
||||
your ticket:
|
||||
83,127,131,137,113,73,139,101,67,53,107,103,59,149,109,61,79,71,97,89
|
||||
|
||||
nearby tickets:
|
||||
539,619,928,309,835,99,521,478,54,340,849,859,376,357,524,841,221,935,806,147
|
||||
231,827,907,526,238,542,181,853,303,143,116,701,206,140,927,203,443,753,151,258
|
||||
445,679,816,617,82,102,197,100,239,490,488,78,707,349,689,335,847,183,144,314
|
||||
476,833,232,489,937,256,87,409,223,364,978,939,398,331,153,945,513,237,934,272
|
||||
492,927,578,788,808,529,739,20,201,688,405,877,228,168,361,521,400,398,618,520
|
||||
332,694,481,571,523,516,395,122,844,358,232,132,315,486,899,154,269,201,831,50
|
||||
907,706,927,126,133,97,217,334,745,751,580,862,526,845,680,125,96,445,863,322
|
||||
498,753,844,670,150,657,853,150,377,487,152,369,500,241,360,204,142,236,948,91
|
||||
578,675,491,230,332,464,258,858,508,330,492,780,494,234,839,645,160,795,896,687
|
||||
814,875,617,185,490,490,501,940,224,751,609,844,442,525,640,609,336,251,532,685
|
||||
684,196,757,841,580,576,18,319,150,249,676,337,155,115,652,638,475,398,789,379
|
||||
445,490,199,140,88,694,184,247,307,386,198,85,905,860,484,244,532,224,681,251
|
||||
172,936,701,440,779,941,639,351,238,70,787,91,259,340,58,541,815,399,238,202
|
||||
715,369,504,226,138,866,783,231,580,147,82,335,533,144,530,462,836,751,473,801
|
||||
932,459,242,947,653,150,618,683,198,608,88,342,948,497,675,53,681,544,315,615
|
||||
422,244,791,929,799,128,374,473,148,931,381,822,318,853,147,367,531,412,242,470
|
||||
464,899,490,846,381,326,271,948,396,318,653,981,310,822,502,895,78,935,78,461
|
||||
231,339,79,530,680,461,863,521,839,517,379,108,395,613,644,751,823,212,206,151
|
||||
526,507,403,354,931,859,787,728,247,781,643,203,847,326,506,79,65,332,91,783
|
||||
571,182,753,841,338,746,254,307,896,648,726,89,314,706,943,464,444,481,465,928
|
||||
184,513,335,941,303,198,537,571,409,337,497,621,350,617,98,897,850,679,794,260
|
||||
235,255,393,310,188,65,943,543,94,374,500,482,122,992,656,523,704,742,331,792
|
||||
315,152,320,983,493,166,754,376,619,480,149,929,330,80,529,131,150,57,251,842
|
||||
54,77,540,141,61,205,273,214,745,145,166,131,93,525,500,521,223,52,237,404
|
||||
300,616,784,250,852,354,327,944,675,859,673,941,789,829,234,104,842,85,742,98
|
||||
110,244,95,93,529,162,82,309,142,680,65,410,531,758,511,790,333,352,926,397
|
||||
496,518,828,896,52,828,805,62,470,121,853,831,346,654,684,196,535,15,251,381
|
||||
231,444,530,616,795,620,78,460,947,748,757,78,706,336,82,317,186,256,216,196
|
||||
520,838,365,445,928,855,418,943,195,689,176,638,151,59,82,495,58,681,737,545
|
||||
172,755,782,71,514,336,383,470,168,70,168,199,307,102,793,250,739,174,368,279
|
||||
897,734,446,184,254,785,499,949,903,405,401,679,356,753,354,351,842,443,207,203
|
||||
60,577,746,229,105,475,640,877,848,477,545,525,793,752,313,315,318,983,537,249
|
||||
474,833,611,169,61,800,759,228,321,833,303,673,513,862,76,122,803,520,67,667
|
||||
504,919,413,521,514,251,785,170,656,759,510,537,579,462,794,756,687,479,864,507
|
||||
949,774,866,805,357,442,183,874,934,195,511,742,756,683,396,407,637,348,866,344
|
||||
687,305,781,780,821,586,945,94,87,230,353,376,849,379,510,368,709,489,113,191
|
||||
275,356,277,655,529,493,541,141,132,804,620,171,382,443,483,978,737,536,532,904
|
||||
357,369,142,383,802,782,722,391,905,684,226,413,379,74,792,618,351,939,580,578
|
||||
368,394,514,461,445,933,677,324,318,250,863,266,855,703,781,142,460,74,753,947
|
||||
935,852,127,241,309,825,481,206,642,81,375,862,330,21,496,60,677,238,532,138
|
||||
258,680,336,136,640,193,372,100,227,856,495,103,92,341,356,703,568,147,311,514
|
||||
412,673,398,244,397,313,378,780,107,905,318,208,172,374,464,690,379,686,538,638
|
||||
660,321,894,681,515,539,486,403,469,91,675,186,386,839,197,639,411,873,69,837
|
||||
845,413,996,87,314,674,362,258,783,412,341,529,519,654,526,757,899,617,909,492
|
||||
127,749,682,785,735,418,112,834,934,381,613,107,748,474,84,72,514,355,942,701
|
||||
541,100,75,155,645,410,612,519,976,656,854,140,61,140,401,827,466,798,385,192
|
||||
332,126,836,373,545,313,379,69,345,751,348,750,746,643,763,519,943,508,679,274
|
||||
642,521,55,479,54,615,323,247,736,80,979,489,97,238,759,579,363,826,91,929
|
||||
227,497,467,249,808,441,906,361,815,523,206,352,383,521,798,84,360,74,680,100
|
||||
96,486,465,382,796,198,500,717,462,617,245,247,649,941,946,750,408,845,637,311
|
||||
379,168,181,100,507,798,928,784,174,128,830,480,113,311,379,474,361,613,909,325
|
||||
130,144,649,305,273,637,112,353,528,786,944,866,931,269,381,271,153,902,552,129
|
||||
520,908,58,249,842,831,756,253,21,238,645,607,902,200,439,100,112,324,374,672
|
||||
614,173,149,316,132,309,484,270,249,104,542,524,350,357,244,331,507,405,793,345
|
||||
943,140,784,620,818,558,780,53,894,673,500,370,109,539,372,376,505,785,909,782
|
||||
900,187,113,464,991,534,368,181,463,841,747,362,945,640,153,227,241,944,833,743
|
||||
863,838,340,366,230,500,643,103,772,127,88,754,611,496,791,444,440,903,75,467
|
||||
649,828,617,466,188,502,315,352,866,758,919,247,835,574,750,409,468,247,359,202
|
||||
371,846,121,755,474,472,176,325,153,97,949,201,65,171,908,500,277,937,90,388
|
||||
929,392,539,469,843,440,947,893,347,312,128,63,754,685,947,227,679,470,945,303
|
||||
731,77,872,620,88,616,104,681,204,312,115,688,386,195,676,506,87,707,519,149
|
||||
278,365,780,785,874,251,114,321,499,898,729,101,637,684,167,797,826,930,615,51
|
||||
319,924,819,856,202,71,102,55,838,81,231,150,656,840,354,679,744,475,344,814
|
||||
926,657,378,507,927,389,680,238,185,319,475,897,132,936,685,540,16,331,508,613
|
||||
681,897,228,303,835,356,523,403,314,709,382,272,370,109,470,479,923,443,896,782
|
||||
677,239,501,233,180,928,351,101,373,151,321,347,445,198,112,679,828,751,680,96
|
||||
840,497,237,318,490,848,248,351,413,850,945,662,460,945,439,929,126,199,330,320
|
||||
647,489,508,105,648,253,270,807,201,110,537,12,336,369,581,609,190,535,676,489
|
||||
534,668,686,442,938,394,798,755,190,412,505,375,101,752,490,405,875,573,417,677
|
||||
231,461,260,138,611,824,333,331,406,351,229,97,756,926,678,849,488,758,230,121
|
||||
82,347,442,172,652,898,687,491,392,539,538,389,257,505,334,325,840,89,918,138
|
||||
517,352,192,701,848,617,804,704,344,785,58,839,351,140,394,242,144,342,179,142
|
||||
166,140,226,442,183,499,166,272,839,795,908,165,901,703,262,91,358,127,872,834
|
||||
788,157,156,675,876,376,473,404,709,752,373,780,324,146,169,819,807,337,514,204
|
||||
190,511,822,204,495,948,123,117,932,509,148,706,66,110,861,674,637,545,486,855
|
||||
119,227,439,442,808,378,929,949,313,142,359,789,503,442,908,310,315,474,395,935
|
||||
367,210,531,480,142,245,833,172,320,137,468,800,827,930,199,318,904,642,516,865
|
||||
538,198,113,62,362,528,787,668,936,657,184,345,895,236,385,829,522,253,758,352
|
||||
315,708,796,639,162,690,688,750,366,171,509,476,708,782,637,368,934,125,73,248
|
||||
617,156,576,737,521,755,932,266,939,203,690,578,853,98,414,50,759,440,819,331
|
||||
593,232,442,468,578,949,383,129,800,152,77,386,935,819,925,470,305,396,308,874
|
||||
102,361,319,187,226,942,493,272,247,68,475,364,398,141,821,900,56,480,814,307
|
||||
650,796,98,92,687,646,128,140,168,813,203,825,851,80,136,473,581,150,865,806
|
||||
263,520,275,378,406,113,59,194,759,128,522,183,498,167,185,702,652,606,133,578
|
||||
707,331,737,748,820,759,257,742,856,500,318,814,507,898,244,153,470,319,532,110
|
||||
488,382,380,145,126,807,359,343,606,82,750,194,607,981,409,151,860,862,339,900
|
||||
873,620,230,924,345,750,62,387,802,113,97,930,63,416,750,76,657,507,260,325
|
||||
111,749,114,785,477,572,248,687,500,64,925,931,132,783,795,491,998,248,754,56
|
||||
115,83,245,512,638,327,108,451,826,757,675,521,342,350,102,462,348,841,874,798
|
||||
941,822,582,948,500,645,393,757,214,362,103,132,181,515,227,828,827,406,375,232
|
||||
647,362,660,738,497,366,803,505,335,105,75,153,313,759,501,241,62,149,748,926
|
||||
123,146,613,390,742,638,907,515,334,686,411,854,933,469,174,126,169,395,842,351
|
||||
830,315,59,573,843,656,523,533,528,403,259,141,523,333,876,355,880,680,134,942
|
||||
234,22,808,145,529,374,142,572,344,409,607,930,858,825,804,223,534,505,466,539
|
||||
684,688,940,524,357,684,844,673,381,794,895,516,308,582,380,487,731,241,797,685
|
||||
196,112,331,528,533,396,489,579,266,496,77,440,650,165,399,469,475,507,364,56
|
||||
354,139,945,330,742,894,782,989,87,231,54,358,51,681,350,652,936,745,134,936
|
||||
804,439,935,234,944,849,186,173,254,690,326,102,149,926,115,792,829,167,508,746
|
||||
388,684,243,814,80,350,637,335,442,146,474,825,477,686,578,331,269,378,472,828
|
||||
826,863,520,70,279,522,801,579,500,237,696,534,242,259,932,540,182,544,72,701
|
||||
886,227,369,89,612,147,488,152,511,646,104,853,352,94,741,223,858,150,383,680
|
||||
792,51,440,64,838,116,195,674,70,902,829,779,682,404,808,860,619,466,807,836
|
||||
652,499,177,830,104,674,377,128,787,123,153,782,230,237,526,478,273,523,92,85
|
||||
418,364,405,327,502,538,539,278,372,508,245,306,325,488,548,674,97,135,944,906
|
||||
409,996,83,929,461,485,829,384,171,844,933,755,780,860,491,331,473,541,874,142
|
||||
390,92,141,310,747,142,653,498,203,829,946,393,142,251,360,22,804,385,240,167
|
||||
874,255,324,340,562,529,366,190,100,480,109,171,947,491,188,154,680,404,275,486
|
||||
945,947,61,110,500,920,875,248,352,56,475,949,876,686,745,443,171,821,348,645
|
||||
705,498,139,798,369,418,666,124,227,578,530,376,607,122,613,87,101,50,930,129
|
||||
475,235,549,581,610,820,206,96,901,802,128,818,413,542,151,362,401,474,76,331
|
||||
506,608,462,708,980,838,582,803,56,503,83,258,384,925,171,874,152,823,170,89
|
||||
517,606,475,644,105,195,846,445,323,619,498,183,310,79,493,155,90,533,259,218
|
||||
63,619,373,850,902,90,153,542,269,330,94,357,797,203,909,201,776,615,606,340
|
||||
501,342,74,394,94,212,401,475,877,72,519,128,148,640,859,68,525,54,358,904
|
||||
875,821,377,781,823,781,398,619,945,130,930,750,802,752,704,439,1,645,337,309
|
||||
533,830,474,829,98,613,896,744,512,126,248,511,113,250,66,515,585,128,877,259
|
||||
201,858,793,791,828,471,859,581,899,76,836,738,259,155,816,360,474,414,277,835
|
||||
5,324,784,71,677,617,745,808,184,56,478,682,578,310,390,330,656,872,305,684
|
||||
508,686,519,385,245,759,766,136,898,128,332,205,276,58,60,252,906,167,737,169
|
||||
799,650,674,67,181,243,155,254,785,208,934,197,835,350,76,865,516,248,837,503
|
||||
361,90,874,251,310,733,155,60,69,276,325,370,330,149,62,397,519,704,823,345
|
||||
186,256,497,252,75,880,516,278,172,381,61,357,358,115,858,202,512,375,836,247
|
||||
465,324,828,443,518,708,781,895,122,334,161,759,517,356,616,399,65,796,127,236
|
||||
792,170,109,461,141,928,758,201,101,114,739,153,108,675,938,512,177,330,580,943
|
||||
92,407,385,278,92,723,333,757,936,373,90,788,388,505,738,609,826,321,153,858
|
||||
350,780,492,311,414,306,702,252,257,782,837,823,137,166,988,648,186,781,613,789
|
||||
83,341,408,537,607,483,948,122,349,757,144,81,945,757,758,474,370,651,947,567
|
||||
110,689,77,706,383,353,395,187,399,402,186,223,816,373,112,530,908,327,531,851
|
||||
492,137,785,209,610,392,791,411,523,198,377,386,225,236,344,837,491,781,393,579
|
||||
233,172,271,138,875,789,512,81,63,406,479,232,122,704,895,946,448,136,684,949
|
||||
351,238,909,505,96,523,192,444,491,259,313,345,100,530,116,257,532,646,103,675
|
||||
642,149,898,346,487,470,896,358,493,674,275,461,503,572,443,787,839,905,499,117
|
||||
306,947,308,523,334,467,127,782,389,835,448,862,895,482,614,278,252,402,641,336
|
||||
232,368,805,944,138,86,143,499,644,60,320,942,89,533,489,71,782,927,327,17
|
||||
141,672,108,175,844,378,843,647,223,372,140,109,705,785,407,843,795,400,182,310
|
||||
253,684,377,93,409,606,688,23,476,51,709,828,860,736,156,75,483,169,441,92
|
||||
519,312,95,899,115,949,818,308,119,611,206,372,643,524,63,757,89,538,783,801
|
||||
577,872,902,510,51,239,278,541,576,235,780,475,758,321,350,575,117,324,83,410
|
||||
932,796,508,832,894,392,314,90,58,13,478,440,942,818,145,271,736,475,181,937
|
||||
113,737,758,182,145,454,332,66,52,488,545,129,500,126,509,703,306,137,534,618
|
||||
928,900,799,575,417,254,903,373,803,803,263,313,365,100,894,250,842,799,929,128
|
||||
69,705,638,72,321,814,610,397,926,902,67,499,122,508,74,744,825,746,183,410
|
||||
926,316,324,483,348,356,544,945,865,538,380,508,76,758,506,380,326,640,118,824
|
||||
832,340,786,225,704,206,508,535,843,347,326,120,620,473,650,247,100,238,309,337
|
||||
677,581,526,334,677,705,266,60,367,485,646,88,252,104,752,509,908,486,684,377
|
||||
55,861,490,521,265,182,339,876,575,242,782,153,673,495,256,534,360,346,233,361
|
||||
446,126,228,876,991,351,271,499,239,831,618,708,935,256,704,904,129,131,227,850
|
||||
219,642,394,413,129,276,843,701,619,349,242,247,608,320,824,864,894,536,701,255
|
||||
544,642,256,128,379,279,307,523,256,75,410,536,357,785,806,790,663,826,642,392
|
||||
311,337,896,352,315,538,786,271,370,54,129,89,946,837,71,519,715,818,76,270
|
||||
871,638,385,795,238,63,645,226,388,337,128,270,679,839,846,516,314,607,616,475
|
||||
94,794,188,392,490,73,144,908,504,139,182,573,844,391,947,333,528,549,782,384
|
||||
758,517,808,637,347,836,105,610,643,852,55,719,581,646,74,362,396,410,141,337
|
||||
949,749,745,848,187,51,350,497,165,543,929,321,245,945,272,121,396,810,198,108
|
||||
407,54,341,519,926,801,73,397,606,524,385,470,413,346,670,80,279,360,901,392
|
||||
794,139,837,745,834,380,701,312,463,705,151,313,682,168,866,1,703,500,476,202
|
||||
544,892,621,354,924,134,736,793,338,872,346,80,823,675,121,97,801,464,508,58
|
||||
370,538,474,641,171,189,342,381,94,145,999,384,383,400,645,866,513,140,618,97
|
||||
230,621,616,240,675,414,933,22,362,828,618,926,486,393,895,88,110,230,528,940
|
||||
483,852,446,339,512,684,582,200,896,862,979,353,319,610,145,374,581,446,750,252
|
||||
157,648,683,439,460,224,357,135,279,69,899,154,75,515,321,349,115,657,156,189
|
||||
414,794,652,930,397,440,655,306,484,512,342,861,344,902,100,860,513,976,66,388
|
||||
405,932,488,444,745,870,528,446,657,188,863,689,475,56,708,476,325,757,336,638
|
||||
456,783,396,84,237,107,443,645,106,652,304,337,110,477,134,899,145,410,709,544
|
||||
334,865,677,708,642,660,343,83,945,855,899,529,704,877,675,199,639,342,337,848
|
||||
490,855,851,784,119,652,489,416,349,538,705,439,736,537,751,312,152,273,307,95
|
||||
696,125,500,754,90,516,681,533,902,226,97,377,57,322,312,191,384,794,109,196
|
||||
195,50,197,253,339,992,502,168,402,107,757,137,247,62,275,855,245,231,645,86
|
||||
638,316,191,524,699,821,898,205,102,98,375,279,376,97,82,582,233,386,347,242
|
||||
177,369,248,754,803,270,927,382,305,532,854,854,614,355,746,356,484,253,388,406
|
||||
844,896,376,832,385,757,755,930,376,509,353,569,255,442,166,312,498,894,394,738
|
||||
362,591,803,532,678,527,517,852,345,440,832,948,403,673,96,228,861,909,840,412
|
||||
484,817,196,102,476,352,232,742,359,367,609,82,207,201,520,521,233,940,384,480
|
||||
906,329,207,67,510,71,98,920,857,384,77,247,571,388,121,387,147,241,894,478
|
||||
390,530,97,924,187,681,120,69,151,226,239,750,945,399,389,613,334,897,463,223
|
||||
345,276,484,617,229,102,580,989,155,683,639,485,545,89,348,800,940,257,137,98
|
||||
68,711,59,69,646,496,410,352,94,519,947,896,465,67,76,830,481,411,95,255
|
||||
704,535,780,309,314,64,63,904,509,93,408,225,189,372,503,139,146,512,4,621
|
||||
277,406,273,709,461,324,923,377,645,747,56,327,820,576,60,502,487,191,754,876
|
||||
364,325,755,509,677,385,235,349,945,480,641,858,142,905,933,214,306,806,97,827
|
||||
4,187,466,402,929,944,125,256,705,199,130,849,741,136,234,944,650,274,682,781
|
||||
318,340,499,237,348,396,682,62,131,574,708,380,278,866,927,85,267,877,830,371
|
||||
776,196,576,749,353,362,934,315,476,538,272,510,396,575,93,574,498,185,741,256
|
||||
50,909,410,647,920,305,655,184,233,361,391,908,258,779,530,708,655,793,92,651
|
||||
677,226,140,709,312,201,443,91,657,899,111,502,464,62,365,374,195,330,670,833
|
||||
555,346,608,401,256,128,318,418,353,56,187,743,231,87,133,909,113,363,319,939
|
||||
204,313,485,190,620,390,820,369,737,323,197,121,488,460,655,812,529,617,185,902
|
||||
749,678,375,242,514,752,325,709,736,532,143,776,269,656,510,486,865,484,305,905
|
||||
942,247,779,305,361,707,817,270,323,833,440,105,242,687,201,875,334,411,132,863
|
||||
484,653,224,511,322,387,229,309,470,64,186,362,202,482,277,660,645,342,320,501
|
||||
608,465,234,143,369,740,363,164,928,805,189,315,154,828,147,346,690,846,621,524
|
||||
825,78,355,520,840,768,58,410,304,581,464,279,572,145,521,534,908,872,755,148
|
||||
71,901,640,395,718,200,860,854,834,908,371,832,277,904,441,378,780,756,927,130
|
||||
489,79,794,258,54,790,792,82,246,80,513,821,97,350,846,144,572,277,695,190
|
||||
139,571,742,381,506,515,679,649,822,853,532,908,23,516,132,474,132,73,857,251
|
||||
61,805,355,524,851,894,691,81,905,924,898,473,652,749,460,948,512,185,414,519
|
||||
505,752,239,508,817,188,345,906,198,525,340,355,688,516,247,517,476,847,542,169
|
||||
649,646,898,462,539,472,396,310,148,832,303,187,362,848,402,646,853,661,477,91
|
||||
612,383,369,231,229,939,351,106,820,313,401,175,654,644,342,334,235,367,675,853
|
||||
794,120,754,469,399,383,613,579,360,87,418,414,390,828,864,606,345,860,309,200
|
||||
746,539,316,14,800,274,641,507,335,410,745,872,947,131,227,656,900,535,802,460
|
||||
945,836,325,610,376,939,616,235,311,408,322,102,743,442,697,141,825,321,534,861
|
||||
252,203,78,611,824,653,348,700,946,508,864,338,98,78,611,319,439,344,791,232
|
||||
508,943,13,933,83,193,149,647,786,385,739,477,707,199,486,746,169,155,466,315
|
||||
472,782,945,275,53,618,340,377,390,545,849,753,375,355,468,704,856,480,157,305
|
||||
338,507,476,303,271,541,135,528,790,53,565,505,249,387,678,747,860,509,466,844
|
||||
140,246,64,309,196,94,834,193,136,97,471,827,251,170,713,757,738,344,460,388
|
||||
847,290,440,313,534,754,481,822,754,740,316,469,538,790,793,864,325,196,575,796
|
||||
645,672,342,193,646,305,781,189,139,979,316,900,749,324,478,525,753,934,256,73
|
||||
613,324,781,581,56,335,524,812,74,142,229,748,873,378,895,529,316,755,147,342
|
||||
95,106,310,303,345,490,736,145,544,614,127,193,93,333,15,56,463,532,861,947
|
||||
366,460,388,806,540,444,96,58,442,577,620,741,685,836,209,785,53,933,787,576
|
||||
522,322,739,572,618,938,686,444,756,254,482,196,333,360,799,101,639,572,768,356
|
||||
127,856,860,943,658,87,115,108,862,619,675,384,581,70,526,789,403,369,938,139
|
||||
475,256,471,91,840,71,183,938,316,255,582,522,840,501,145,677,700,839,866,655
|
||||
744,262,389,538,839,844,194,907,228,181,478,941,418,948,329,418,329,379,643,127
|
||||
237,85,72,150,574,619,678,82,658,71,411,674,273,527,856,791,834,327,87,756
|
||||
390,500,270,354,74,701,567,497,611,779,146,741,328,383,877,309,90,749,279,237
|
||||
379,155,70,508,530,171,906,257,376,535,778,152,439,129,235,80,803,859,743,522
|
||||
527,690,385,491,249,780,618,57,798,365,409,223,924,537,903,498,874,137,720,580
|
||||
536,875,477,246,114,167,55,803,609,525,670,834,244,67,54,704,753,757,127,829
|
||||
653,942,643,938,214,751,80,749,749,513,645,838,866,538,145,60,275,674,673,346
|
||||
914,113,304,639,310,783,851,825,685,309,69,351,875,155,152,238,353,575,78,638
|
||||
822,334,935,793,146,492,861,767,529,753,277,758,843,321,468,491,340,679,83,226
|
||||
444,870,341,653,852,89,651,941,309,258,645,841,606,364,649,873,138,529,259,800
|
||||
898,683,464,783,897,607,99,183,483,395,219,932,706,847,737,128,754,409,259,409
|
||||
608,564,144,86,523,941,226,519,97,925,333,67,383,501,226,581,106,805,481,614
|
||||
171,55,392,79,501,925,189,196,366,269,996,833,531,371,110,785,354,201,759,352
|
||||
374,60,400,272,54,74,353,522,494,785,811,277,69,201,744,399,341,929,940,66
|
||||
190,805,131,494,806,260,753,576,131,531,896,384,607,354,791,194,149,644,904,500
|
||||
68,498,742,747,57,792,9,256,508,942,354,614,110,339,325,851,826,64,64,143
|
||||
443,92,847,250,516,827,247,562,71,794,224,751,498,484,279,202,513,244,641,542
|
||||
379,487,709,324,906,204,613,207,553,904,319,792,805,368,168,617,840,442,488,205
|
||||
249,876,640,471,542,801,744,245,127,206,808,978,823,925,513,873,347,69,931,442
|
||||
818,353,391,512,102,175,402,362,94,247,682,257,493,441,73,397,123,839,575,738
|
||||
135,59,606,183,743,255,528,171,387,513,473,577,66,899,139,65,410,757,371,178
|
||||
100,315,606,894,345,131,199,472,123,931,646,993,493,615,611,154,182,418,106,835
|
||||
227,580,210,650,201,225,374,675,362,366,269,402,127,399,808,409,504,688,205,506
|
||||
83,862,749,940,760,446,483,468,223,103,378,740,379,132,753,131,329,169,197,136
|
106
2020/d16/ex2/ex2.py
Executable file
106
2020/d16/ex2/ex2.py
Executable file
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/env python
|
||||
import math
|
||||
import sys
|
||||
from typing import Dict, List, Set, Tuple
|
||||
|
||||
Ranges = Dict[str, Set[int]]
|
||||
Ticket = List[int]
|
||||
|
||||
|
||||
def parse(raw: List[str]) -> Tuple[Ranges, List[Ticket]]:
|
||||
def extract_field_info(line: str) -> Tuple[str, Set[int]]:
|
||||
field, rest = line.split(":")
|
||||
ranges: Set[int] = set()
|
||||
for r in rest.strip().split(" or "):
|
||||
lhs, rhs = r.split("-")
|
||||
ranges |= set(range(int(lhs), int(rhs) + 1))
|
||||
return field, ranges
|
||||
|
||||
def parse_tickets(line: str) -> Ticket:
|
||||
return [int(i) for i in line.split(",")]
|
||||
|
||||
ranges: Ranges = {}
|
||||
tickets: List[Ticket] = []
|
||||
|
||||
should_parse_tickets = False
|
||||
for line in raw:
|
||||
if line == "":
|
||||
should_parse_tickets = True
|
||||
continue
|
||||
if "ticket" in line:
|
||||
continue
|
||||
if should_parse_tickets:
|
||||
tickets.append(parse_tickets(line))
|
||||
else:
|
||||
field, field_ranges = extract_field_info(line)
|
||||
ranges[field] = field_ranges
|
||||
|
||||
return ranges, tickets
|
||||
|
||||
|
||||
def verify_mapping(possibilites: Dict[int, Set[str]]) -> None:
|
||||
for pos in possibilites.values():
|
||||
assert len(pos) == 1
|
||||
|
||||
|
||||
def cross_eliminate(possibilites: Dict[int, Set[str]]) -> None:
|
||||
while True:
|
||||
eliminated = False
|
||||
for pos in possibilites:
|
||||
if len(possibilites[pos]) != 1:
|
||||
continue
|
||||
for other_pos in possibilites:
|
||||
if other_pos == pos:
|
||||
continue
|
||||
if len(possibilites[other_pos] & possibilites[pos]) == 0:
|
||||
continue
|
||||
eliminated = True
|
||||
possibilites[other_pos] = possibilites[other_pos] - (possibilites[pos])
|
||||
if not eliminated:
|
||||
break
|
||||
|
||||
|
||||
def match_ranges(ranges: Ranges, tickets: List[Ticket]) -> Dict[int, str]:
|
||||
possibilites: Dict[int, Set[str]] = {
|
||||
i: set(ranges.keys()) for i in range(len(ranges))
|
||||
}
|
||||
|
||||
def whittle_down() -> None:
|
||||
for t in tickets[1:]:
|
||||
for i, val in enumerate(t):
|
||||
for field, valid in ranges.items():
|
||||
if val in valid:
|
||||
continue
|
||||
possibilites[i].remove(field)
|
||||
|
||||
whittle_down()
|
||||
cross_eliminate(possibilites)
|
||||
verify_mapping(possibilites)
|
||||
|
||||
return {i: pos.pop() for i, pos in possibilites.items()}
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
ranges, tickets = parse(raw)
|
||||
|
||||
def valid(t: Ticket) -> bool:
|
||||
for val in t:
|
||||
if not any(val in r for r in ranges.values()):
|
||||
return False
|
||||
return True
|
||||
|
||||
tickets = [t for i, t in enumerate(tickets) if i == 0 or valid(t)]
|
||||
|
||||
mapping = match_ranges(ranges, tickets)
|
||||
return math.prod(
|
||||
tickets[0][i] for i, field in mapping.items() if "departure" in field
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
264
2020/d16/ex2/input
Normal file
264
2020/d16/ex2/input
Normal file
|
@ -0,0 +1,264 @@
|
|||
departure location: 44-709 or 728-964
|
||||
departure station: 42-259 or 269-974
|
||||
departure platform: 39-690 or 701-954
|
||||
departure track: 49-909 or 924-965
|
||||
departure date: 48-759 or 779-957
|
||||
departure time: 38-115 or 121-965
|
||||
arrival location: 32-808 or 818-949
|
||||
arrival station: 45-418 or 439-949
|
||||
arrival platform: 35-877 or 894-962
|
||||
arrival track: 26-866 or 872-958
|
||||
class: 32-727 or 736-969
|
||||
duration: 35-446 or 460-968
|
||||
price: 26-545 or 571-961
|
||||
route: 35-207 or 223-960
|
||||
row: 43-156 or 165-955
|
||||
seat: 26-172 or 181-966
|
||||
train: 49-582 or 606-952
|
||||
type: 36-279 or 303-968
|
||||
wagon: 26-657 or 672-959
|
||||
zone: 36-621 or 637-963
|
||||
|
||||
your ticket:
|
||||
83,127,131,137,113,73,139,101,67,53,107,103,59,149,109,61,79,71,97,89
|
||||
|
||||
nearby tickets:
|
||||
539,619,928,309,835,99,521,478,54,340,849,859,376,357,524,841,221,935,806,147
|
||||
231,827,907,526,238,542,181,853,303,143,116,701,206,140,927,203,443,753,151,258
|
||||
445,679,816,617,82,102,197,100,239,490,488,78,707,349,689,335,847,183,144,314
|
||||
476,833,232,489,937,256,87,409,223,364,978,939,398,331,153,945,513,237,934,272
|
||||
492,927,578,788,808,529,739,20,201,688,405,877,228,168,361,521,400,398,618,520
|
||||
332,694,481,571,523,516,395,122,844,358,232,132,315,486,899,154,269,201,831,50
|
||||
907,706,927,126,133,97,217,334,745,751,580,862,526,845,680,125,96,445,863,322
|
||||
498,753,844,670,150,657,853,150,377,487,152,369,500,241,360,204,142,236,948,91
|
||||
578,675,491,230,332,464,258,858,508,330,492,780,494,234,839,645,160,795,896,687
|
||||
814,875,617,185,490,490,501,940,224,751,609,844,442,525,640,609,336,251,532,685
|
||||
684,196,757,841,580,576,18,319,150,249,676,337,155,115,652,638,475,398,789,379
|
||||
445,490,199,140,88,694,184,247,307,386,198,85,905,860,484,244,532,224,681,251
|
||||
172,936,701,440,779,941,639,351,238,70,787,91,259,340,58,541,815,399,238,202
|
||||
715,369,504,226,138,866,783,231,580,147,82,335,533,144,530,462,836,751,473,801
|
||||
932,459,242,947,653,150,618,683,198,608,88,342,948,497,675,53,681,544,315,615
|
||||
422,244,791,929,799,128,374,473,148,931,381,822,318,853,147,367,531,412,242,470
|
||||
464,899,490,846,381,326,271,948,396,318,653,981,310,822,502,895,78,935,78,461
|
||||
231,339,79,530,680,461,863,521,839,517,379,108,395,613,644,751,823,212,206,151
|
||||
526,507,403,354,931,859,787,728,247,781,643,203,847,326,506,79,65,332,91,783
|
||||
571,182,753,841,338,746,254,307,896,648,726,89,314,706,943,464,444,481,465,928
|
||||
184,513,335,941,303,198,537,571,409,337,497,621,350,617,98,897,850,679,794,260
|
||||
235,255,393,310,188,65,943,543,94,374,500,482,122,992,656,523,704,742,331,792
|
||||
315,152,320,983,493,166,754,376,619,480,149,929,330,80,529,131,150,57,251,842
|
||||
54,77,540,141,61,205,273,214,745,145,166,131,93,525,500,521,223,52,237,404
|
||||
300,616,784,250,852,354,327,944,675,859,673,941,789,829,234,104,842,85,742,98
|
||||
110,244,95,93,529,162,82,309,142,680,65,410,531,758,511,790,333,352,926,397
|
||||
496,518,828,896,52,828,805,62,470,121,853,831,346,654,684,196,535,15,251,381
|
||||
231,444,530,616,795,620,78,460,947,748,757,78,706,336,82,317,186,256,216,196
|
||||
520,838,365,445,928,855,418,943,195,689,176,638,151,59,82,495,58,681,737,545
|
||||
172,755,782,71,514,336,383,470,168,70,168,199,307,102,793,250,739,174,368,279
|
||||
897,734,446,184,254,785,499,949,903,405,401,679,356,753,354,351,842,443,207,203
|
||||
60,577,746,229,105,475,640,877,848,477,545,525,793,752,313,315,318,983,537,249
|
||||
474,833,611,169,61,800,759,228,321,833,303,673,513,862,76,122,803,520,67,667
|
||||
504,919,413,521,514,251,785,170,656,759,510,537,579,462,794,756,687,479,864,507
|
||||
949,774,866,805,357,442,183,874,934,195,511,742,756,683,396,407,637,348,866,344
|
||||
687,305,781,780,821,586,945,94,87,230,353,376,849,379,510,368,709,489,113,191
|
||||
275,356,277,655,529,493,541,141,132,804,620,171,382,443,483,978,737,536,532,904
|
||||
357,369,142,383,802,782,722,391,905,684,226,413,379,74,792,618,351,939,580,578
|
||||
368,394,514,461,445,933,677,324,318,250,863,266,855,703,781,142,460,74,753,947
|
||||
935,852,127,241,309,825,481,206,642,81,375,862,330,21,496,60,677,238,532,138
|
||||
258,680,336,136,640,193,372,100,227,856,495,103,92,341,356,703,568,147,311,514
|
||||
412,673,398,244,397,313,378,780,107,905,318,208,172,374,464,690,379,686,538,638
|
||||
660,321,894,681,515,539,486,403,469,91,675,186,386,839,197,639,411,873,69,837
|
||||
845,413,996,87,314,674,362,258,783,412,341,529,519,654,526,757,899,617,909,492
|
||||
127,749,682,785,735,418,112,834,934,381,613,107,748,474,84,72,514,355,942,701
|
||||
541,100,75,155,645,410,612,519,976,656,854,140,61,140,401,827,466,798,385,192
|
||||
332,126,836,373,545,313,379,69,345,751,348,750,746,643,763,519,943,508,679,274
|
||||
642,521,55,479,54,615,323,247,736,80,979,489,97,238,759,579,363,826,91,929
|
||||
227,497,467,249,808,441,906,361,815,523,206,352,383,521,798,84,360,74,680,100
|
||||
96,486,465,382,796,198,500,717,462,617,245,247,649,941,946,750,408,845,637,311
|
||||
379,168,181,100,507,798,928,784,174,128,830,480,113,311,379,474,361,613,909,325
|
||||
130,144,649,305,273,637,112,353,528,786,944,866,931,269,381,271,153,902,552,129
|
||||
520,908,58,249,842,831,756,253,21,238,645,607,902,200,439,100,112,324,374,672
|
||||
614,173,149,316,132,309,484,270,249,104,542,524,350,357,244,331,507,405,793,345
|
||||
943,140,784,620,818,558,780,53,894,673,500,370,109,539,372,376,505,785,909,782
|
||||
900,187,113,464,991,534,368,181,463,841,747,362,945,640,153,227,241,944,833,743
|
||||
863,838,340,366,230,500,643,103,772,127,88,754,611,496,791,444,440,903,75,467
|
||||
649,828,617,466,188,502,315,352,866,758,919,247,835,574,750,409,468,247,359,202
|
||||
371,846,121,755,474,472,176,325,153,97,949,201,65,171,908,500,277,937,90,388
|
||||
929,392,539,469,843,440,947,893,347,312,128,63,754,685,947,227,679,470,945,303
|
||||
731,77,872,620,88,616,104,681,204,312,115,688,386,195,676,506,87,707,519,149
|
||||
278,365,780,785,874,251,114,321,499,898,729,101,637,684,167,797,826,930,615,51
|
||||
319,924,819,856,202,71,102,55,838,81,231,150,656,840,354,679,744,475,344,814
|
||||
926,657,378,507,927,389,680,238,185,319,475,897,132,936,685,540,16,331,508,613
|
||||
681,897,228,303,835,356,523,403,314,709,382,272,370,109,470,479,923,443,896,782
|
||||
677,239,501,233,180,928,351,101,373,151,321,347,445,198,112,679,828,751,680,96
|
||||
840,497,237,318,490,848,248,351,413,850,945,662,460,945,439,929,126,199,330,320
|
||||
647,489,508,105,648,253,270,807,201,110,537,12,336,369,581,609,190,535,676,489
|
||||
534,668,686,442,938,394,798,755,190,412,505,375,101,752,490,405,875,573,417,677
|
||||
231,461,260,138,611,824,333,331,406,351,229,97,756,926,678,849,488,758,230,121
|
||||
82,347,442,172,652,898,687,491,392,539,538,389,257,505,334,325,840,89,918,138
|
||||
517,352,192,701,848,617,804,704,344,785,58,839,351,140,394,242,144,342,179,142
|
||||
166,140,226,442,183,499,166,272,839,795,908,165,901,703,262,91,358,127,872,834
|
||||
788,157,156,675,876,376,473,404,709,752,373,780,324,146,169,819,807,337,514,204
|
||||
190,511,822,204,495,948,123,117,932,509,148,706,66,110,861,674,637,545,486,855
|
||||
119,227,439,442,808,378,929,949,313,142,359,789,503,442,908,310,315,474,395,935
|
||||
367,210,531,480,142,245,833,172,320,137,468,800,827,930,199,318,904,642,516,865
|
||||
538,198,113,62,362,528,787,668,936,657,184,345,895,236,385,829,522,253,758,352
|
||||
315,708,796,639,162,690,688,750,366,171,509,476,708,782,637,368,934,125,73,248
|
||||
617,156,576,737,521,755,932,266,939,203,690,578,853,98,414,50,759,440,819,331
|
||||
593,232,442,468,578,949,383,129,800,152,77,386,935,819,925,470,305,396,308,874
|
||||
102,361,319,187,226,942,493,272,247,68,475,364,398,141,821,900,56,480,814,307
|
||||
650,796,98,92,687,646,128,140,168,813,203,825,851,80,136,473,581,150,865,806
|
||||
263,520,275,378,406,113,59,194,759,128,522,183,498,167,185,702,652,606,133,578
|
||||
707,331,737,748,820,759,257,742,856,500,318,814,507,898,244,153,470,319,532,110
|
||||
488,382,380,145,126,807,359,343,606,82,750,194,607,981,409,151,860,862,339,900
|
||||
873,620,230,924,345,750,62,387,802,113,97,930,63,416,750,76,657,507,260,325
|
||||
111,749,114,785,477,572,248,687,500,64,925,931,132,783,795,491,998,248,754,56
|
||||
115,83,245,512,638,327,108,451,826,757,675,521,342,350,102,462,348,841,874,798
|
||||
941,822,582,948,500,645,393,757,214,362,103,132,181,515,227,828,827,406,375,232
|
||||
647,362,660,738,497,366,803,505,335,105,75,153,313,759,501,241,62,149,748,926
|
||||
123,146,613,390,742,638,907,515,334,686,411,854,933,469,174,126,169,395,842,351
|
||||
830,315,59,573,843,656,523,533,528,403,259,141,523,333,876,355,880,680,134,942
|
||||
234,22,808,145,529,374,142,572,344,409,607,930,858,825,804,223,534,505,466,539
|
||||
684,688,940,524,357,684,844,673,381,794,895,516,308,582,380,487,731,241,797,685
|
||||
196,112,331,528,533,396,489,579,266,496,77,440,650,165,399,469,475,507,364,56
|
||||
354,139,945,330,742,894,782,989,87,231,54,358,51,681,350,652,936,745,134,936
|
||||
804,439,935,234,944,849,186,173,254,690,326,102,149,926,115,792,829,167,508,746
|
||||
388,684,243,814,80,350,637,335,442,146,474,825,477,686,578,331,269,378,472,828
|
||||
826,863,520,70,279,522,801,579,500,237,696,534,242,259,932,540,182,544,72,701
|
||||
886,227,369,89,612,147,488,152,511,646,104,853,352,94,741,223,858,150,383,680
|
||||
792,51,440,64,838,116,195,674,70,902,829,779,682,404,808,860,619,466,807,836
|
||||
652,499,177,830,104,674,377,128,787,123,153,782,230,237,526,478,273,523,92,85
|
||||
418,364,405,327,502,538,539,278,372,508,245,306,325,488,548,674,97,135,944,906
|
||||
409,996,83,929,461,485,829,384,171,844,933,755,780,860,491,331,473,541,874,142
|
||||
390,92,141,310,747,142,653,498,203,829,946,393,142,251,360,22,804,385,240,167
|
||||
874,255,324,340,562,529,366,190,100,480,109,171,947,491,188,154,680,404,275,486
|
||||
945,947,61,110,500,920,875,248,352,56,475,949,876,686,745,443,171,821,348,645
|
||||
705,498,139,798,369,418,666,124,227,578,530,376,607,122,613,87,101,50,930,129
|
||||
475,235,549,581,610,820,206,96,901,802,128,818,413,542,151,362,401,474,76,331
|
||||
506,608,462,708,980,838,582,803,56,503,83,258,384,925,171,874,152,823,170,89
|
||||
517,606,475,644,105,195,846,445,323,619,498,183,310,79,493,155,90,533,259,218
|
||||
63,619,373,850,902,90,153,542,269,330,94,357,797,203,909,201,776,615,606,340
|
||||
501,342,74,394,94,212,401,475,877,72,519,128,148,640,859,68,525,54,358,904
|
||||
875,821,377,781,823,781,398,619,945,130,930,750,802,752,704,439,1,645,337,309
|
||||
533,830,474,829,98,613,896,744,512,126,248,511,113,250,66,515,585,128,877,259
|
||||
201,858,793,791,828,471,859,581,899,76,836,738,259,155,816,360,474,414,277,835
|
||||
5,324,784,71,677,617,745,808,184,56,478,682,578,310,390,330,656,872,305,684
|
||||
508,686,519,385,245,759,766,136,898,128,332,205,276,58,60,252,906,167,737,169
|
||||
799,650,674,67,181,243,155,254,785,208,934,197,835,350,76,865,516,248,837,503
|
||||
361,90,874,251,310,733,155,60,69,276,325,370,330,149,62,397,519,704,823,345
|
||||
186,256,497,252,75,880,516,278,172,381,61,357,358,115,858,202,512,375,836,247
|
||||
465,324,828,443,518,708,781,895,122,334,161,759,517,356,616,399,65,796,127,236
|
||||
792,170,109,461,141,928,758,201,101,114,739,153,108,675,938,512,177,330,580,943
|
||||
92,407,385,278,92,723,333,757,936,373,90,788,388,505,738,609,826,321,153,858
|
||||
350,780,492,311,414,306,702,252,257,782,837,823,137,166,988,648,186,781,613,789
|
||||
83,341,408,537,607,483,948,122,349,757,144,81,945,757,758,474,370,651,947,567
|
||||
110,689,77,706,383,353,395,187,399,402,186,223,816,373,112,530,908,327,531,851
|
||||
492,137,785,209,610,392,791,411,523,198,377,386,225,236,344,837,491,781,393,579
|
||||
233,172,271,138,875,789,512,81,63,406,479,232,122,704,895,946,448,136,684,949
|
||||
351,238,909,505,96,523,192,444,491,259,313,345,100,530,116,257,532,646,103,675
|
||||
642,149,898,346,487,470,896,358,493,674,275,461,503,572,443,787,839,905,499,117
|
||||
306,947,308,523,334,467,127,782,389,835,448,862,895,482,614,278,252,402,641,336
|
||||
232,368,805,944,138,86,143,499,644,60,320,942,89,533,489,71,782,927,327,17
|
||||
141,672,108,175,844,378,843,647,223,372,140,109,705,785,407,843,795,400,182,310
|
||||
253,684,377,93,409,606,688,23,476,51,709,828,860,736,156,75,483,169,441,92
|
||||
519,312,95,899,115,949,818,308,119,611,206,372,643,524,63,757,89,538,783,801
|
||||
577,872,902,510,51,239,278,541,576,235,780,475,758,321,350,575,117,324,83,410
|
||||
932,796,508,832,894,392,314,90,58,13,478,440,942,818,145,271,736,475,181,937
|
||||
113,737,758,182,145,454,332,66,52,488,545,129,500,126,509,703,306,137,534,618
|
||||
928,900,799,575,417,254,903,373,803,803,263,313,365,100,894,250,842,799,929,128
|
||||
69,705,638,72,321,814,610,397,926,902,67,499,122,508,74,744,825,746,183,410
|
||||
926,316,324,483,348,356,544,945,865,538,380,508,76,758,506,380,326,640,118,824
|
||||
832,340,786,225,704,206,508,535,843,347,326,120,620,473,650,247,100,238,309,337
|
||||
677,581,526,334,677,705,266,60,367,485,646,88,252,104,752,509,908,486,684,377
|
||||
55,861,490,521,265,182,339,876,575,242,782,153,673,495,256,534,360,346,233,361
|
||||
446,126,228,876,991,351,271,499,239,831,618,708,935,256,704,904,129,131,227,850
|
||||
219,642,394,413,129,276,843,701,619,349,242,247,608,320,824,864,894,536,701,255
|
||||
544,642,256,128,379,279,307,523,256,75,410,536,357,785,806,790,663,826,642,392
|
||||
311,337,896,352,315,538,786,271,370,54,129,89,946,837,71,519,715,818,76,270
|
||||
871,638,385,795,238,63,645,226,388,337,128,270,679,839,846,516,314,607,616,475
|
||||
94,794,188,392,490,73,144,908,504,139,182,573,844,391,947,333,528,549,782,384
|
||||
758,517,808,637,347,836,105,610,643,852,55,719,581,646,74,362,396,410,141,337
|
||||
949,749,745,848,187,51,350,497,165,543,929,321,245,945,272,121,396,810,198,108
|
||||
407,54,341,519,926,801,73,397,606,524,385,470,413,346,670,80,279,360,901,392
|
||||
794,139,837,745,834,380,701,312,463,705,151,313,682,168,866,1,703,500,476,202
|
||||
544,892,621,354,924,134,736,793,338,872,346,80,823,675,121,97,801,464,508,58
|
||||
370,538,474,641,171,189,342,381,94,145,999,384,383,400,645,866,513,140,618,97
|
||||
230,621,616,240,675,414,933,22,362,828,618,926,486,393,895,88,110,230,528,940
|
||||
483,852,446,339,512,684,582,200,896,862,979,353,319,610,145,374,581,446,750,252
|
||||
157,648,683,439,460,224,357,135,279,69,899,154,75,515,321,349,115,657,156,189
|
||||
414,794,652,930,397,440,655,306,484,512,342,861,344,902,100,860,513,976,66,388
|
||||
405,932,488,444,745,870,528,446,657,188,863,689,475,56,708,476,325,757,336,638
|
||||
456,783,396,84,237,107,443,645,106,652,304,337,110,477,134,899,145,410,709,544
|
||||
334,865,677,708,642,660,343,83,945,855,899,529,704,877,675,199,639,342,337,848
|
||||
490,855,851,784,119,652,489,416,349,538,705,439,736,537,751,312,152,273,307,95
|
||||
696,125,500,754,90,516,681,533,902,226,97,377,57,322,312,191,384,794,109,196
|
||||
195,50,197,253,339,992,502,168,402,107,757,137,247,62,275,855,245,231,645,86
|
||||
638,316,191,524,699,821,898,205,102,98,375,279,376,97,82,582,233,386,347,242
|
||||
177,369,248,754,803,270,927,382,305,532,854,854,614,355,746,356,484,253,388,406
|
||||
844,896,376,832,385,757,755,930,376,509,353,569,255,442,166,312,498,894,394,738
|
||||
362,591,803,532,678,527,517,852,345,440,832,948,403,673,96,228,861,909,840,412
|
||||
484,817,196,102,476,352,232,742,359,367,609,82,207,201,520,521,233,940,384,480
|
||||
906,329,207,67,510,71,98,920,857,384,77,247,571,388,121,387,147,241,894,478
|
||||
390,530,97,924,187,681,120,69,151,226,239,750,945,399,389,613,334,897,463,223
|
||||
345,276,484,617,229,102,580,989,155,683,639,485,545,89,348,800,940,257,137,98
|
||||
68,711,59,69,646,496,410,352,94,519,947,896,465,67,76,830,481,411,95,255
|
||||
704,535,780,309,314,64,63,904,509,93,408,225,189,372,503,139,146,512,4,621
|
||||
277,406,273,709,461,324,923,377,645,747,56,327,820,576,60,502,487,191,754,876
|
||||
364,325,755,509,677,385,235,349,945,480,641,858,142,905,933,214,306,806,97,827
|
||||
4,187,466,402,929,944,125,256,705,199,130,849,741,136,234,944,650,274,682,781
|
||||
318,340,499,237,348,396,682,62,131,574,708,380,278,866,927,85,267,877,830,371
|
||||
776,196,576,749,353,362,934,315,476,538,272,510,396,575,93,574,498,185,741,256
|
||||
50,909,410,647,920,305,655,184,233,361,391,908,258,779,530,708,655,793,92,651
|
||||
677,226,140,709,312,201,443,91,657,899,111,502,464,62,365,374,195,330,670,833
|
||||
555,346,608,401,256,128,318,418,353,56,187,743,231,87,133,909,113,363,319,939
|
||||
204,313,485,190,620,390,820,369,737,323,197,121,488,460,655,812,529,617,185,902
|
||||
749,678,375,242,514,752,325,709,736,532,143,776,269,656,510,486,865,484,305,905
|
||||
942,247,779,305,361,707,817,270,323,833,440,105,242,687,201,875,334,411,132,863
|
||||
484,653,224,511,322,387,229,309,470,64,186,362,202,482,277,660,645,342,320,501
|
||||
608,465,234,143,369,740,363,164,928,805,189,315,154,828,147,346,690,846,621,524
|
||||
825,78,355,520,840,768,58,410,304,581,464,279,572,145,521,534,908,872,755,148
|
||||
71,901,640,395,718,200,860,854,834,908,371,832,277,904,441,378,780,756,927,130
|
||||
489,79,794,258,54,790,792,82,246,80,513,821,97,350,846,144,572,277,695,190
|
||||
139,571,742,381,506,515,679,649,822,853,532,908,23,516,132,474,132,73,857,251
|
||||
61,805,355,524,851,894,691,81,905,924,898,473,652,749,460,948,512,185,414,519
|
||||
505,752,239,508,817,188,345,906,198,525,340,355,688,516,247,517,476,847,542,169
|
||||
649,646,898,462,539,472,396,310,148,832,303,187,362,848,402,646,853,661,477,91
|
||||
612,383,369,231,229,939,351,106,820,313,401,175,654,644,342,334,235,367,675,853
|
||||
794,120,754,469,399,383,613,579,360,87,418,414,390,828,864,606,345,860,309,200
|
||||
746,539,316,14,800,274,641,507,335,410,745,872,947,131,227,656,900,535,802,460
|
||||
945,836,325,610,376,939,616,235,311,408,322,102,743,442,697,141,825,321,534,861
|
||||
252,203,78,611,824,653,348,700,946,508,864,338,98,78,611,319,439,344,791,232
|
||||
508,943,13,933,83,193,149,647,786,385,739,477,707,199,486,746,169,155,466,315
|
||||
472,782,945,275,53,618,340,377,390,545,849,753,375,355,468,704,856,480,157,305
|
||||
338,507,476,303,271,541,135,528,790,53,565,505,249,387,678,747,860,509,466,844
|
||||
140,246,64,309,196,94,834,193,136,97,471,827,251,170,713,757,738,344,460,388
|
||||
847,290,440,313,534,754,481,822,754,740,316,469,538,790,793,864,325,196,575,796
|
||||
645,672,342,193,646,305,781,189,139,979,316,900,749,324,478,525,753,934,256,73
|
||||
613,324,781,581,56,335,524,812,74,142,229,748,873,378,895,529,316,755,147,342
|
||||
95,106,310,303,345,490,736,145,544,614,127,193,93,333,15,56,463,532,861,947
|
||||
366,460,388,806,540,444,96,58,442,577,620,741,685,836,209,785,53,933,787,576
|
||||
522,322,739,572,618,938,686,444,756,254,482,196,333,360,799,101,639,572,768,356
|
||||
127,856,860,943,658,87,115,108,862,619,675,384,581,70,526,789,403,369,938,139
|
||||
475,256,471,91,840,71,183,938,316,255,582,522,840,501,145,677,700,839,866,655
|
||||
744,262,389,538,839,844,194,907,228,181,478,941,418,948,329,418,329,379,643,127
|
||||
237,85,72,150,574,619,678,82,658,71,411,674,273,527,856,791,834,327,87,756
|
||||
390,500,270,354,74,701,567,497,611,779,146,741,328,383,877,309,90,749,279,237
|
||||
379,155,70,508,530,171,906,257,376,535,778,152,439,129,235,80,803,859,743,522
|
||||
527,690,385,491,249,780,618,57,798,365,409,223,924,537,903,498,874,137,720,580
|
||||
536,875,477,246,114,167,55,803,609,525,670,834,244,67,54,704,753,757,127,829
|
||||
653,942,643,938,214,751,80,749,749,513,645,838,866,538,145,60,275,674,673,346
|
||||
914,113,304,639,310,783,851,825,685,309,69,351,875,155,152,238,353,575,78,638
|
||||
822,334,935,793,146,492,861,767,529,753,277,758,843,321,468,491,340,679,83,226
|
||||
444,870,341,653,852,89,651,941,309,258,645,841,606,364,649,873,138,529,259,800
|
||||
898,683,464,783,897,607,99,183,483,395,219,932,706,847,737,128,754,409,259,409
|
||||
608,564,144,86,523,941,226,519,97,925,333,67,383,501,226,581,106,805,481,614
|
||||
171,55,392,79,501,925,189,196,366,269,996,833,531,371,110,785,354,201,759,352
|
||||
374,60,400,272,54,74,353,522,494,785,811,277,69,201,744,399,341,929,940,66
|
||||
190,805,131,494,806,260,753,576,131,531,896,384,607,354,791,194,149,644,904,500
|
||||
68,498,742,747,57,792,9,256,508,942,354,614,110,339,325,851,826,64,64,143
|
||||
443,92,847,250,516,827,247,562,71,794,224,751,498,484,279,202,513,244,641,542
|
||||
379,487,709,324,906,204,613,207,553,904,319,792,805,368,168,617,840,442,488,205
|
||||
249,876,640,471,542,801,744,245,127,206,808,978,823,925,513,873,347,69,931,442
|
||||
818,353,391,512,102,175,402,362,94,247,682,257,493,441,73,397,123,839,575,738
|
||||
135,59,606,183,743,255,528,171,387,513,473,577,66,899,139,65,410,757,371,178
|
||||
100,315,606,894,345,131,199,472,123,931,646,993,493,615,611,154,182,418,106,835
|
||||
227,580,210,650,201,225,374,675,362,366,269,402,127,399,808,409,504,688,205,506
|
||||
83,862,749,940,760,446,483,468,223,103,378,740,379,132,753,131,329,169,197,136
|
66
2020/d17/ex1/ex1.py
Executable file
66
2020/d17/ex1/ex1.py
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from typing import Iterator, Set, Tuple
|
||||
|
||||
Point = Tuple[int, int, int]
|
||||
Grid = Set[Point]
|
||||
|
||||
|
||||
def update(grid: Grid) -> Grid:
|
||||
def neightbours(p: Point) -> Iterator[Point]:
|
||||
for dx, dy, dz in itertools.product(range(-1, 2), repeat=3):
|
||||
if dx == 0 and dy == 0 and dz == 0:
|
||||
continue
|
||||
yield p[0] + dx, p[1] + dy, p[2] + dz
|
||||
|
||||
def count_neighbours(p: Point) -> int:
|
||||
return sum(n in grid for n in neightbours(p))
|
||||
|
||||
new_grid: Grid = set()
|
||||
seen: Set[Point] = set()
|
||||
for p in grid:
|
||||
for n in itertools.chain(neightbours(p), [p]):
|
||||
if n in seen:
|
||||
continue
|
||||
seen |= {n}
|
||||
active = n in grid
|
||||
num_neighbours = count_neighbours(n)
|
||||
|
||||
if active and num_neighbours in [2, 3]:
|
||||
new_grid |= {n}
|
||||
elif active:
|
||||
continue
|
||||
elif num_neighbours == 3:
|
||||
new_grid |= {n}
|
||||
else:
|
||||
continue
|
||||
|
||||
return new_grid
|
||||
|
||||
|
||||
def solve(grid: Grid) -> int:
|
||||
|
||||
for __ in range(6):
|
||||
grid = update(grid)
|
||||
|
||||
return len(grid)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(
|
||||
solve(
|
||||
{
|
||||
(i, j, 0)
|
||||
for i, line in enumerate(input)
|
||||
for j, x in enumerate(line)
|
||||
if x == "#"
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
8
2020/d17/ex1/input
Normal file
8
2020/d17/ex1/input
Normal file
|
@ -0,0 +1,8 @@
|
|||
######.#
|
||||
#.###.#.
|
||||
###.....
|
||||
#.####..
|
||||
##.#.###
|
||||
.######.
|
||||
###.####
|
||||
######.#
|
66
2020/d17/ex2/ex2.py
Executable file
66
2020/d17/ex2/ex2.py
Executable file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from typing import Iterator, Set, Tuple
|
||||
|
||||
Point = Tuple[int, int, int, int]
|
||||
Grid = Set[Point]
|
||||
|
||||
|
||||
def update(grid: Grid) -> Grid:
|
||||
def neightbours(p: Point) -> Iterator[Point]:
|
||||
for dx, dy, dz, dw in itertools.product(range(-1, 2), repeat=4):
|
||||
if dx == 0 and dy == 0 and dz == 0 and dw == 0:
|
||||
continue
|
||||
yield p[0] + dx, p[1] + dy, p[2] + dz, p[3] + dw
|
||||
|
||||
def count_neighbours(p: Point) -> int:
|
||||
return sum(n in grid for n in neightbours(p))
|
||||
|
||||
new_grid: Grid = set()
|
||||
seen: Set[Point] = set()
|
||||
for p in grid:
|
||||
for n in itertools.chain(neightbours(p), [p]):
|
||||
if n in seen:
|
||||
continue
|
||||
seen |= {n}
|
||||
active = n in grid
|
||||
num_neighbours = count_neighbours(n)
|
||||
|
||||
if active and num_neighbours in [2, 3]:
|
||||
new_grid |= {n}
|
||||
elif active:
|
||||
continue
|
||||
elif num_neighbours == 3:
|
||||
new_grid |= {n}
|
||||
else:
|
||||
continue
|
||||
|
||||
return new_grid
|
||||
|
||||
|
||||
def solve(grid: Grid) -> int:
|
||||
|
||||
for __ in range(6):
|
||||
grid = update(grid)
|
||||
|
||||
return len(grid)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(
|
||||
solve(
|
||||
{
|
||||
(i, j, 0, 0)
|
||||
for i, line in enumerate(input)
|
||||
for j, x in enumerate(line)
|
||||
if x == "#"
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
8
2020/d17/ex2/input
Normal file
8
2020/d17/ex2/input
Normal file
|
@ -0,0 +1,8 @@
|
|||
######.#
|
||||
#.###.#.
|
||||
###.....
|
||||
#.####..
|
||||
##.#.###
|
||||
.######.
|
||||
###.####
|
||||
######.#
|
72
2020/d18/ex1/ex1.py
Executable file
72
2020/d18/ex1/ex1.py
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import Callable, Dict, List
|
||||
|
||||
"""
|
||||
E : G [ (+|*) G ]*
|
||||
|
||||
G : '(' E ')' | CONSTANT
|
||||
"""
|
||||
|
||||
|
||||
def parse_g(expr: List[str]) -> int:
|
||||
top = expr.pop(0)
|
||||
if top == "(":
|
||||
ans = parse_e(expr)
|
||||
assert expr.pop(0) == ")"
|
||||
return ans
|
||||
return int(top)
|
||||
|
||||
|
||||
def parse_e(expr: List[str]) -> int:
|
||||
ops: Dict[str, Callable[[int, int], int]] = {
|
||||
"*": lambda lhs, rhs: lhs * rhs,
|
||||
"+": lambda lhs, rhs: lhs + rhs,
|
||||
}
|
||||
lhs = parse_g(expr)
|
||||
while len(expr) and expr[0] in ["+", "*"]:
|
||||
op = expr.pop(0)
|
||||
rhs = parse_g(expr)
|
||||
lhs = ops[op](lhs, rhs)
|
||||
return lhs
|
||||
|
||||
|
||||
def parse_infix(input: List[str]) -> int:
|
||||
"""
|
||||
Parses the given string in infix notation.
|
||||
"""
|
||||
ans = parse_e(input)
|
||||
assert len(input) == 0
|
||||
return ans
|
||||
|
||||
|
||||
def tokenize(expr: str) -> List[str]:
|
||||
res = []
|
||||
|
||||
def split_tok(tok: str) -> None:
|
||||
if "(" not in tok and ")" not in tok:
|
||||
res.append(tok)
|
||||
if "(" in tok:
|
||||
res.append("(")
|
||||
split_tok(tok[1:])
|
||||
if ")" in tok:
|
||||
split_tok(tok[:-1])
|
||||
res.append(")")
|
||||
|
||||
for tok in expr.split():
|
||||
split_tok(tok)
|
||||
return res
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return sum(parse_infix(tokenize(expr)) for expr in raw)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
377
2020/d18/ex1/input
Normal file
377
2020/d18/ex1/input
Normal file
|
@ -0,0 +1,377 @@
|
|||
(5 * 7 * 5) * 6 * 5 + 7 + 6 * 4
|
||||
(2 + 3 + (2 + 8) * 3 + (7 + 4)) * 3 + 7
|
||||
2 + 4 * (2 + 2 * (9 + 2 + 6 + 3 + 6) + 4)
|
||||
4 * 3
|
||||
9 + (8 * 5 * 5 * 4 * (3 * 5) * 2) + 4 + 4
|
||||
5 + 5 + 2 * 4 + 4
|
||||
7 + 9 * 2 + 2 * 3
|
||||
5 + 8 + 5 * (6 * 8 * (9 * 2 + 2 + 7 + 4 + 2) + 4 * 6) * 5
|
||||
8 * 7 * 4 * 5 + 3
|
||||
(9 * 9 + 9 * 7 * 4) + 9 + 5 * (5 + (8 * 8) * (2 * 8) * (5 + 3 + 5 * 5 + 4 + 2)) + 2
|
||||
(4 + 7 + 2) + 9 * 3 + 7 * ((8 * 7) + 5 * (9 * 9) * 8 + (8 * 2)) * 9
|
||||
8 * 2 * (2 + 5 + (5 * 4 * 2 + 7 + 3 * 4)) + ((4 + 9) + (4 * 8) + (6 * 8 + 6) + (4 * 3 * 9) + 5) * 7
|
||||
7 + 2 + 8 * 2 * (2 * (6 * 2 * 4 * 5) * (4 * 4) + 2 + 3 + 2) + 6
|
||||
8 * ((6 + 8 * 3 * 9) + 9 + 8)
|
||||
7 + ((6 + 3 + 7 + 6 * 7) + 6 * 6)
|
||||
5 * (7 * 5 + 4 + 7 * 4 * 4) * (7 + 6 * 4 + 4 + (3 + 3 * 7 + 2 + 8)) * 8
|
||||
((3 * 7 * 3 * 9) * 2 + (5 * 2 * 6 * 6 * 5 + 6)) * 4 + 6 * 4 + 7
|
||||
2 + (7 + 5 + 9 + 9) * 4
|
||||
(9 + 6 + 5 * 5 * 5 + 5) * 9 * 2 + (6 * (8 + 4 * 9) * 5 + 7) * 9 * 5
|
||||
9 + 2 + (5 * 6 + 7) + 4 + 7
|
||||
9 * (2 * 9 * 4 * 4 + 6 * 6) * 8 * 3 * (4 + 7 + 8 * 3 + 4 + 9) * 9
|
||||
2 + 4 + 6 * 6 * (3 * 3 + 6 * 4 * 8) * (5 + (9 * 2))
|
||||
9 + (6 + 8) + 7 * (8 * (7 + 6 * 4) + 7) * ((6 * 7) + 8 + 2) * 8
|
||||
((6 * 3 * 2 + 8 + 4) * 6 + (7 * 7 * 7 + 3)) * (2 * 5 + 2 * 3) + ((2 + 8 * 5 + 4) + 6 + 6 * (3 + 8 * 9)) * 5 * 4 + 2
|
||||
(4 + (3 + 9 * 9 + 9 + 2 * 3) + 6 * 2 * 3) + (7 * 7 * 8 + 6 * 5) * 7 + 8 + (7 + 7 + 4)
|
||||
9 + (5 + 5 * 4 * 4 * 3 * 8) * 6 + 5 + 4
|
||||
8 * 2 + 9 + 7 + 6 * (3 * 6 * 7 * 6 * 8)
|
||||
(7 + 6 * 3 * 3) * 8 + (8 * 2 * 5 + 8 + 2) + 4
|
||||
5 + 9 * 5 + 5 * 6 + (7 * 8 * 8 + (2 + 9 * 4))
|
||||
((7 * 4 + 2 + 6 + 3) * 4) + 7 + 7
|
||||
(7 * 8 + 8 + 3) * 3 * (9 * 5 * 3 * 9) * 5
|
||||
6 + (8 + 8 * 7 + 7) + (5 + 7 * 4 * 4 * 5) * 5 * 2 * (5 * 4 * 5)
|
||||
2 * (5 * (8 + 5 + 8)) * 5 * ((6 + 9 + 6 + 8 + 9) * 4 + 8 + 7 + (5 * 7 * 2 * 3))
|
||||
8 + 9 * 7 + ((6 * 4 + 3 * 9 + 9) * (3 + 8 * 5 * 4 + 5 + 5) * 2 + (2 * 2 * 3 * 9))
|
||||
2 * 9 + 4 * (2 * (7 + 8 * 2 * 9 + 2 * 6) * 3 * (6 + 3 * 7 * 7 + 4))
|
||||
5 * 3 + (8 * 6 + 7 * 8 + (8 + 3)) * 7 + 3 * 2
|
||||
((2 * 7 + 7) * 9 * 8 * 7) * 6 * (6 + 2) * 9
|
||||
7 * 6 * (3 * (5 * 7 + 5 * 4) * (4 + 6 + 3) + (6 * 7)) * 3 * 8
|
||||
(3 * 6) + 7 * 2 * 6 + 7 * 3
|
||||
6 * 3 * ((4 + 8 * 7 + 2) * 3)
|
||||
6 + 9 + (3 * 9 * 5 * 8) * 7 + 8
|
||||
8 + 6 + 2 * 2 + ((7 + 4 * 9) + 8 * 4)
|
||||
6 * 3 * 5 + 7 + 5
|
||||
((4 + 5 * 2) + 6 * 7 * 7 * 6) * (7 + 8 * 4 + 9)
|
||||
(8 * 5 + 8) * (5 + 4 * (5 * 7 * 4 * 8 + 4 * 4) * 9) + (2 * 2 + (8 + 3) * 4) + (4 * 4)
|
||||
6 * (5 * 4 + (5 + 8 * 7)) * 2
|
||||
(2 * 2 * 9 + 9 + 8) * (6 * 6 + 8 * (5 * 4) * (3 + 8) + 2) + 5 + 2
|
||||
2 * (3 + (5 + 4 * 4 * 2 + 8) + 8 * 2 + 8 + 5)
|
||||
3 + 9 * (7 + (2 * 5 * 5 * 4 * 9) * (8 * 3) + 5) * 2
|
||||
(2 * (2 * 4 * 7 + 7 + 4)) * 8 * 6 * 7
|
||||
(4 * (5 * 2 * 3 * 7) * 5 + (2 * 9) + 6) + (6 + 8 * (4 * 6 * 4) + 2 * 6 * 2) + 6 * 5 + 5
|
||||
5 + (7 + 3 + 6 + 9 + 5 + (3 + 9 * 8 + 8 + 7)) * 9 * 9
|
||||
3 + 2 + (4 * 6 + (2 * 8 + 6 * 7) + 6) * 9 * 9
|
||||
(3 + 2 * (8 + 9 + 8) * 5) * 3 * 3 * ((3 + 9 * 7) + (9 * 8 + 6 * 9 * 9 * 3) * 5 * 7 + 4) + 5 * 4
|
||||
7 * 6 + 8 + 2 * (5 + 3 * 5 * 5 * 7 + 8) + 9
|
||||
7 + 6 * 6 + (5 + 6) * (8 * 3 + 2 + 9)
|
||||
6 * (7 + (3 + 8 * 9 + 4 + 7) + 6 * (2 + 8 + 3) * 5) + 9 * (5 + 5 * 2) + 8 + 3
|
||||
(6 + 6 * 9 * 3) * 6 * 3 + (5 * 4)
|
||||
6 * 9 * 8
|
||||
7 * 4 * (8 + 7 + 7) * 4 * 7 + 4
|
||||
5 + 8 * 5 * 7 + 7 + 5
|
||||
2 * ((9 * 3 * 7 + 6 * 6) + (5 * 3 * 2 * 8)) * (8 * 3 + 2 * 6) * 6 * 5
|
||||
9 + 5 + 6 * 5 + (9 * 4 * (8 + 2) * 6 + 4 * (2 + 3 + 2 * 2)) + 4
|
||||
6 * 4 + (2 + 4 + (6 * 9 * 3 * 8 * 6 + 8)) * 4 + 5
|
||||
9 + (3 * 5 * 4 * 9 + 6) * 7
|
||||
9 + (8 * 2) * (3 * 7 + (7 * 2) * 8) + 5 * (7 + 9 * 7 + 3)
|
||||
(5 + 3 + 4 + 8 * 3 * (6 * 5 * 9 * 3)) + 2 * 4
|
||||
4 + ((2 * 9 * 2 + 5) * 6 * 5) * (5 + 2) + 7 * 5 + 5
|
||||
8 * 3 * (9 * 3 + 5 * (5 * 4 * 3))
|
||||
8 * ((3 + 8 + 5) + 6 + 9) + 7 + 4 * 5
|
||||
(9 + 9 + 7) + (7 * 2) * (7 * 3 + (5 + 2 * 3) * 9 * 3) + ((2 * 6 + 2 + 7 + 8 * 2) * (2 + 3) + 4)
|
||||
(9 + 8 * 9 * (7 + 7) + 5 * 7) + 9 + 2
|
||||
3 + (8 * 5 + 9) + 2 + 8 + 8
|
||||
5 + 2 + (5 * 8 * 3 * 7 * (3 * 7 + 6) * 4) * 3
|
||||
((7 * 9 + 3 + 2) * (9 + 9 + 7) + 4 * 4) * 7
|
||||
(7 * (3 * 8 + 3) + 4 + 6 * (4 * 7 + 9)) + ((4 * 6 * 6 * 9) * (6 + 3 + 2 * 8 + 5 * 7) + 3 + 2 * 2 + 3) * 2 + (6 + 4 * (6 + 7))
|
||||
7 * (6 * 7 + 6) + 2
|
||||
4 * (3 * 4) + 9 + 8 + (4 + 5 + 9 * (7 + 9 + 5) + 7 + 2)
|
||||
7 + 2 * 5 + (4 + (8 + 3 * 3 + 6) * 5 * 7) + 6 + 3
|
||||
(4 + (9 + 8 * 7 * 7) * 3 * 6) * 7 + 9 * 7 + 5
|
||||
2 + 4
|
||||
(2 * (8 + 3 + 8 * 2 + 7 + 3) + 7 + 7 + 6) * 3 * 7 * 7 * 2
|
||||
9 + 6 + 2 + (5 + 5 + 2 * 3) + 9
|
||||
3 * (6 * 8 + 2 * 8 + 7 * (3 + 3 * 4 + 2 + 7)) * (4 + 4 + 6 * 2 * 4 + 4) * 8
|
||||
5 + (5 + 8) + (2 + (7 * 9 * 2 + 8) + 6) + 9 + 3
|
||||
9 + 5 + (8 * 4 * 3 + 4) + (6 * 3 * 9) * 3
|
||||
(5 * 7 * (7 * 7 * 6) * (8 + 2) + 8 * 7) * 3 + 7
|
||||
8 * (6 + 6 * 4 + 9 + 4) * 3 * 6 * 8 + 6
|
||||
5 * 5 + 2 * (5 * 2 * 9 + (6 + 7)) * 7
|
||||
(5 * 6 * 5 * 3) * 2 + (8 + 6 + 9 * 7 + (2 * 3 + 3 * 8 + 5 + 2))
|
||||
8 + 7 * ((6 + 4 + 4 + 8 + 7) + 2 * 5 + 3 * 9 + 6) * (3 * 5 * 5 * 9 * 4) * 3 + ((3 + 4 + 2 * 3 * 2 + 2) + 7)
|
||||
(8 + (9 * 6 * 3) * (9 + 8 + 3) + 4) * 5
|
||||
4 + (4 + 2 + 7 + 9 * 3 * 7) + 9 * (5 + (9 + 9 + 7 + 8 + 8) * 7 + (2 + 2 * 9 + 3)) + 3
|
||||
4 + 5 + 5 * (6 * 6 + 3)
|
||||
(7 * 7 + 6 * 7 * (4 * 2 + 9 + 7)) + 8
|
||||
(4 * 7 + 9 * 6) * 6 * 4 + 8 * (6 + 7 * 9) * 2
|
||||
7 + (8 + 9) * 6 * 3 + 4
|
||||
8 * (7 * (7 * 3 + 3) + 3 * 5 * 9 * 2) * 6 * ((2 + 4 * 5 * 2 + 5 + 3) + 4 + (4 * 2) * 2 * (9 + 5 + 3 + 7) * 5) + (5 + 5 + 3 + (6 + 6 * 2 * 8 + 6))
|
||||
6 * 6
|
||||
8 + 5 + 5 + (8 + (3 * 5) + 5 * 3) * 2 + 5
|
||||
((4 * 7 * 3) * 7 + 2 * (6 + 2) * 8) * 8
|
||||
(6 + 3 * 5 * 5 * 6 + 2) * 3 * 7 * 6
|
||||
6 + (9 * (4 * 8 * 5 * 3 + 6 * 9) * 4 * (8 + 3 + 3 * 4) * 6 + 4) + 4 * 2 + 9
|
||||
((5 + 4 + 6) + 7 * 8 + 7) + 8 + 9 * 8 + 3
|
||||
(4 + 2 + 5 + 4 * 7 * 9) * (7 + (2 * 9) * 8) + 3 + 5
|
||||
(3 * 6 + 8 * 8 + 2) * 6 + 4 + (7 + 2 + 6 + 2 * 7)
|
||||
8 + (2 * 9 + (3 + 4 + 3) + 2)
|
||||
5 + 2 * (5 * 9 * (6 * 8 * 3 + 6) * 8 * 5 + (5 * 4)) + 9
|
||||
6 + ((8 * 3 + 5 + 9 * 9) * 3 + 6 * 9) * (5 + (5 * 4 * 8 + 5) * 4 * (3 * 2 + 7 * 7 * 4) + 2 * 2)
|
||||
9 + 4 * (2 * (6 + 9 + 6 * 8 + 7)) * 9 * 2
|
||||
4 + 8 + (8 + 5 * 8 + 7)
|
||||
8 * (2 + 4 + 5 + 7 * 6) * (4 + 9 * 4 + 7 * 2 * 7) * 6 + 9 + 4
|
||||
8 + 3 * 8 * (2 * 5 + 5 + (5 * 2 * 6 + 3) + 6) * 9
|
||||
((4 + 5 * 7) * 9 * 8 * 2 + 6) + 9 + 7
|
||||
((4 + 3 * 6 * 3 * 4 * 7) + 3 * 5 * 4) + 9 * (8 + 7 * 2 * (2 + 8) + 9 * (2 * 8)) * 5 * 5 * 8
|
||||
2 + (5 + 6) * 4 + (9 + 5 * 5 * 7 * 5 + 2)
|
||||
6 + 6 * (6 * 3 * (2 + 3 + 4 * 3 * 7) * 3 * (4 * 9) * 5) * 9
|
||||
7 * 2 * (9 + 8 + 3 * 9 * 4) + 8
|
||||
(9 * 8 * 2 + 7 * 2 * 8) * 4 + 9 + (3 + (3 + 3 * 5 + 2) + 9 * 4 * (5 * 3 + 2)) * 6
|
||||
7 * 2 * 9 + ((5 * 5 * 8 * 4 + 3 + 7) + 8 + 2 + 3 + 6) * 5 * (8 + (5 + 6 + 7 + 6 + 8 * 6) * 6)
|
||||
5 + 6 * ((3 * 7 * 2 + 6 * 9) * 6 + 2 * (8 * 5 * 5 + 9 + 8)) * 6 + 4 * 7
|
||||
7 + 7 + 9 * 6 * 4 + 3
|
||||
4 + (3 * 8 + 8 + 2) * 8 * (9 + 3 + 7) * (4 + 7 + 2 + 5)
|
||||
9 * 2 + 5 + 6 * 6 + (3 + 9 * 6)
|
||||
(6 + 3) + 5 + (4 * 6 + 8) * 6
|
||||
9 * (6 + 6 * 7 + 6) * 7 * 3 * 5 + 4
|
||||
(7 + 8 + 8 * 2 + 5) + 7 + 2
|
||||
(5 * 4 + 8) + 9 + (3 + (8 + 2 * 5 * 7) * 9 + 3) * 7
|
||||
(2 * 3 + (7 * 4) + 8 * (6 + 4 + 7 * 4 + 5 + 4)) * 7 * 9 * 8 + (3 + 6 + 6 + 9 + 2)
|
||||
2 * 2 * (3 * (5 + 4 * 4 + 9 + 7) + 5 * 8 * (7 + 2 * 2))
|
||||
2 * 5 * 8 + 6 + (2 + 3 * (7 + 4 + 4)) * 6
|
||||
3 + 3 + 2 + 8 + (4 + 9 * (5 + 7 * 3 * 8 + 4))
|
||||
(6 * 8) * 5 + 5 * 8
|
||||
2 * 3 * 9 * (3 * 7 + 6 + 9) + 2 + 6
|
||||
5 * 8 * (2 * 3 * 7 + 3) * 7
|
||||
2 + (5 * 5 * 8 * 7 + (3 * 9) * (3 + 8 + 3)) * 5 + (6 * 2 * 9 + 3 + (4 + 4 * 7 + 6 * 6 + 8) + 9) + 5 + 9
|
||||
(3 * 5 + 7 + 5 + 5 * 7) * (2 + 4 * 4) + 5 * 6 + 9
|
||||
4 + 4 + ((9 * 3 + 5 + 4 * 7) + 6 * 6 * 2 + 9 * 2) * 9 * 9
|
||||
7 * (4 + 7 + (5 + 5 * 8 + 8 * 3 * 3) + 7 * 7 + 7)
|
||||
2 + 9 + 2
|
||||
((9 * 8 + 4 * 3 + 6 + 6) + (4 * 2) + 2 * 9 + 4) + 6 + 7 + (3 + 8 * 9 * 8) + 2 * 2
|
||||
(3 + 6 * (9 * 6) * (2 + 6 + 7 * 4) * 7 * 3) * 9 + 8
|
||||
4 + 7 * (2 * 2 + 6) * (2 + 4 + 6 * 5 + 6)
|
||||
(8 * 7 * 4 + 7 * 5 + 7) + 6 * 2
|
||||
2 * 2 + 3 * (4 + (3 + 9 * 3)) * 4
|
||||
6 + 5 * 5 + 9 + ((7 + 6 + 2) + (2 * 6 * 2 * 5) * 7 * 4 * 3 * (6 * 4)) + 9
|
||||
3 + 2 * ((9 + 2 + 2 + 6 * 9 + 4) + 5) * 8 * 9
|
||||
(8 + 4) + 2 + (2 * 2 + 8 * (5 * 6 + 6 * 4 + 9) + 8) + 2 * 8 + 2
|
||||
2 * 5 * 7 * 6 * (8 * (2 * 7 * 4 + 6) + 3 + 9 * (8 * 3 + 2) * 8)
|
||||
4 + 3 + 4 + (6 + (6 + 4 + 7) + 4 + 7) * 6
|
||||
8 + 5 + (9 * 6 * 6 + (3 * 9 + 3 + 6 + 9))
|
||||
((3 + 6) + 6 * 3 + 3) * 2 + (9 * (8 * 7) + (2 * 9 * 6) * 6 + 2) * 8 + 2
|
||||
((7 * 4 + 7 * 4 + 2 + 7) * 3 * (7 * 8 * 4 + 8 + 4 + 4)) * 6
|
||||
6 * 4 * (8 + 5 + 2)
|
||||
(8 + 5) * 2 + 4 + 6 + 3
|
||||
((4 * 5 + 7 * 2 * 8 + 9) + 4) + 7 + 3 * 8
|
||||
2 + 2 * 3 + 7 * (3 * 6 + 9 + 5 * 7 * 5)
|
||||
8 * (9 * 8 * 7 + 9 * 6 + 9) + 9
|
||||
5 * (4 * 3) * 6
|
||||
5 * 6 * 8 * (2 * (4 + 5) * 4) + 3
|
||||
4 + 8 * (2 + 6 * 8 * 7 + 9 * 3) + 5
|
||||
2 * 3 * 7 * (2 * (7 + 7 + 8) + 8 * 7 + 6 + 2) * 7 + ((4 * 2 * 3) + 9 * 7)
|
||||
9 + 6 * 6 + (3 + 4 * 3 + 9 + 5 + 3) * 4
|
||||
(2 * (4 + 3) * 9) * (2 + 9 * (6 + 6 + 3 * 5 + 2 + 4) * (2 + 5 + 4 + 7) + 2 + (4 + 4 * 8 * 7 * 7)) + (3 * 7 * (3 + 3 + 3 + 2) * (6 * 3 * 8)) * 4 + 4
|
||||
(4 + 7) + (3 * (5 * 3 + 5 + 9) * 9 * 3 * 9)
|
||||
9 + 7 * ((2 + 2 * 8 + 7 + 6 * 5) + (6 * 7) * (3 + 6 + 8 * 5) * (8 * 8) * (3 + 3 * 7 + 4 + 7))
|
||||
9 + 9 * (3 * (6 + 7 * 9 * 7 + 3)) + 3 + 6 + 9
|
||||
2 + ((3 + 7 * 8 + 9) + (8 + 8 * 9)) + 6 + 7 * 8
|
||||
4 * (6 + 8 * 8 + 4 * (3 * 2))
|
||||
(5 + 5 * 3 * 3 + 3) * 7 + 7 + 3
|
||||
2 * (2 + 6 + 4 * (3 + 4 + 7 * 8 * 9 + 9)) * 9 * 7
|
||||
(4 + 6 + 7 + 4) * 7 * ((4 + 9) + 8 + 5 * 7)
|
||||
8 * 6 + 6 + 7
|
||||
(5 + 3 * 2 + (4 * 4 + 5 * 4) + 3) + 7 + 8 + 8 + 7 * 3
|
||||
4 + (7 * 5 + 6 * 7 + (2 * 7 * 8) * 3)
|
||||
7 * ((3 * 3 + 2) + (8 + 6)) * 4 + (7 * 7) * 8 * 7
|
||||
((5 * 8) * 6 + 8) * 5 * 7
|
||||
3 * 3 + 5 + ((2 * 4 + 3 + 8 + 8) + 2 + (7 * 9 * 6) * 6 * 6)
|
||||
7 + 7 + 5 + 4 * ((5 + 8 * 8) + (2 * 2 * 2 * 6)) * 6
|
||||
(4 + 6 + 7) + 2 + 3
|
||||
(8 + 8 + 2 + (4 + 6 * 4 + 9 + 9 + 4) * 6 * 4) + 9 * 4 + (9 * 7 + 5 * (3 * 9 + 4 + 7) + 7 * 4)
|
||||
8 + (8 + 5) * (8 * (3 + 3 + 5 + 9))
|
||||
8 + (4 + (7 + 8 + 4 + 9 + 4) * 7 + (5 * 9 + 2 * 6 + 6) + 4 * (7 + 2))
|
||||
(3 * 7 + 8 + 6 * 3) + 5 * 5 + 7 * (9 + 5 + 7 * 8)
|
||||
(9 + 7 + 2 + 2) + 4 * 4 * 9
|
||||
2 + (4 + 4 + (8 * 9 * 2 * 7 * 2) * 8 * 5) * 5 + (4 + (3 + 2) * (3 * 2 * 9 + 9 * 8 + 5) + 2 * (3 * 4 * 7 * 5 * 6 + 7) * 5)
|
||||
(2 * 6 * 9 * 7) + (4 * (4 + 3) + 9) * 9
|
||||
4 * 3 + 5 + (6 * 6 * 3 * 9 * 7) * 7 * 4
|
||||
8 * 6 * (2 * 6 * 2 * 7 * (6 + 4)) * 4 + 5
|
||||
4 * 9 + 7 * 6 * ((9 + 7 * 5 * 5) + 7 * 9)
|
||||
3 + (8 + (5 * 2 + 8 * 7 + 6 + 3) + (7 + 9 * 2 + 3) * 6 * 7)
|
||||
4 * 7 * 4 * (4 * 5 + (7 + 6 * 7 + 8)) + 4
|
||||
(8 + 5 * 3) + ((8 * 7 + 6 * 5 + 8 + 9) * 5 + 2 + 7 + 8 * (5 + 7 + 4 + 4)) + 3 * 9
|
||||
6 * (7 + 2) + 4 + 7 * 2 * 5
|
||||
(2 * 9 * 9 * (3 * 4)) * 7 * 4 + 2 + 4
|
||||
(8 + (9 * 2 * 8) + (5 * 9 * 5) + (5 * 6 * 3 + 8 * 2 + 6) * 5 * 5) * 6 + 8 + 3 * 3 * 2
|
||||
2 * 5 * 7 * 4
|
||||
(2 * 8) * (2 + (4 + 2 * 5 + 2) * (2 + 7 + 6) + 5 + 5 + 7) * 4 + 8 * 7
|
||||
(8 * 5 + 4) * 5
|
||||
(9 * 6 + 8 * (3 * 8) + 5) + (8 * (3 * 9 + 7 * 3) + 9 + 2 + (4 + 5 * 7 + 6 * 9)) * 6 * 8
|
||||
5 * 4 + 3
|
||||
(8 + 7 * 9 + 5 * 5) + 9 + 3 * (6 + 6 + 5)
|
||||
(3 * 7 + 2 * 4 + 4) + 8 * 6 + 3 * 5
|
||||
((4 + 8 + 8 * 7) + 9 * 7 + 8 + (8 + 3 + 2) * 3) * 2 + (6 * 7) + 8
|
||||
(7 + (3 * 5 * 7 * 6) * 7 + (8 * 3 + 9 + 8 * 9 + 8) + 8) + 9
|
||||
((6 * 7 * 7 + 4) * 8 + 6 + 4 + 9) + 7 + 4 + 2 + 5 + 5
|
||||
4 * (2 * 2) + 2 + 3 * 3 + (4 + 2 + 2)
|
||||
((4 * 8 + 8 + 9 + 3 + 3) * 9 * 9 + 7 * (6 * 5 * 3 + 3 + 3)) + (9 * 5 * 2) + (2 + 7 + 6) * 3 * 6
|
||||
(4 * 5 * (8 * 7 + 8 + 4 + 3 * 9) * 3 + 7 * (3 + 4 + 3)) + 3 + 6 * ((6 + 2 * 8) * 9) + 2 + 4
|
||||
7 * 3 + 8 + (8 + 2 * 9 * 2 * (7 + 4 + 7 + 7 * 7 * 8)) * ((4 * 6 + 7 + 4 + 6) + 5 + 3 + 6 * 6 * (6 + 2 * 9 + 6 * 7 + 3)) * 5
|
||||
(7 * 8 + 2 * (5 * 7) + 7 * 4) * 8 + 2 * 3
|
||||
4 + (8 * 3 + 9 * 9 * 3) + 7 + 7 + (3 * 4)
|
||||
(4 * (5 + 9)) * 9 + 5 + 7
|
||||
6 * 2 * 9 + 4 + 6 * 2
|
||||
(7 + 3) * ((3 * 7) + 8 + (8 + 6 * 2 * 8 * 6 + 2)) * (7 + 9)
|
||||
9 * 4 * 3 + 7 * 6 + (3 + 8)
|
||||
4 * ((2 * 6 + 3 * 4) + 3 * 4) * 7 + 8
|
||||
(8 + 7 * (4 * 8) * 6) + 7 + 4 * 4 * ((8 * 9 * 7 * 9 + 7 + 3) + 6 + 8)
|
||||
5 * (9 + 3 * 4 * (2 * 9 * 4 * 2 + 3) * 8)
|
||||
4 * 9 * 8 * 7 + (6 * 9)
|
||||
(4 + 4 + 3 + 5) + 9 * 4
|
||||
9 + (4 + 7 + 6 + 4 * (8 * 9 * 7 * 3 * 2 * 6)) + 3 * 6
|
||||
5 + 6 + (6 * 5) + 8 + 7
|
||||
(9 + 4 * 8 * (8 * 7 * 2 + 4) * (5 * 4 + 9)) + 6 + 5
|
||||
5 * 2 + 9 + ((3 + 2 * 9 + 3) * 5 * 9 + 2 + 3) * 8 + 5
|
||||
(6 + 8 + (3 + 8 + 4 * 4) + 6 * 9 * 3) * 7 + 3 + (5 * 9 + 2 + 7 + 6 * 8) + 5 + (3 + 2 + 2 + (3 + 4 + 2))
|
||||
9 * 3 + 7 + 6 * 7 + 3
|
||||
(2 * 4 * 3 * 7 + 5) + 6 + (2 + 7 + 4 + 3 * 4) + ((7 * 2 + 7 + 6 * 8) + 6 * 2 * 5)
|
||||
((2 * 4) + 3 + 6 + 6 * (7 * 4 * 6 * 5)) * 3 * 6 + (9 * 5 + 8)
|
||||
(4 * 3 * 4 * 4) + 5 + 8 + ((8 + 6 + 8 * 9 + 7 * 5) * (6 * 2 * 3 * 6 * 8) * 3) + 8
|
||||
(3 * 8 * (8 + 4 * 2 * 9)) + 4
|
||||
3 + 7 * 7 + 3 + 9
|
||||
((4 * 7 * 2) * 2) + 2 + 9 * 3 * (9 * 3 + (8 * 5 * 9 * 9) * 6)
|
||||
9 * 6 * 4 + 5 + (6 + 5 * 4 * (8 + 9))
|
||||
2 * (2 * (6 + 2 * 2 + 9 + 6) + (8 + 8 + 7) + (6 + 8 + 7)) * 2 + 5
|
||||
5 * 8 * 2 + (7 * 7) + 7 + 6
|
||||
6 + (5 * 9 * 7) * 3 * 7
|
||||
3 + 9 * (4 + (5 * 8 + 4 + 4 + 5))
|
||||
4 * 7 * (8 * 2 + (3 * 8 + 9 + 2 + 6 + 6))
|
||||
(9 + 3) * 6 * 9 * 2 * 8 + (7 * 8)
|
||||
(8 * 2 + (5 * 8 + 6 * 9 * 8 * 3)) + 9 * ((9 + 6 + 3) * 6 * 4 * 4 * 5) + 8
|
||||
3 + 3 * (3 * 6 + 8 + (8 * 7) + 5) + 7
|
||||
5 * 3 * 2 * 3 * (4 + 9 + 8 * 9)
|
||||
(8 * (9 + 5 * 8) + (6 * 8) + 2 + (8 + 3 + 4 * 5 * 3) + 4) * (4 * 4 * 9 + 9 * 6) + 6 + 3
|
||||
2 + (5 + 8 * (5 + 4 * 7 * 4) + 4 * 7 + 5)
|
||||
5 + ((6 * 9 + 5 + 5) + 2 * (4 + 4 + 2 * 6 + 3 + 9)) * ((3 * 5 * 2 * 8 * 5) + 2 * (4 + 9 + 5 * 9 * 8) + (2 + 6 * 6 * 5 + 3 + 9)) * (2 + 9 * 9) + 2 * 6
|
||||
5 + 2 * ((7 + 4) * 3 * 6) + 7
|
||||
4 + 3 * 6 * 8
|
||||
(8 + 7) * 5 + (2 + 5 + 3 + 4 * (3 + 7) + 3)
|
||||
(2 * 2 * 7) + 2 * ((4 * 5 * 2) * 5 + 9 * (7 * 4 + 2 * 2 * 9) * 9) + 9
|
||||
3 + 6 * (7 * 7 * 2) + 6
|
||||
6 + (2 * 7) * 4 * ((3 * 2 * 4) + 3) + (7 + 2 * 7 * (5 * 2 * 3 * 3 + 8) + 7 + 7) * 8
|
||||
(5 * 3 + (8 * 8 * 5 + 3 + 2) + 6) * 5 * ((5 + 2) * (9 * 7 * 2 * 3 * 6) * 6 * (9 * 5 * 5 + 3 + 9) + (9 + 3 * 5))
|
||||
9 * 4 * 7 * 3 + (5 + 2 * 6 + 9) + (2 * 4)
|
||||
(4 * (9 + 3 * 7 + 7 * 5) + 2) + 6 * 4
|
||||
8 + 5 * 6 * 2 * 2 + (8 * 4 + 6 * 9 + 2 * 5)
|
||||
4 + (9 * 4) * 5 + (2 * 8 * 7)
|
||||
7 * (3 + (4 * 3 + 8 * 3 * 3) * 5 * 4)
|
||||
9 + 7 + (3 * 3 * (7 * 4) + (9 * 4 + 3 * 6 + 6 * 7) + 9) * 2 + 5
|
||||
8 + 6 * 9 * 4
|
||||
8 + 3 * (9 + (3 * 7 + 3 + 9 + 3) * 9) * 4 + 8
|
||||
4 + ((6 * 4 + 4 * 2 * 6 * 5) + 2 * 2) + (4 + 5 + 8 * 5 * 5) * 3 * 5 * 7
|
||||
(9 + 8 + 6 * 5 * 5) * 4 + (8 * 3 * 5) * (9 + (3 + 9 + 5 * 3 * 6 + 6) * 7 + (8 * 8 + 8) * 2 + 4)
|
||||
(8 * 6 * 2 + 5) * 9 + 6 * 2 * 5
|
||||
2 * 5 * 3 + 7 + 6 * 6
|
||||
(3 * (4 * 9 + 6 * 2) * 8 + 8) + 7 * 5 + 9 + 2 * 2
|
||||
8 + (8 * 4 + 6 * (7 * 7 + 3 * 4 * 7 + 2))
|
||||
3 + (7 * (4 * 8 * 8 + 3 * 9) + 2 * 9) + 6
|
||||
8 * (6 * 9) * 7 + (9 + 2 * 9 * 7) * (3 + 7)
|
||||
((6 + 7 + 4 + 8) * 5 * 7 + 3 + (8 * 2 * 5 + 9)) + 5 * 2 * 9 * 4
|
||||
3 * (7 * 7 + 6) * 3 * (5 * (7 * 2 + 6 * 9 + 9) + 3 + 6 * 9 * (2 * 3 * 6 * 9)) * 6 * 5
|
||||
(2 * (9 + 4 + 4 + 5 + 5) * (6 * 7 * 4 * 9) * (9 + 4 + 8 * 4) * 3) * (9 + 3 + 3 * 3 * 4 * 2) * 5 + 2 + 5 + 3
|
||||
(7 * 8) + (8 * (3 * 8 + 4)) + 3 * 7 * 7 * 6
|
||||
2 * 6 * (6 * 3 * (2 + 8 * 5 * 3 + 3 + 4)) * 5 + (9 + 9 + 2 + 3 * 3)
|
||||
5 + 7 + 4 * 2
|
||||
4 * 3 + 7 + 9 + (5 * 2 + (5 * 6) + 3 + 4) + 6
|
||||
8 * 4 * (9 + 3 + (7 * 8 + 7 * 6 + 4 * 3)) * (6 + 9 + 9 * (3 * 7 * 9 + 2 + 2 + 2) * 6 + 4) + 8
|
||||
(5 + 9 + (8 + 7 + 6) + 8) + 6 + 2
|
||||
2 * (9 + 3 + 4 + (5 + 5 + 2 * 2 + 3 + 8) + 9) * 6 * 7 * 2
|
||||
5 * (6 * 7 + 2) * 9 + 7 + 4 + 3
|
||||
9 + ((4 * 4 + 3 + 8 * 6 * 7) * (8 * 4 + 9 * 4 + 8) + 6 + (9 * 3 + 5 + 7 + 9 + 3))
|
||||
6 * (3 + 8 * (5 * 7 + 5 + 8)) * 5 * 4 + 8 * 3
|
||||
7 * (3 * (7 * 4 * 8) + 4 + 3 * (2 * 3)) * 4 + (7 + 6) * 9
|
||||
(3 + (5 + 4 + 3 * 3 * 2 + 9) + 7 + 2) + 6
|
||||
3 * (5 + (3 + 3 + 4 * 5 * 8 * 9) + 9)
|
||||
4 * (6 + 4) + (8 * 4 * (8 + 8 * 7 * 8 * 4) * 8) * 7
|
||||
(9 * (4 * 5 + 9 * 6 * 7 + 4) + 4 * 3) * 5 + 7 + 7 + 9
|
||||
5 * (7 * 8 * 8) + 4 + 9 + (4 * (3 * 5 * 6 * 7) + 4 * 8 * 4 * 3) + 2
|
||||
4 * 6 + 8 * ((3 + 4 * 3) + 6 + 3 + 2 * 5)
|
||||
6 * (2 + 4 * (7 * 4 * 4 + 4 + 6) * 4) + ((9 + 7 * 6 * 7) * 8) * 7 * 3 * 9
|
||||
3 + (3 + 2 * 7 * 6) * (5 * 2 + 2 * 2) * 2 * (5 * 2 + 3) + 8
|
||||
6 * 2 * (8 * 9)
|
||||
7 * 4 + 9 * (9 * 2)
|
||||
(2 * 6) + (6 + 7 + 5 + 8 + 4)
|
||||
6 + (9 * 5 * 6 + 5 + 6 * 6)
|
||||
(5 + 9) + 2 + (5 * 7)
|
||||
7 * 7 + 4 + (4 * 3) * 8 * (4 * (3 * 3 + 6))
|
||||
7 * (8 + 5 + (3 + 7)) * (4 + 4 + 8 + (7 * 7 * 6 + 9)) + 6 * 8 + 8
|
||||
4 + (8 + (5 + 2 * 7 + 6 * 7 * 6) + 5 * 9)
|
||||
8 + (6 + 3 * 7 * 8 + 8 * 7) + 8 + 5 + 8 * 9
|
||||
7 * (7 * (3 + 3) * 6 + 9 * 7 + (2 + 3 + 6 * 8 * 6)) + 3 * (7 * 9)
|
||||
(5 * (4 + 6) * 4 * 8 + 6 * 3) + 6 + 2 + (8 * 5 + 9 * 3 + (5 + 7 * 5 + 7) + 3)
|
||||
(2 * 7 + 3) + 9 * 8 * 7
|
||||
(4 * 3 + 9 * 5 + 4 + 4) * 9 + (3 * 9 * 7 * 4) * (3 + 5 * 4 + 6 + 5) + ((7 + 6 * 7 * 4 + 5) + 2 * 7 + 8) + 8
|
||||
(7 * 4 * 4 + 7) + (6 * 9 * 7) + 5 + (3 + 5 * 9 * 4 * 9 * 2) + 4 * 7
|
||||
(4 + 2 * 2 * 8 + 5 * 3) + 4 * 5 * 3 * (4 * (2 * 3 + 2 * 8 + 2) + 4 * 9 * (6 + 3 * 7 * 3) * 5) + (7 * 8 * 9 + 3 * 9 * 4)
|
||||
8 + (3 + 3 + 2)
|
||||
6 * (3 * 6 * (3 + 5 + 8 + 5 + 5))
|
||||
(9 + 7 * 9 + (3 * 4 * 2 * 2 * 7) + 5 + 9) + 7 + (9 * (8 * 9) * 9) + 3
|
||||
(9 * 6 * 8 * 2) + (6 + (9 * 5 + 6 * 5 + 5 + 5) * (6 + 7 * 8 * 4 + 4 + 6) + 9) + 9 * 7 * 4
|
||||
4 + (3 * (3 + 4)) * 8 + 4 + 2
|
||||
((9 * 2 * 5 * 3 + 9 + 3) * (7 * 6 * 9 * 8 * 2) * 8 + 4) * 6 + 8 * 6 + 9 + (4 * 3 + 2 * 9)
|
||||
(8 + 5 + (6 * 7 * 2 * 4 * 8)) * (9 + 8 + (4 + 8 * 2 + 8 * 4) * 9 * 8 * 9) + 7 + 9 + 7
|
||||
(5 + 2 + 3 * 5) * ((9 * 8) * 8 * 2 * 6 + (9 * 4 * 7)) + (5 + 3 * (5 + 7 + 6 * 4 + 8 + 5)) + (7 + 6 * 2 + 2 * 6 * 7) + 2
|
||||
7 * 2 + 7 + 8 + (9 * 9 + 8 * 6 + 7 * 7) * (7 + 3 + 5 * 4)
|
||||
5 * (5 + 2 + 6) * 2 + (7 * 5 + 4 + (8 * 9 + 8 * 9 + 8) + 3)
|
||||
4 + (3 + (4 * 4) + 8 + 8 * 9 + 7) * (4 * 4 * 2) + 8 * 5
|
||||
6 + 4 + ((5 + 7) + (8 + 9 * 3 + 5 * 9)) + (4 + 8 + 7 * 6) * 5
|
||||
3 + ((6 + 2 + 6) * 9 + 8 + (5 + 5) * 6 * (8 + 6 + 7 + 7 + 9 * 9)) + 9
|
||||
8 * 8
|
||||
(3 + 7) * 2 + 2
|
||||
2 * ((4 * 9 + 9 + 5 * 7 * 9) + 8 * 3 + 7 * 7) + ((3 * 4 + 4 + 6 * 9 + 8) * (7 * 2 * 9 + 8 + 5) * 9 * (9 * 3 * 3) + 6)
|
||||
(4 + 6 * 5 * 7 * 7 + 6) + 9 + 8 + 8 * 3 * 8
|
||||
7 * 6 * (3 + 5 + 6 + 4 + 5 + (2 + 2 + 7)) + 6 + 3 * (4 * (3 + 4) * 9 + 3 * (7 * 4 + 3 + 6))
|
||||
9 * 5 * 7 + (5 + 2 * 4 * 4 + 9 + 6)
|
||||
(6 + 2 * 8 * 6 + (5 + 9) + 3) * 5 + 6 + 4
|
||||
6 + 8 + 5
|
||||
6 + (8 + (6 * 3 * 5) + 4 + 5 * (5 * 6 * 2) + 8) + 3 + 9 * 8 + 6
|
||||
3 + (2 + 9 + 2 * (8 + 2 * 3 * 6 * 9) * 2) * 4
|
||||
7 + 4 + (8 + 7 * (3 * 2 * 7 + 2 + 3 * 8)) + 9 * ((5 + 5) + 2)
|
||||
2 + (2 * 5 + 5 + 9 + 4) * 2 + 8 + 8
|
||||
(2 + 4) + ((9 + 4) * 3 + 7 * 6) + 9 * 6
|
||||
(9 * (7 + 5 + 8 + 8) + 8 + 5) + ((5 + 9 + 4 * 7 * 5) * 4 + 6 + 9 * 9)
|
||||
4 + 8 + ((6 + 2 + 2 * 6 * 2) + 7) * 7 + (3 + 8 + 4 + 2)
|
||||
((4 * 2 * 9 + 5 * 9) * 7) * 9 * (7 * 8 * 6 + 8 * 6 * 8)
|
||||
(4 * (8 * 5 * 5)) + 5 + 6 * 2 + (2 + 9 + 7 + 6) * 5
|
||||
(6 + 2) + 5
|
||||
2 * (3 * 4) * 4 + 6
|
||||
2 * 8 * (6 * (7 * 4 * 9) + (2 + 2) * 2 * (6 * 2 + 9)) * (7 * (2 * 5 + 3 * 8 * 4) * (3 + 7) + 6 + 2 * 5)
|
||||
3 * 7 + (4 * 3 + 5 + 9 + 2)
|
||||
6 * 5 * 3 + 3 * 7 * ((3 * 4 * 3 + 8 + 6) * 4)
|
||||
(6 * 6 + 4 + 5 * 5) * 7
|
||||
((6 + 8 + 4 + 5 + 9) * 3 + 4 * 5 + 4) * 5 + 9 + 9 * 9
|
||||
(9 + 4 * 5 * 5 + (3 * 3 + 5)) * 5 * 4 * 9 + (4 + 5 * 9)
|
||||
2 + (9 + 5)
|
||||
8 * (8 + 3 * 9 + 7)
|
||||
(9 + (4 + 2 * 4 * 6 + 7 * 2)) + 5 * (5 * (3 * 7 + 3 * 8 * 8 * 8) * 9)
|
||||
3 * ((4 + 3 * 8 + 5) * 9) * (6 * 5 + (2 + 5 + 4 + 3 + 8 + 2))
|
||||
6 + (3 * 3 * 5 + 9 * 8 + 8) * 7 + 9
|
||||
(5 * 8) * 2 * ((3 * 5 + 6 * 9 * 3 * 8) + 8 + 4 + 2 + 2)
|
||||
(6 + 4 * 6 * 6) * (3 * 6) * 8
|
||||
((7 * 8 + 6 * 8 + 2) + 5 * 6) + 5 * 7 * 6 + 6
|
||||
4 + 8 * 9 * (2 * 5 * 8 + 9 * (5 * 8 + 9 * 4 + 6 + 4)) + 2
|
||||
9 * (7 * 7 * 7 * 8 * 5) + 8 + 4
|
||||
4 * 9
|
||||
(9 * (7 * 7 * 7 * 9)) + 6 * 7 + 4 * 8
|
||||
7 + (5 * 9 + (9 + 8 + 5)) + 4 * 7 + 8 * 5
|
||||
6 * 2 + (7 * 9) * 6
|
||||
(5 * 4) * (4 + 8)
|
||||
9 * 4 + 6 * 5 * 6 + ((8 + 9 + 8) * 8 + 6 + (4 * 2 * 2 + 3 * 6))
|
||||
7 + (7 * 2 * 4 + 2 * 5 * 4) * 7 * (9 * 4 * 2 * 7 + 9) + 8
|
||||
(6 + 2) + (5 * 8 + 8 + 4)
|
||||
(8 + (8 + 8 + 3) * 6 + (6 * 9 * 4 + 7) + 2) + 8 * 8 + 4 + ((7 + 4 + 5 + 8 + 9) + 6 + 7 + 9 + 6) + 3
|
||||
((7 + 6 + 3) * 4 + 2 + 5 + 8) * 4 * 2 * 2
|
||||
((4 + 6 + 3 + 2 + 2) + 3 * (7 * 6 + 9 * 5 + 6 * 4) * 3) * 3 * (5 + 4 + 3 * 9) * (9 + 3 + 2 + 5 * 7 + 5) + (4 * 2 + 6) + 4
|
||||
4 + 4 + ((2 * 4 + 9 * 8 * 5 + 8) * 9 * 9 * 6 + 9) + (6 + (5 + 9))
|
||||
3 + 8 * (3 + 8 * (3 * 7 * 4 * 2) + (6 * 9 * 8))
|
||||
2 + 5 + ((5 + 4) * (2 + 4) * 9 + 6) + 5 * 9
|
||||
7 + 7 + 6
|
||||
8 + (7 + 8 + 7 + 7 * (8 + 8 + 9 * 2 + 8 + 2) + (3 * 6 + 3 * 2))
|
||||
4 * 9 + (4 * (7 + 7 + 7 + 8 + 5 + 2) + 4 * 6 + 2 + 6)
|
||||
(4 * 9 * 7 + 8 + 3 + 9) + 8 + (5 * 9 + 9 + 3 + 3 + 4) * 9 * 8
|
||||
(5 + 5 * 6) * (6 + 8 + 7) + (5 + 2 + 5 * 5 * (3 + 7 + 6 * 9)) + 9
|
||||
4 * 2 + (4 + 5 + (3 + 5 + 9) + 7 + 7 + 4) + 3 + (6 * (2 + 2 + 8 * 8) + (8 + 9 * 7 + 7 + 6 * 9) + (3 * 9 * 3 * 5 + 5) * 5) * 3
|
||||
7 + 2 + (4 * 3) * 7 + (2 * 3 + 7 * 9)
|
||||
5 * 9 * 2 * (5 * 2) + 5
|
||||
4 + 4 * 6 + (2 + 5 + 6 + 8 * 7)
|
79
2020/d18/ex2/ex2.py
Executable file
79
2020/d18/ex2/ex2.py
Executable file
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from typing import Callable, Dict, List
|
||||
|
||||
"""
|
||||
E : T [ * T ]*
|
||||
|
||||
T : G [ + G ]*
|
||||
|
||||
G : '(' E ')' | CONSTANT
|
||||
"""
|
||||
|
||||
|
||||
def parse_g(expr: List[str]) -> int:
|
||||
top = expr.pop(0)
|
||||
if top == "(":
|
||||
ans = parse_e(expr)
|
||||
assert expr.pop(0) == ")"
|
||||
return ans
|
||||
return int(top)
|
||||
|
||||
|
||||
def parse_t(expr: List[str]) -> int:
|
||||
lhs = parse_g(expr)
|
||||
while len(expr) and expr[0] == "+":
|
||||
expr.pop(0)
|
||||
rhs = parse_g(expr)
|
||||
lhs += rhs
|
||||
return lhs
|
||||
|
||||
|
||||
def parse_e(expr: List[str]) -> int:
|
||||
lhs = parse_t(expr)
|
||||
while len(expr) and expr[0] == "*":
|
||||
expr.pop(0)
|
||||
rhs = parse_t(expr)
|
||||
lhs *= rhs
|
||||
return lhs
|
||||
|
||||
|
||||
def parse_infix(input: List[str]) -> int:
|
||||
"""
|
||||
Parses the given string in infix notation.
|
||||
"""
|
||||
ans = parse_e(input)
|
||||
assert len(input) == 0
|
||||
return ans
|
||||
|
||||
|
||||
def tokenize(expr: str) -> List[str]:
|
||||
res = []
|
||||
|
||||
def split_tok(tok: str) -> None:
|
||||
if "(" not in tok and ")" not in tok:
|
||||
res.append(tok)
|
||||
if "(" in tok:
|
||||
res.append("(")
|
||||
split_tok(tok[1:])
|
||||
if ")" in tok:
|
||||
split_tok(tok[:-1])
|
||||
res.append(")")
|
||||
|
||||
for tok in expr.split():
|
||||
split_tok(tok)
|
||||
return res
|
||||
|
||||
|
||||
def solve(raw: List[str]) -> int:
|
||||
return sum(parse_infix(tokenize(expr)) for expr in raw)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
377
2020/d18/ex2/input
Normal file
377
2020/d18/ex2/input
Normal file
|
@ -0,0 +1,377 @@
|
|||
(5 * 7 * 5) * 6 * 5 + 7 + 6 * 4
|
||||
(2 + 3 + (2 + 8) * 3 + (7 + 4)) * 3 + 7
|
||||
2 + 4 * (2 + 2 * (9 + 2 + 6 + 3 + 6) + 4)
|
||||
4 * 3
|
||||
9 + (8 * 5 * 5 * 4 * (3 * 5) * 2) + 4 + 4
|
||||
5 + 5 + 2 * 4 + 4
|
||||
7 + 9 * 2 + 2 * 3
|
||||
5 + 8 + 5 * (6 * 8 * (9 * 2 + 2 + 7 + 4 + 2) + 4 * 6) * 5
|
||||
8 * 7 * 4 * 5 + 3
|
||||
(9 * 9 + 9 * 7 * 4) + 9 + 5 * (5 + (8 * 8) * (2 * 8) * (5 + 3 + 5 * 5 + 4 + 2)) + 2
|
||||
(4 + 7 + 2) + 9 * 3 + 7 * ((8 * 7) + 5 * (9 * 9) * 8 + (8 * 2)) * 9
|
||||
8 * 2 * (2 + 5 + (5 * 4 * 2 + 7 + 3 * 4)) + ((4 + 9) + (4 * 8) + (6 * 8 + 6) + (4 * 3 * 9) + 5) * 7
|
||||
7 + 2 + 8 * 2 * (2 * (6 * 2 * 4 * 5) * (4 * 4) + 2 + 3 + 2) + 6
|
||||
8 * ((6 + 8 * 3 * 9) + 9 + 8)
|
||||
7 + ((6 + 3 + 7 + 6 * 7) + 6 * 6)
|
||||
5 * (7 * 5 + 4 + 7 * 4 * 4) * (7 + 6 * 4 + 4 + (3 + 3 * 7 + 2 + 8)) * 8
|
||||
((3 * 7 * 3 * 9) * 2 + (5 * 2 * 6 * 6 * 5 + 6)) * 4 + 6 * 4 + 7
|
||||
2 + (7 + 5 + 9 + 9) * 4
|
||||
(9 + 6 + 5 * 5 * 5 + 5) * 9 * 2 + (6 * (8 + 4 * 9) * 5 + 7) * 9 * 5
|
||||
9 + 2 + (5 * 6 + 7) + 4 + 7
|
||||
9 * (2 * 9 * 4 * 4 + 6 * 6) * 8 * 3 * (4 + 7 + 8 * 3 + 4 + 9) * 9
|
||||
2 + 4 + 6 * 6 * (3 * 3 + 6 * 4 * 8) * (5 + (9 * 2))
|
||||
9 + (6 + 8) + 7 * (8 * (7 + 6 * 4) + 7) * ((6 * 7) + 8 + 2) * 8
|
||||
((6 * 3 * 2 + 8 + 4) * 6 + (7 * 7 * 7 + 3)) * (2 * 5 + 2 * 3) + ((2 + 8 * 5 + 4) + 6 + 6 * (3 + 8 * 9)) * 5 * 4 + 2
|
||||
(4 + (3 + 9 * 9 + 9 + 2 * 3) + 6 * 2 * 3) + (7 * 7 * 8 + 6 * 5) * 7 + 8 + (7 + 7 + 4)
|
||||
9 + (5 + 5 * 4 * 4 * 3 * 8) * 6 + 5 + 4
|
||||
8 * 2 + 9 + 7 + 6 * (3 * 6 * 7 * 6 * 8)
|
||||
(7 + 6 * 3 * 3) * 8 + (8 * 2 * 5 + 8 + 2) + 4
|
||||
5 + 9 * 5 + 5 * 6 + (7 * 8 * 8 + (2 + 9 * 4))
|
||||
((7 * 4 + 2 + 6 + 3) * 4) + 7 + 7
|
||||
(7 * 8 + 8 + 3) * 3 * (9 * 5 * 3 * 9) * 5
|
||||
6 + (8 + 8 * 7 + 7) + (5 + 7 * 4 * 4 * 5) * 5 * 2 * (5 * 4 * 5)
|
||||
2 * (5 * (8 + 5 + 8)) * 5 * ((6 + 9 + 6 + 8 + 9) * 4 + 8 + 7 + (5 * 7 * 2 * 3))
|
||||
8 + 9 * 7 + ((6 * 4 + 3 * 9 + 9) * (3 + 8 * 5 * 4 + 5 + 5) * 2 + (2 * 2 * 3 * 9))
|
||||
2 * 9 + 4 * (2 * (7 + 8 * 2 * 9 + 2 * 6) * 3 * (6 + 3 * 7 * 7 + 4))
|
||||
5 * 3 + (8 * 6 + 7 * 8 + (8 + 3)) * 7 + 3 * 2
|
||||
((2 * 7 + 7) * 9 * 8 * 7) * 6 * (6 + 2) * 9
|
||||
7 * 6 * (3 * (5 * 7 + 5 * 4) * (4 + 6 + 3) + (6 * 7)) * 3 * 8
|
||||
(3 * 6) + 7 * 2 * 6 + 7 * 3
|
||||
6 * 3 * ((4 + 8 * 7 + 2) * 3)
|
||||
6 + 9 + (3 * 9 * 5 * 8) * 7 + 8
|
||||
8 + 6 + 2 * 2 + ((7 + 4 * 9) + 8 * 4)
|
||||
6 * 3 * 5 + 7 + 5
|
||||
((4 + 5 * 2) + 6 * 7 * 7 * 6) * (7 + 8 * 4 + 9)
|
||||
(8 * 5 + 8) * (5 + 4 * (5 * 7 * 4 * 8 + 4 * 4) * 9) + (2 * 2 + (8 + 3) * 4) + (4 * 4)
|
||||
6 * (5 * 4 + (5 + 8 * 7)) * 2
|
||||
(2 * 2 * 9 + 9 + 8) * (6 * 6 + 8 * (5 * 4) * (3 + 8) + 2) + 5 + 2
|
||||
2 * (3 + (5 + 4 * 4 * 2 + 8) + 8 * 2 + 8 + 5)
|
||||
3 + 9 * (7 + (2 * 5 * 5 * 4 * 9) * (8 * 3) + 5) * 2
|
||||
(2 * (2 * 4 * 7 + 7 + 4)) * 8 * 6 * 7
|
||||
(4 * (5 * 2 * 3 * 7) * 5 + (2 * 9) + 6) + (6 + 8 * (4 * 6 * 4) + 2 * 6 * 2) + 6 * 5 + 5
|
||||
5 + (7 + 3 + 6 + 9 + 5 + (3 + 9 * 8 + 8 + 7)) * 9 * 9
|
||||
3 + 2 + (4 * 6 + (2 * 8 + 6 * 7) + 6) * 9 * 9
|
||||
(3 + 2 * (8 + 9 + 8) * 5) * 3 * 3 * ((3 + 9 * 7) + (9 * 8 + 6 * 9 * 9 * 3) * 5 * 7 + 4) + 5 * 4
|
||||
7 * 6 + 8 + 2 * (5 + 3 * 5 * 5 * 7 + 8) + 9
|
||||
7 + 6 * 6 + (5 + 6) * (8 * 3 + 2 + 9)
|
||||
6 * (7 + (3 + 8 * 9 + 4 + 7) + 6 * (2 + 8 + 3) * 5) + 9 * (5 + 5 * 2) + 8 + 3
|
||||
(6 + 6 * 9 * 3) * 6 * 3 + (5 * 4)
|
||||
6 * 9 * 8
|
||||
7 * 4 * (8 + 7 + 7) * 4 * 7 + 4
|
||||
5 + 8 * 5 * 7 + 7 + 5
|
||||
2 * ((9 * 3 * 7 + 6 * 6) + (5 * 3 * 2 * 8)) * (8 * 3 + 2 * 6) * 6 * 5
|
||||
9 + 5 + 6 * 5 + (9 * 4 * (8 + 2) * 6 + 4 * (2 + 3 + 2 * 2)) + 4
|
||||
6 * 4 + (2 + 4 + (6 * 9 * 3 * 8 * 6 + 8)) * 4 + 5
|
||||
9 + (3 * 5 * 4 * 9 + 6) * 7
|
||||
9 + (8 * 2) * (3 * 7 + (7 * 2) * 8) + 5 * (7 + 9 * 7 + 3)
|
||||
(5 + 3 + 4 + 8 * 3 * (6 * 5 * 9 * 3)) + 2 * 4
|
||||
4 + ((2 * 9 * 2 + 5) * 6 * 5) * (5 + 2) + 7 * 5 + 5
|
||||
8 * 3 * (9 * 3 + 5 * (5 * 4 * 3))
|
||||
8 * ((3 + 8 + 5) + 6 + 9) + 7 + 4 * 5
|
||||
(9 + 9 + 7) + (7 * 2) * (7 * 3 + (5 + 2 * 3) * 9 * 3) + ((2 * 6 + 2 + 7 + 8 * 2) * (2 + 3) + 4)
|
||||
(9 + 8 * 9 * (7 + 7) + 5 * 7) + 9 + 2
|
||||
3 + (8 * 5 + 9) + 2 + 8 + 8
|
||||
5 + 2 + (5 * 8 * 3 * 7 * (3 * 7 + 6) * 4) * 3
|
||||
((7 * 9 + 3 + 2) * (9 + 9 + 7) + 4 * 4) * 7
|
||||
(7 * (3 * 8 + 3) + 4 + 6 * (4 * 7 + 9)) + ((4 * 6 * 6 * 9) * (6 + 3 + 2 * 8 + 5 * 7) + 3 + 2 * 2 + 3) * 2 + (6 + 4 * (6 + 7))
|
||||
7 * (6 * 7 + 6) + 2
|
||||
4 * (3 * 4) + 9 + 8 + (4 + 5 + 9 * (7 + 9 + 5) + 7 + 2)
|
||||
7 + 2 * 5 + (4 + (8 + 3 * 3 + 6) * 5 * 7) + 6 + 3
|
||||
(4 + (9 + 8 * 7 * 7) * 3 * 6) * 7 + 9 * 7 + 5
|
||||
2 + 4
|
||||
(2 * (8 + 3 + 8 * 2 + 7 + 3) + 7 + 7 + 6) * 3 * 7 * 7 * 2
|
||||
9 + 6 + 2 + (5 + 5 + 2 * 3) + 9
|
||||
3 * (6 * 8 + 2 * 8 + 7 * (3 + 3 * 4 + 2 + 7)) * (4 + 4 + 6 * 2 * 4 + 4) * 8
|
||||
5 + (5 + 8) + (2 + (7 * 9 * 2 + 8) + 6) + 9 + 3
|
||||
9 + 5 + (8 * 4 * 3 + 4) + (6 * 3 * 9) * 3
|
||||
(5 * 7 * (7 * 7 * 6) * (8 + 2) + 8 * 7) * 3 + 7
|
||||
8 * (6 + 6 * 4 + 9 + 4) * 3 * 6 * 8 + 6
|
||||
5 * 5 + 2 * (5 * 2 * 9 + (6 + 7)) * 7
|
||||
(5 * 6 * 5 * 3) * 2 + (8 + 6 + 9 * 7 + (2 * 3 + 3 * 8 + 5 + 2))
|
||||
8 + 7 * ((6 + 4 + 4 + 8 + 7) + 2 * 5 + 3 * 9 + 6) * (3 * 5 * 5 * 9 * 4) * 3 + ((3 + 4 + 2 * 3 * 2 + 2) + 7)
|
||||
(8 + (9 * 6 * 3) * (9 + 8 + 3) + 4) * 5
|
||||
4 + (4 + 2 + 7 + 9 * 3 * 7) + 9 * (5 + (9 + 9 + 7 + 8 + 8) * 7 + (2 + 2 * 9 + 3)) + 3
|
||||
4 + 5 + 5 * (6 * 6 + 3)
|
||||
(7 * 7 + 6 * 7 * (4 * 2 + 9 + 7)) + 8
|
||||
(4 * 7 + 9 * 6) * 6 * 4 + 8 * (6 + 7 * 9) * 2
|
||||
7 + (8 + 9) * 6 * 3 + 4
|
||||
8 * (7 * (7 * 3 + 3) + 3 * 5 * 9 * 2) * 6 * ((2 + 4 * 5 * 2 + 5 + 3) + 4 + (4 * 2) * 2 * (9 + 5 + 3 + 7) * 5) + (5 + 5 + 3 + (6 + 6 * 2 * 8 + 6))
|
||||
6 * 6
|
||||
8 + 5 + 5 + (8 + (3 * 5) + 5 * 3) * 2 + 5
|
||||
((4 * 7 * 3) * 7 + 2 * (6 + 2) * 8) * 8
|
||||
(6 + 3 * 5 * 5 * 6 + 2) * 3 * 7 * 6
|
||||
6 + (9 * (4 * 8 * 5 * 3 + 6 * 9) * 4 * (8 + 3 + 3 * 4) * 6 + 4) + 4 * 2 + 9
|
||||
((5 + 4 + 6) + 7 * 8 + 7) + 8 + 9 * 8 + 3
|
||||
(4 + 2 + 5 + 4 * 7 * 9) * (7 + (2 * 9) * 8) + 3 + 5
|
||||
(3 * 6 + 8 * 8 + 2) * 6 + 4 + (7 + 2 + 6 + 2 * 7)
|
||||
8 + (2 * 9 + (3 + 4 + 3) + 2)
|
||||
5 + 2 * (5 * 9 * (6 * 8 * 3 + 6) * 8 * 5 + (5 * 4)) + 9
|
||||
6 + ((8 * 3 + 5 + 9 * 9) * 3 + 6 * 9) * (5 + (5 * 4 * 8 + 5) * 4 * (3 * 2 + 7 * 7 * 4) + 2 * 2)
|
||||
9 + 4 * (2 * (6 + 9 + 6 * 8 + 7)) * 9 * 2
|
||||
4 + 8 + (8 + 5 * 8 + 7)
|
||||
8 * (2 + 4 + 5 + 7 * 6) * (4 + 9 * 4 + 7 * 2 * 7) * 6 + 9 + 4
|
||||
8 + 3 * 8 * (2 * 5 + 5 + (5 * 2 * 6 + 3) + 6) * 9
|
||||
((4 + 5 * 7) * 9 * 8 * 2 + 6) + 9 + 7
|
||||
((4 + 3 * 6 * 3 * 4 * 7) + 3 * 5 * 4) + 9 * (8 + 7 * 2 * (2 + 8) + 9 * (2 * 8)) * 5 * 5 * 8
|
||||
2 + (5 + 6) * 4 + (9 + 5 * 5 * 7 * 5 + 2)
|
||||
6 + 6 * (6 * 3 * (2 + 3 + 4 * 3 * 7) * 3 * (4 * 9) * 5) * 9
|
||||
7 * 2 * (9 + 8 + 3 * 9 * 4) + 8
|
||||
(9 * 8 * 2 + 7 * 2 * 8) * 4 + 9 + (3 + (3 + 3 * 5 + 2) + 9 * 4 * (5 * 3 + 2)) * 6
|
||||
7 * 2 * 9 + ((5 * 5 * 8 * 4 + 3 + 7) + 8 + 2 + 3 + 6) * 5 * (8 + (5 + 6 + 7 + 6 + 8 * 6) * 6)
|
||||
5 + 6 * ((3 * 7 * 2 + 6 * 9) * 6 + 2 * (8 * 5 * 5 + 9 + 8)) * 6 + 4 * 7
|
||||
7 + 7 + 9 * 6 * 4 + 3
|
||||
4 + (3 * 8 + 8 + 2) * 8 * (9 + 3 + 7) * (4 + 7 + 2 + 5)
|
||||
9 * 2 + 5 + 6 * 6 + (3 + 9 * 6)
|
||||
(6 + 3) + 5 + (4 * 6 + 8) * 6
|
||||
9 * (6 + 6 * 7 + 6) * 7 * 3 * 5 + 4
|
||||
(7 + 8 + 8 * 2 + 5) + 7 + 2
|
||||
(5 * 4 + 8) + 9 + (3 + (8 + 2 * 5 * 7) * 9 + 3) * 7
|
||||
(2 * 3 + (7 * 4) + 8 * (6 + 4 + 7 * 4 + 5 + 4)) * 7 * 9 * 8 + (3 + 6 + 6 + 9 + 2)
|
||||
2 * 2 * (3 * (5 + 4 * 4 + 9 + 7) + 5 * 8 * (7 + 2 * 2))
|
||||
2 * 5 * 8 + 6 + (2 + 3 * (7 + 4 + 4)) * 6
|
||||
3 + 3 + 2 + 8 + (4 + 9 * (5 + 7 * 3 * 8 + 4))
|
||||
(6 * 8) * 5 + 5 * 8
|
||||
2 * 3 * 9 * (3 * 7 + 6 + 9) + 2 + 6
|
||||
5 * 8 * (2 * 3 * 7 + 3) * 7
|
||||
2 + (5 * 5 * 8 * 7 + (3 * 9) * (3 + 8 + 3)) * 5 + (6 * 2 * 9 + 3 + (4 + 4 * 7 + 6 * 6 + 8) + 9) + 5 + 9
|
||||
(3 * 5 + 7 + 5 + 5 * 7) * (2 + 4 * 4) + 5 * 6 + 9
|
||||
4 + 4 + ((9 * 3 + 5 + 4 * 7) + 6 * 6 * 2 + 9 * 2) * 9 * 9
|
||||
7 * (4 + 7 + (5 + 5 * 8 + 8 * 3 * 3) + 7 * 7 + 7)
|
||||
2 + 9 + 2
|
||||
((9 * 8 + 4 * 3 + 6 + 6) + (4 * 2) + 2 * 9 + 4) + 6 + 7 + (3 + 8 * 9 * 8) + 2 * 2
|
||||
(3 + 6 * (9 * 6) * (2 + 6 + 7 * 4) * 7 * 3) * 9 + 8
|
||||
4 + 7 * (2 * 2 + 6) * (2 + 4 + 6 * 5 + 6)
|
||||
(8 * 7 * 4 + 7 * 5 + 7) + 6 * 2
|
||||
2 * 2 + 3 * (4 + (3 + 9 * 3)) * 4
|
||||
6 + 5 * 5 + 9 + ((7 + 6 + 2) + (2 * 6 * 2 * 5) * 7 * 4 * 3 * (6 * 4)) + 9
|
||||
3 + 2 * ((9 + 2 + 2 + 6 * 9 + 4) + 5) * 8 * 9
|
||||
(8 + 4) + 2 + (2 * 2 + 8 * (5 * 6 + 6 * 4 + 9) + 8) + 2 * 8 + 2
|
||||
2 * 5 * 7 * 6 * (8 * (2 * 7 * 4 + 6) + 3 + 9 * (8 * 3 + 2) * 8)
|
||||
4 + 3 + 4 + (6 + (6 + 4 + 7) + 4 + 7) * 6
|
||||
8 + 5 + (9 * 6 * 6 + (3 * 9 + 3 + 6 + 9))
|
||||
((3 + 6) + 6 * 3 + 3) * 2 + (9 * (8 * 7) + (2 * 9 * 6) * 6 + 2) * 8 + 2
|
||||
((7 * 4 + 7 * 4 + 2 + 7) * 3 * (7 * 8 * 4 + 8 + 4 + 4)) * 6
|
||||
6 * 4 * (8 + 5 + 2)
|
||||
(8 + 5) * 2 + 4 + 6 + 3
|
||||
((4 * 5 + 7 * 2 * 8 + 9) + 4) + 7 + 3 * 8
|
||||
2 + 2 * 3 + 7 * (3 * 6 + 9 + 5 * 7 * 5)
|
||||
8 * (9 * 8 * 7 + 9 * 6 + 9) + 9
|
||||
5 * (4 * 3) * 6
|
||||
5 * 6 * 8 * (2 * (4 + 5) * 4) + 3
|
||||
4 + 8 * (2 + 6 * 8 * 7 + 9 * 3) + 5
|
||||
2 * 3 * 7 * (2 * (7 + 7 + 8) + 8 * 7 + 6 + 2) * 7 + ((4 * 2 * 3) + 9 * 7)
|
||||
9 + 6 * 6 + (3 + 4 * 3 + 9 + 5 + 3) * 4
|
||||
(2 * (4 + 3) * 9) * (2 + 9 * (6 + 6 + 3 * 5 + 2 + 4) * (2 + 5 + 4 + 7) + 2 + (4 + 4 * 8 * 7 * 7)) + (3 * 7 * (3 + 3 + 3 + 2) * (6 * 3 * 8)) * 4 + 4
|
||||
(4 + 7) + (3 * (5 * 3 + 5 + 9) * 9 * 3 * 9)
|
||||
9 + 7 * ((2 + 2 * 8 + 7 + 6 * 5) + (6 * 7) * (3 + 6 + 8 * 5) * (8 * 8) * (3 + 3 * 7 + 4 + 7))
|
||||
9 + 9 * (3 * (6 + 7 * 9 * 7 + 3)) + 3 + 6 + 9
|
||||
2 + ((3 + 7 * 8 + 9) + (8 + 8 * 9)) + 6 + 7 * 8
|
||||
4 * (6 + 8 * 8 + 4 * (3 * 2))
|
||||
(5 + 5 * 3 * 3 + 3) * 7 + 7 + 3
|
||||
2 * (2 + 6 + 4 * (3 + 4 + 7 * 8 * 9 + 9)) * 9 * 7
|
||||
(4 + 6 + 7 + 4) * 7 * ((4 + 9) + 8 + 5 * 7)
|
||||
8 * 6 + 6 + 7
|
||||
(5 + 3 * 2 + (4 * 4 + 5 * 4) + 3) + 7 + 8 + 8 + 7 * 3
|
||||
4 + (7 * 5 + 6 * 7 + (2 * 7 * 8) * 3)
|
||||
7 * ((3 * 3 + 2) + (8 + 6)) * 4 + (7 * 7) * 8 * 7
|
||||
((5 * 8) * 6 + 8) * 5 * 7
|
||||
3 * 3 + 5 + ((2 * 4 + 3 + 8 + 8) + 2 + (7 * 9 * 6) * 6 * 6)
|
||||
7 + 7 + 5 + 4 * ((5 + 8 * 8) + (2 * 2 * 2 * 6)) * 6
|
||||
(4 + 6 + 7) + 2 + 3
|
||||
(8 + 8 + 2 + (4 + 6 * 4 + 9 + 9 + 4) * 6 * 4) + 9 * 4 + (9 * 7 + 5 * (3 * 9 + 4 + 7) + 7 * 4)
|
||||
8 + (8 + 5) * (8 * (3 + 3 + 5 + 9))
|
||||
8 + (4 + (7 + 8 + 4 + 9 + 4) * 7 + (5 * 9 + 2 * 6 + 6) + 4 * (7 + 2))
|
||||
(3 * 7 + 8 + 6 * 3) + 5 * 5 + 7 * (9 + 5 + 7 * 8)
|
||||
(9 + 7 + 2 + 2) + 4 * 4 * 9
|
||||
2 + (4 + 4 + (8 * 9 * 2 * 7 * 2) * 8 * 5) * 5 + (4 + (3 + 2) * (3 * 2 * 9 + 9 * 8 + 5) + 2 * (3 * 4 * 7 * 5 * 6 + 7) * 5)
|
||||
(2 * 6 * 9 * 7) + (4 * (4 + 3) + 9) * 9
|
||||
4 * 3 + 5 + (6 * 6 * 3 * 9 * 7) * 7 * 4
|
||||
8 * 6 * (2 * 6 * 2 * 7 * (6 + 4)) * 4 + 5
|
||||
4 * 9 + 7 * 6 * ((9 + 7 * 5 * 5) + 7 * 9)
|
||||
3 + (8 + (5 * 2 + 8 * 7 + 6 + 3) + (7 + 9 * 2 + 3) * 6 * 7)
|
||||
4 * 7 * 4 * (4 * 5 + (7 + 6 * 7 + 8)) + 4
|
||||
(8 + 5 * 3) + ((8 * 7 + 6 * 5 + 8 + 9) * 5 + 2 + 7 + 8 * (5 + 7 + 4 + 4)) + 3 * 9
|
||||
6 * (7 + 2) + 4 + 7 * 2 * 5
|
||||
(2 * 9 * 9 * (3 * 4)) * 7 * 4 + 2 + 4
|
||||
(8 + (9 * 2 * 8) + (5 * 9 * 5) + (5 * 6 * 3 + 8 * 2 + 6) * 5 * 5) * 6 + 8 + 3 * 3 * 2
|
||||
2 * 5 * 7 * 4
|
||||
(2 * 8) * (2 + (4 + 2 * 5 + 2) * (2 + 7 + 6) + 5 + 5 + 7) * 4 + 8 * 7
|
||||
(8 * 5 + 4) * 5
|
||||
(9 * 6 + 8 * (3 * 8) + 5) + (8 * (3 * 9 + 7 * 3) + 9 + 2 + (4 + 5 * 7 + 6 * 9)) * 6 * 8
|
||||
5 * 4 + 3
|
||||
(8 + 7 * 9 + 5 * 5) + 9 + 3 * (6 + 6 + 5)
|
||||
(3 * 7 + 2 * 4 + 4) + 8 * 6 + 3 * 5
|
||||
((4 + 8 + 8 * 7) + 9 * 7 + 8 + (8 + 3 + 2) * 3) * 2 + (6 * 7) + 8
|
||||
(7 + (3 * 5 * 7 * 6) * 7 + (8 * 3 + 9 + 8 * 9 + 8) + 8) + 9
|
||||
((6 * 7 * 7 + 4) * 8 + 6 + 4 + 9) + 7 + 4 + 2 + 5 + 5
|
||||
4 * (2 * 2) + 2 + 3 * 3 + (4 + 2 + 2)
|
||||
((4 * 8 + 8 + 9 + 3 + 3) * 9 * 9 + 7 * (6 * 5 * 3 + 3 + 3)) + (9 * 5 * 2) + (2 + 7 + 6) * 3 * 6
|
||||
(4 * 5 * (8 * 7 + 8 + 4 + 3 * 9) * 3 + 7 * (3 + 4 + 3)) + 3 + 6 * ((6 + 2 * 8) * 9) + 2 + 4
|
||||
7 * 3 + 8 + (8 + 2 * 9 * 2 * (7 + 4 + 7 + 7 * 7 * 8)) * ((4 * 6 + 7 + 4 + 6) + 5 + 3 + 6 * 6 * (6 + 2 * 9 + 6 * 7 + 3)) * 5
|
||||
(7 * 8 + 2 * (5 * 7) + 7 * 4) * 8 + 2 * 3
|
||||
4 + (8 * 3 + 9 * 9 * 3) + 7 + 7 + (3 * 4)
|
||||
(4 * (5 + 9)) * 9 + 5 + 7
|
||||
6 * 2 * 9 + 4 + 6 * 2
|
||||
(7 + 3) * ((3 * 7) + 8 + (8 + 6 * 2 * 8 * 6 + 2)) * (7 + 9)
|
||||
9 * 4 * 3 + 7 * 6 + (3 + 8)
|
||||
4 * ((2 * 6 + 3 * 4) + 3 * 4) * 7 + 8
|
||||
(8 + 7 * (4 * 8) * 6) + 7 + 4 * 4 * ((8 * 9 * 7 * 9 + 7 + 3) + 6 + 8)
|
||||
5 * (9 + 3 * 4 * (2 * 9 * 4 * 2 + 3) * 8)
|
||||
4 * 9 * 8 * 7 + (6 * 9)
|
||||
(4 + 4 + 3 + 5) + 9 * 4
|
||||
9 + (4 + 7 + 6 + 4 * (8 * 9 * 7 * 3 * 2 * 6)) + 3 * 6
|
||||
5 + 6 + (6 * 5) + 8 + 7
|
||||
(9 + 4 * 8 * (8 * 7 * 2 + 4) * (5 * 4 + 9)) + 6 + 5
|
||||
5 * 2 + 9 + ((3 + 2 * 9 + 3) * 5 * 9 + 2 + 3) * 8 + 5
|
||||
(6 + 8 + (3 + 8 + 4 * 4) + 6 * 9 * 3) * 7 + 3 + (5 * 9 + 2 + 7 + 6 * 8) + 5 + (3 + 2 + 2 + (3 + 4 + 2))
|
||||
9 * 3 + 7 + 6 * 7 + 3
|
||||
(2 * 4 * 3 * 7 + 5) + 6 + (2 + 7 + 4 + 3 * 4) + ((7 * 2 + 7 + 6 * 8) + 6 * 2 * 5)
|
||||
((2 * 4) + 3 + 6 + 6 * (7 * 4 * 6 * 5)) * 3 * 6 + (9 * 5 + 8)
|
||||
(4 * 3 * 4 * 4) + 5 + 8 + ((8 + 6 + 8 * 9 + 7 * 5) * (6 * 2 * 3 * 6 * 8) * 3) + 8
|
||||
(3 * 8 * (8 + 4 * 2 * 9)) + 4
|
||||
3 + 7 * 7 + 3 + 9
|
||||
((4 * 7 * 2) * 2) + 2 + 9 * 3 * (9 * 3 + (8 * 5 * 9 * 9) * 6)
|
||||
9 * 6 * 4 + 5 + (6 + 5 * 4 * (8 + 9))
|
||||
2 * (2 * (6 + 2 * 2 + 9 + 6) + (8 + 8 + 7) + (6 + 8 + 7)) * 2 + 5
|
||||
5 * 8 * 2 + (7 * 7) + 7 + 6
|
||||
6 + (5 * 9 * 7) * 3 * 7
|
||||
3 + 9 * (4 + (5 * 8 + 4 + 4 + 5))
|
||||
4 * 7 * (8 * 2 + (3 * 8 + 9 + 2 + 6 + 6))
|
||||
(9 + 3) * 6 * 9 * 2 * 8 + (7 * 8)
|
||||
(8 * 2 + (5 * 8 + 6 * 9 * 8 * 3)) + 9 * ((9 + 6 + 3) * 6 * 4 * 4 * 5) + 8
|
||||
3 + 3 * (3 * 6 + 8 + (8 * 7) + 5) + 7
|
||||
5 * 3 * 2 * 3 * (4 + 9 + 8 * 9)
|
||||
(8 * (9 + 5 * 8) + (6 * 8) + 2 + (8 + 3 + 4 * 5 * 3) + 4) * (4 * 4 * 9 + 9 * 6) + 6 + 3
|
||||
2 + (5 + 8 * (5 + 4 * 7 * 4) + 4 * 7 + 5)
|
||||
5 + ((6 * 9 + 5 + 5) + 2 * (4 + 4 + 2 * 6 + 3 + 9)) * ((3 * 5 * 2 * 8 * 5) + 2 * (4 + 9 + 5 * 9 * 8) + (2 + 6 * 6 * 5 + 3 + 9)) * (2 + 9 * 9) + 2 * 6
|
||||
5 + 2 * ((7 + 4) * 3 * 6) + 7
|
||||
4 + 3 * 6 * 8
|
||||
(8 + 7) * 5 + (2 + 5 + 3 + 4 * (3 + 7) + 3)
|
||||
(2 * 2 * 7) + 2 * ((4 * 5 * 2) * 5 + 9 * (7 * 4 + 2 * 2 * 9) * 9) + 9
|
||||
3 + 6 * (7 * 7 * 2) + 6
|
||||
6 + (2 * 7) * 4 * ((3 * 2 * 4) + 3) + (7 + 2 * 7 * (5 * 2 * 3 * 3 + 8) + 7 + 7) * 8
|
||||
(5 * 3 + (8 * 8 * 5 + 3 + 2) + 6) * 5 * ((5 + 2) * (9 * 7 * 2 * 3 * 6) * 6 * (9 * 5 * 5 + 3 + 9) + (9 + 3 * 5))
|
||||
9 * 4 * 7 * 3 + (5 + 2 * 6 + 9) + (2 * 4)
|
||||
(4 * (9 + 3 * 7 + 7 * 5) + 2) + 6 * 4
|
||||
8 + 5 * 6 * 2 * 2 + (8 * 4 + 6 * 9 + 2 * 5)
|
||||
4 + (9 * 4) * 5 + (2 * 8 * 7)
|
||||
7 * (3 + (4 * 3 + 8 * 3 * 3) * 5 * 4)
|
||||
9 + 7 + (3 * 3 * (7 * 4) + (9 * 4 + 3 * 6 + 6 * 7) + 9) * 2 + 5
|
||||
8 + 6 * 9 * 4
|
||||
8 + 3 * (9 + (3 * 7 + 3 + 9 + 3) * 9) * 4 + 8
|
||||
4 + ((6 * 4 + 4 * 2 * 6 * 5) + 2 * 2) + (4 + 5 + 8 * 5 * 5) * 3 * 5 * 7
|
||||
(9 + 8 + 6 * 5 * 5) * 4 + (8 * 3 * 5) * (9 + (3 + 9 + 5 * 3 * 6 + 6) * 7 + (8 * 8 + 8) * 2 + 4)
|
||||
(8 * 6 * 2 + 5) * 9 + 6 * 2 * 5
|
||||
2 * 5 * 3 + 7 + 6 * 6
|
||||
(3 * (4 * 9 + 6 * 2) * 8 + 8) + 7 * 5 + 9 + 2 * 2
|
||||
8 + (8 * 4 + 6 * (7 * 7 + 3 * 4 * 7 + 2))
|
||||
3 + (7 * (4 * 8 * 8 + 3 * 9) + 2 * 9) + 6
|
||||
8 * (6 * 9) * 7 + (9 + 2 * 9 * 7) * (3 + 7)
|
||||
((6 + 7 + 4 + 8) * 5 * 7 + 3 + (8 * 2 * 5 + 9)) + 5 * 2 * 9 * 4
|
||||
3 * (7 * 7 + 6) * 3 * (5 * (7 * 2 + 6 * 9 + 9) + 3 + 6 * 9 * (2 * 3 * 6 * 9)) * 6 * 5
|
||||
(2 * (9 + 4 + 4 + 5 + 5) * (6 * 7 * 4 * 9) * (9 + 4 + 8 * 4) * 3) * (9 + 3 + 3 * 3 * 4 * 2) * 5 + 2 + 5 + 3
|
||||
(7 * 8) + (8 * (3 * 8 + 4)) + 3 * 7 * 7 * 6
|
||||
2 * 6 * (6 * 3 * (2 + 8 * 5 * 3 + 3 + 4)) * 5 + (9 + 9 + 2 + 3 * 3)
|
||||
5 + 7 + 4 * 2
|
||||
4 * 3 + 7 + 9 + (5 * 2 + (5 * 6) + 3 + 4) + 6
|
||||
8 * 4 * (9 + 3 + (7 * 8 + 7 * 6 + 4 * 3)) * (6 + 9 + 9 * (3 * 7 * 9 + 2 + 2 + 2) * 6 + 4) + 8
|
||||
(5 + 9 + (8 + 7 + 6) + 8) + 6 + 2
|
||||
2 * (9 + 3 + 4 + (5 + 5 + 2 * 2 + 3 + 8) + 9) * 6 * 7 * 2
|
||||
5 * (6 * 7 + 2) * 9 + 7 + 4 + 3
|
||||
9 + ((4 * 4 + 3 + 8 * 6 * 7) * (8 * 4 + 9 * 4 + 8) + 6 + (9 * 3 + 5 + 7 + 9 + 3))
|
||||
6 * (3 + 8 * (5 * 7 + 5 + 8)) * 5 * 4 + 8 * 3
|
||||
7 * (3 * (7 * 4 * 8) + 4 + 3 * (2 * 3)) * 4 + (7 + 6) * 9
|
||||
(3 + (5 + 4 + 3 * 3 * 2 + 9) + 7 + 2) + 6
|
||||
3 * (5 + (3 + 3 + 4 * 5 * 8 * 9) + 9)
|
||||
4 * (6 + 4) + (8 * 4 * (8 + 8 * 7 * 8 * 4) * 8) * 7
|
||||
(9 * (4 * 5 + 9 * 6 * 7 + 4) + 4 * 3) * 5 + 7 + 7 + 9
|
||||
5 * (7 * 8 * 8) + 4 + 9 + (4 * (3 * 5 * 6 * 7) + 4 * 8 * 4 * 3) + 2
|
||||
4 * 6 + 8 * ((3 + 4 * 3) + 6 + 3 + 2 * 5)
|
||||
6 * (2 + 4 * (7 * 4 * 4 + 4 + 6) * 4) + ((9 + 7 * 6 * 7) * 8) * 7 * 3 * 9
|
||||
3 + (3 + 2 * 7 * 6) * (5 * 2 + 2 * 2) * 2 * (5 * 2 + 3) + 8
|
||||
6 * 2 * (8 * 9)
|
||||
7 * 4 + 9 * (9 * 2)
|
||||
(2 * 6) + (6 + 7 + 5 + 8 + 4)
|
||||
6 + (9 * 5 * 6 + 5 + 6 * 6)
|
||||
(5 + 9) + 2 + (5 * 7)
|
||||
7 * 7 + 4 + (4 * 3) * 8 * (4 * (3 * 3 + 6))
|
||||
7 * (8 + 5 + (3 + 7)) * (4 + 4 + 8 + (7 * 7 * 6 + 9)) + 6 * 8 + 8
|
||||
4 + (8 + (5 + 2 * 7 + 6 * 7 * 6) + 5 * 9)
|
||||
8 + (6 + 3 * 7 * 8 + 8 * 7) + 8 + 5 + 8 * 9
|
||||
7 * (7 * (3 + 3) * 6 + 9 * 7 + (2 + 3 + 6 * 8 * 6)) + 3 * (7 * 9)
|
||||
(5 * (4 + 6) * 4 * 8 + 6 * 3) + 6 + 2 + (8 * 5 + 9 * 3 + (5 + 7 * 5 + 7) + 3)
|
||||
(2 * 7 + 3) + 9 * 8 * 7
|
||||
(4 * 3 + 9 * 5 + 4 + 4) * 9 + (3 * 9 * 7 * 4) * (3 + 5 * 4 + 6 + 5) + ((7 + 6 * 7 * 4 + 5) + 2 * 7 + 8) + 8
|
||||
(7 * 4 * 4 + 7) + (6 * 9 * 7) + 5 + (3 + 5 * 9 * 4 * 9 * 2) + 4 * 7
|
||||
(4 + 2 * 2 * 8 + 5 * 3) + 4 * 5 * 3 * (4 * (2 * 3 + 2 * 8 + 2) + 4 * 9 * (6 + 3 * 7 * 3) * 5) + (7 * 8 * 9 + 3 * 9 * 4)
|
||||
8 + (3 + 3 + 2)
|
||||
6 * (3 * 6 * (3 + 5 + 8 + 5 + 5))
|
||||
(9 + 7 * 9 + (3 * 4 * 2 * 2 * 7) + 5 + 9) + 7 + (9 * (8 * 9) * 9) + 3
|
||||
(9 * 6 * 8 * 2) + (6 + (9 * 5 + 6 * 5 + 5 + 5) * (6 + 7 * 8 * 4 + 4 + 6) + 9) + 9 * 7 * 4
|
||||
4 + (3 * (3 + 4)) * 8 + 4 + 2
|
||||
((9 * 2 * 5 * 3 + 9 + 3) * (7 * 6 * 9 * 8 * 2) * 8 + 4) * 6 + 8 * 6 + 9 + (4 * 3 + 2 * 9)
|
||||
(8 + 5 + (6 * 7 * 2 * 4 * 8)) * (9 + 8 + (4 + 8 * 2 + 8 * 4) * 9 * 8 * 9) + 7 + 9 + 7
|
||||
(5 + 2 + 3 * 5) * ((9 * 8) * 8 * 2 * 6 + (9 * 4 * 7)) + (5 + 3 * (5 + 7 + 6 * 4 + 8 + 5)) + (7 + 6 * 2 + 2 * 6 * 7) + 2
|
||||
7 * 2 + 7 + 8 + (9 * 9 + 8 * 6 + 7 * 7) * (7 + 3 + 5 * 4)
|
||||
5 * (5 + 2 + 6) * 2 + (7 * 5 + 4 + (8 * 9 + 8 * 9 + 8) + 3)
|
||||
4 + (3 + (4 * 4) + 8 + 8 * 9 + 7) * (4 * 4 * 2) + 8 * 5
|
||||
6 + 4 + ((5 + 7) + (8 + 9 * 3 + 5 * 9)) + (4 + 8 + 7 * 6) * 5
|
||||
3 + ((6 + 2 + 6) * 9 + 8 + (5 + 5) * 6 * (8 + 6 + 7 + 7 + 9 * 9)) + 9
|
||||
8 * 8
|
||||
(3 + 7) * 2 + 2
|
||||
2 * ((4 * 9 + 9 + 5 * 7 * 9) + 8 * 3 + 7 * 7) + ((3 * 4 + 4 + 6 * 9 + 8) * (7 * 2 * 9 + 8 + 5) * 9 * (9 * 3 * 3) + 6)
|
||||
(4 + 6 * 5 * 7 * 7 + 6) + 9 + 8 + 8 * 3 * 8
|
||||
7 * 6 * (3 + 5 + 6 + 4 + 5 + (2 + 2 + 7)) + 6 + 3 * (4 * (3 + 4) * 9 + 3 * (7 * 4 + 3 + 6))
|
||||
9 * 5 * 7 + (5 + 2 * 4 * 4 + 9 + 6)
|
||||
(6 + 2 * 8 * 6 + (5 + 9) + 3) * 5 + 6 + 4
|
||||
6 + 8 + 5
|
||||
6 + (8 + (6 * 3 * 5) + 4 + 5 * (5 * 6 * 2) + 8) + 3 + 9 * 8 + 6
|
||||
3 + (2 + 9 + 2 * (8 + 2 * 3 * 6 * 9) * 2) * 4
|
||||
7 + 4 + (8 + 7 * (3 * 2 * 7 + 2 + 3 * 8)) + 9 * ((5 + 5) + 2)
|
||||
2 + (2 * 5 + 5 + 9 + 4) * 2 + 8 + 8
|
||||
(2 + 4) + ((9 + 4) * 3 + 7 * 6) + 9 * 6
|
||||
(9 * (7 + 5 + 8 + 8) + 8 + 5) + ((5 + 9 + 4 * 7 * 5) * 4 + 6 + 9 * 9)
|
||||
4 + 8 + ((6 + 2 + 2 * 6 * 2) + 7) * 7 + (3 + 8 + 4 + 2)
|
||||
((4 * 2 * 9 + 5 * 9) * 7) * 9 * (7 * 8 * 6 + 8 * 6 * 8)
|
||||
(4 * (8 * 5 * 5)) + 5 + 6 * 2 + (2 + 9 + 7 + 6) * 5
|
||||
(6 + 2) + 5
|
||||
2 * (3 * 4) * 4 + 6
|
||||
2 * 8 * (6 * (7 * 4 * 9) + (2 + 2) * 2 * (6 * 2 + 9)) * (7 * (2 * 5 + 3 * 8 * 4) * (3 + 7) + 6 + 2 * 5)
|
||||
3 * 7 + (4 * 3 + 5 + 9 + 2)
|
||||
6 * 5 * 3 + 3 * 7 * ((3 * 4 * 3 + 8 + 6) * 4)
|
||||
(6 * 6 + 4 + 5 * 5) * 7
|
||||
((6 + 8 + 4 + 5 + 9) * 3 + 4 * 5 + 4) * 5 + 9 + 9 * 9
|
||||
(9 + 4 * 5 * 5 + (3 * 3 + 5)) * 5 * 4 * 9 + (4 + 5 * 9)
|
||||
2 + (9 + 5)
|
||||
8 * (8 + 3 * 9 + 7)
|
||||
(9 + (4 + 2 * 4 * 6 + 7 * 2)) + 5 * (5 * (3 * 7 + 3 * 8 * 8 * 8) * 9)
|
||||
3 * ((4 + 3 * 8 + 5) * 9) * (6 * 5 + (2 + 5 + 4 + 3 + 8 + 2))
|
||||
6 + (3 * 3 * 5 + 9 * 8 + 8) * 7 + 9
|
||||
(5 * 8) * 2 * ((3 * 5 + 6 * 9 * 3 * 8) + 8 + 4 + 2 + 2)
|
||||
(6 + 4 * 6 * 6) * (3 * 6) * 8
|
||||
((7 * 8 + 6 * 8 + 2) + 5 * 6) + 5 * 7 * 6 + 6
|
||||
4 + 8 * 9 * (2 * 5 * 8 + 9 * (5 * 8 + 9 * 4 + 6 + 4)) + 2
|
||||
9 * (7 * 7 * 7 * 8 * 5) + 8 + 4
|
||||
4 * 9
|
||||
(9 * (7 * 7 * 7 * 9)) + 6 * 7 + 4 * 8
|
||||
7 + (5 * 9 + (9 + 8 + 5)) + 4 * 7 + 8 * 5
|
||||
6 * 2 + (7 * 9) * 6
|
||||
(5 * 4) * (4 + 8)
|
||||
9 * 4 + 6 * 5 * 6 + ((8 + 9 + 8) * 8 + 6 + (4 * 2 * 2 + 3 * 6))
|
||||
7 + (7 * 2 * 4 + 2 * 5 * 4) * 7 * (9 * 4 * 2 * 7 + 9) + 8
|
||||
(6 + 2) + (5 * 8 + 8 + 4)
|
||||
(8 + (8 + 8 + 3) * 6 + (6 * 9 * 4 + 7) + 2) + 8 * 8 + 4 + ((7 + 4 + 5 + 8 + 9) + 6 + 7 + 9 + 6) + 3
|
||||
((7 + 6 + 3) * 4 + 2 + 5 + 8) * 4 * 2 * 2
|
||||
((4 + 6 + 3 + 2 + 2) + 3 * (7 * 6 + 9 * 5 + 6 * 4) * 3) * 3 * (5 + 4 + 3 * 9) * (9 + 3 + 2 + 5 * 7 + 5) + (4 * 2 + 6) + 4
|
||||
4 + 4 + ((2 * 4 + 9 * 8 * 5 + 8) * 9 * 9 * 6 + 9) + (6 + (5 + 9))
|
||||
3 + 8 * (3 + 8 * (3 * 7 * 4 * 2) + (6 * 9 * 8))
|
||||
2 + 5 + ((5 + 4) * (2 + 4) * 9 + 6) + 5 * 9
|
||||
7 + 7 + 6
|
||||
8 + (7 + 8 + 7 + 7 * (8 + 8 + 9 * 2 + 8 + 2) + (3 * 6 + 3 * 2))
|
||||
4 * 9 + (4 * (7 + 7 + 7 + 8 + 5 + 2) + 4 * 6 + 2 + 6)
|
||||
(4 * 9 * 7 + 8 + 3 + 9) + 8 + (5 * 9 + 9 + 3 + 3 + 4) * 9 * 8
|
||||
(5 + 5 * 6) * (6 + 8 + 7) + (5 + 2 + 5 * 5 * (3 + 7 + 6 * 9)) + 9
|
||||
4 * 2 + (4 + 5 + (3 + 5 + 9) + 7 + 7 + 4) + 3 + (6 * (2 + 2 + 8 * 8) + (8 + 9 * 7 + 7 + 6 * 9) + (3 * 9 * 3 * 5 + 5) * 5) * 3
|
||||
7 + 2 + (4 * 3) * 7 + (2 * 3 + 7 * 9)
|
||||
5 * 9 * 2 * (5 * 2) + 5
|
||||
4 + 4 * 6 + (2 + 5 + 6 + 8 * 7)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue