From 20d47b00486651399e588a9e1c71bb091e4a9d29 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 13 Dec 2019 22:17:27 +0100 Subject: [PATCH 001/129] 2019: d13: ex1: add solution --- 2019/d13/ex1/ex1.py | 213 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100755 2019/d13/ex1/ex1.py diff --git a/2019/d13/ex1/ex1.py b/2019/d13/ex1/ex1.py new file mode 100755 index 0000000..1bf7e8c --- /dev/null +++ b/2019/d13/ex1/ex1.py @@ -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() From 94dffe573c9673a28cfea4dcf4ca9955c4ec1c33 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 13 Dec 2019 22:36:41 +0100 Subject: [PATCH 002/129] 2019: d13: ex2: add input --- 2019/d13/ex2/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d13/ex2/input diff --git a/2019/d13/ex2/input b/2019/d13/ex2/input new file mode 100644 index 0000000..98d5ab4 --- /dev/null +++ b/2019/d13/ex2/input @@ -0,0 +1 @@ +1,380,379,385,1008,2663,704183,381,1005,381,12,99,109,2664,1102,1,0,383,1102,0,1,382,20102,1,382,1,21001,383,0,2,21102,37,1,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,44,381,1005,381,22,1001,383,1,383,1007,383,23,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1105,1,161,107,1,392,381,1006,381,161,1102,-1,1,384,1105,1,119,1007,392,42,381,1006,381,161,1101,0,1,384,20102,1,392,1,21102,21,1,2,21102,1,0,3,21102,138,1,0,1105,1,549,1,392,384,392,20101,0,392,1,21102,21,1,2,21101,3,0,3,21101,0,161,0,1106,0,549,1101,0,0,384,20001,388,390,1,21002,389,1,2,21102,180,1,0,1106,0,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,20102,1,389,2,21101,0,205,0,1105,1,393,1002,390,-1,390,1102,1,1,384,21001,388,0,1,20001,389,391,2,21102,1,228,0,1106,0,578,1206,1,261,1208,1,2,381,1006,381,253,20102,1,388,1,20001,389,391,2,21101,253,0,0,1105,1,393,1002,391,-1,391,1101,1,0,384,1005,384,161,20001,388,390,1,20001,389,391,2,21101,0,279,0,1105,1,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1106,0,393,1002,390,-1,390,1002,391,-1,391,1101,0,1,384,1005,384,161,20102,1,388,1,21002,389,1,2,21102,0,1,3,21101,0,338,0,1106,0,549,1,388,390,388,1,389,391,389,21002,388,1,1,21001,389,0,2,21102,1,4,3,21102,365,1,0,1105,1,549,1007,389,22,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,414,20,18,1,1,22,109,3,22102,1,-2,1,21202,-1,1,2,21102,1,0,3,21101,0,414,0,1106,0,549,21201,-2,0,1,21202,-1,1,2,21101,429,0,0,1105,1,601,1201,1,0,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2106,0,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,22102,1,-3,-7,109,-8,2106,0,0,109,4,1202,-2,44,566,201,-3,566,566,101,639,566,566,2101,0,-1,0,204,-3,204,-2,204,-1,109,-4,2105,1,0,109,3,1202,-1,44,594,201,-2,594,594,101,639,594,594,20101,0,0,-2,109,-3,2106,0,0,109,3,22102,23,-2,1,22201,1,-1,1,21102,509,1,2,21102,150,1,3,21101,1012,0,4,21102,630,1,0,1106,0,456,21201,1,1651,-2,109,-3,2105,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,0,2,0,2,2,2,2,2,0,2,2,2,2,2,2,0,2,0,2,2,2,0,2,0,0,2,2,2,0,2,2,2,2,0,2,0,0,2,0,1,1,0,2,0,2,0,2,2,2,2,0,0,2,2,2,2,0,2,2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,2,0,2,2,0,2,0,2,2,0,0,2,2,2,2,2,0,2,2,0,2,2,0,2,2,2,2,0,2,2,0,2,0,2,2,2,2,0,0,0,1,1,0,2,0,2,2,2,0,2,2,2,2,2,2,0,2,0,2,2,2,0,0,2,2,2,2,2,0,2,0,2,0,2,0,2,0,2,2,2,0,0,2,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,34,29,24,40,90,52,13,48,86,82,86,77,3,16,27,97,89,38,11,82,76,15,50,46,33,57,17,38,39,91,43,86,43,55,15,24,23,74,5,53,20,10,16,77,73,84,85,36,89,77,79,82,37,7,24,68,14,78,75,7,86,80,18,84,68,62,89,7,64,11,9,56,62,3,29,95,41,23,18,90,1,10,4,94,8,69,57,13,72,89,61,72,61,17,54,88,96,53,73,21,92,16,52,18,26,89,32,2,50,8,3,5,36,26,64,75,51,55,49,45,78,49,27,55,2,29,37,77,69,3,21,69,6,18,59,91,57,92,6,26,58,40,26,54,33,40,96,45,89,23,53,94,61,44,32,33,41,12,31,67,17,96,34,72,72,49,90,21,1,40,75,97,56,57,77,20,21,68,14,4,7,9,41,88,32,40,79,77,17,48,70,56,50,67,36,16,98,98,65,98,53,7,36,47,27,15,77,80,83,39,8,22,61,11,9,10,54,16,65,54,82,60,66,21,92,51,70,17,53,22,39,89,92,29,12,60,37,42,75,65,1,61,90,86,46,62,81,2,64,64,21,43,17,46,57,72,25,63,51,30,22,65,81,54,85,45,93,24,23,23,27,37,94,11,15,93,78,75,11,41,56,42,89,20,73,23,27,98,89,29,68,73,89,75,80,31,90,36,62,44,65,18,97,24,22,84,30,56,41,44,67,63,71,85,76,66,64,51,58,98,30,66,4,90,38,8,49,49,62,55,53,5,74,18,93,4,34,48,86,17,37,35,28,45,38,76,95,67,21,67,6,36,38,1,16,5,8,89,9,37,32,78,90,46,92,61,3,96,40,91,31,98,35,90,96,44,43,55,39,51,64,51,39,12,90,58,69,58,39,13,49,60,35,40,56,56,74,47,54,23,8,54,59,97,12,8,62,21,66,59,96,61,54,12,98,28,85,95,2,4,14,89,78,4,16,66,48,37,43,17,59,77,20,63,28,87,10,20,58,46,55,26,94,3,71,5,13,90,67,68,55,93,38,16,28,45,47,41,88,98,90,95,44,33,89,54,24,33,38,94,79,32,15,62,26,52,39,8,22,38,79,3,60,75,55,91,53,36,59,86,1,98,25,87,84,47,83,40,74,22,91,86,73,73,6,15,72,90,43,87,97,63,24,77,20,76,10,96,65,27,69,87,93,17,34,5,52,31,24,46,4,26,3,34,87,96,68,16,82,85,67,65,11,57,71,49,62,77,5,68,20,51,26,40,67,69,32,82,46,57,15,31,81,38,74,98,3,77,78,36,10,55,76,48,90,2,8,21,29,17,66,51,91,59,36,8,2,85,50,53,76,38,91,24,54,6,6,28,20,25,7,56,87,44,54,98,6,10,94,44,93,25,26,65,22,87,52,47,36,1,22,21,32,49,7,72,66,89,92,63,85,90,82,79,33,36,39,69,15,57,80,46,39,28,79,73,43,95,81,21,47,39,68,30,34,79,33,72,14,54,96,52,60,16,9,73,54,78,77,26,89,14,14,28,83,47,81,87,14,86,11,96,29,10,2,84,1,70,59,81,64,29,25,40,53,87,4,42,76,80,48,39,85,60,96,95,78,30,8,83,46,62,68,82,40,15,43,51,81,65,64,3,81,13,48,70,97,95,6,23,91,66,63,22,70,28,10,42,90,91,80,34,29,48,18,96,78,14,17,88,13,96,72,72,86,45,95,59,20,67,65,35,89,46,76,35,7,35,4,64,58,15,98,39,81,2,95,10,75,56,85,22,31,22,14,9,12,48,15,75,91,85,91,26,40,78,23,76,5,45,6,79,58,4,70,7,10,79,56,98,86,34,18,73,57,70,97,72,59,75,36,30,21,41,38,83,93,64,92,89,17,65,19,93,9,83,51,3,20,71,89,37,70,3,90,13,35,95,43,14,78,3,43,15,11,21,36,50,12,27,47,58,18,8,66,23,32,7,88,82,27,21,23,5,80,79,44,87,19,11,47,15,14,18,14,95,54,81,76,93,51,53,63,97,39,11,30,26,89,6,29,15,21,49,57,53,52,93,83,11,95,28,58,79,22,65,58,93,89,60,49,78,55,22,42,25,14,61,66,28,84,43,4,68,54,68,17,46,13,88,30,39,40,35,35,14,69,34,55,93,43,7,20,82,83,50,25,50,26,78,17,93,7,10,24,3,27,85,97,88,62,65,11,66,36,38,14,32,31,94,14,3,38,39,96,23,64,89,91,37,9,5,44,4,18,43,64,53,58,96,84,67,96,24,86,49,30,49,24,4,46,57,704183 From 3a1984671774aa870f82a332302fe8ab597c8455 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 13 Dec 2019 22:36:47 +0100 Subject: [PATCH 003/129] 2019: d13: ex2: add solution --- 2019/d13/ex2/ex2.py | 249 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100755 2019/d13/ex2/ex2.py diff --git a/2019/d13/ex2/ex2.py b/2019/d13/ex2/ex2.py new file mode 100755 index 0000000..9fb669f --- /dev/null +++ b/2019/d13/ex2/ex2.py @@ -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() From 030f45af6c27a6b8777fdbc7945f6387e144822c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 14 Dec 2019 17:35:40 +0100 Subject: [PATCH 004/129] 2019: d14: ex1: add input --- 2019/d14/ex1/input | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 2019/d14/ex1/input diff --git a/2019/d14/ex1/input b/2019/d14/ex1/input new file mode 100644 index 0000000..7e55064 --- /dev/null +++ b/2019/d14/ex1/input @@ -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 From 213575d822a2d5226ccf8e090311ff7e2790064d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 14 Dec 2019 17:35:44 +0100 Subject: [PATCH 005/129] 2019: d14: ex1: add solution --- 2019/d14/ex1/ex1.py | 89 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 2019/d14/ex1/ex1.py diff --git a/2019/d14/ex1/ex1.py b/2019/d14/ex1/ex1.py new file mode 100755 index 0000000..66144b2 --- /dev/null +++ b/2019/d14/ex1/ex1.py @@ -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() From 2b15ae755251b397f11553cd7623cc69b25c16b4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 14 Dec 2019 17:46:10 +0100 Subject: [PATCH 006/129] 2019: d14: ex2: add input --- 2019/d14/ex2/input | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 2019/d14/ex2/input diff --git a/2019/d14/ex2/input b/2019/d14/ex2/input new file mode 100644 index 0000000..7e55064 --- /dev/null +++ b/2019/d14/ex2/input @@ -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 From d3445b2ef11f86d946a7fbeb7e8c4580b2d98faf Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 14 Dec 2019 17:46:19 +0100 Subject: [PATCH 007/129] 2019: d14: ex2: add solution --- 2019/d14/ex2/ex2.py | 106 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 2019/d14/ex2/ex2.py diff --git a/2019/d14/ex2/ex2.py b/2019/d14/ex2/ex2.py new file mode 100755 index 0000000..177ed1c --- /dev/null +++ b/2019/d14/ex2/ex2.py @@ -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() From ed9ba2c14a55508ea734c87dae5d93c9252768cb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 15 Dec 2019 14:10:42 +0100 Subject: [PATCH 008/129] 2019: d15: ex1: add input --- 2019/d15/ex1/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d15/ex1/input diff --git a/2019/d15/ex1/input b/2019/d15/ex1/input new file mode 100644 index 0000000..7dbcaac --- /dev/null +++ b/2019/d15/ex1/input @@ -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 From 1b8f5bc5e0df34563d61b45fdacd1126e4bdbf23 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 15 Dec 2019 14:10:54 +0100 Subject: [PATCH 009/129] 2019: d15: ex1: add solution --- 2019/d15/ex1/ex1.py | 315 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) create mode 100755 2019/d15/ex1/ex1.py diff --git a/2019/d15/ex1/ex1.py b/2019/d15/ex1/ex1.py new file mode 100755 index 0000000..59b99ad --- /dev/null +++ b/2019/d15/ex1/ex1.py @@ -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() From ac39fe2abb3c7f0b5c8a8a64cfaf4d6cb17e6615 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 15 Dec 2019 14:13:59 +0100 Subject: [PATCH 010/129] 2019: d15: ex2: add input --- 2019/d15/ex2/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d15/ex2/input diff --git a/2019/d15/ex2/input b/2019/d15/ex2/input new file mode 100644 index 0000000..7dbcaac --- /dev/null +++ b/2019/d15/ex2/input @@ -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 From 3fc73336a4bc7a7a0d89fbbd401bd0b9832e963d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 15 Dec 2019 14:14:05 +0100 Subject: [PATCH 011/129] 2019: d15: ex2: add solution --- 2019/d15/ex2/ex2.py | 318 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100755 2019/d15/ex2/ex2.py diff --git a/2019/d15/ex2/ex2.py b/2019/d15/ex2/ex2.py new file mode 100755 index 0000000..ee99d3b --- /dev/null +++ b/2019/d15/ex2/ex2.py @@ -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() From e4699300b03fbae2b693a1afa7240409a016d76c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 16 Dec 2019 11:37:41 +0100 Subject: [PATCH 012/129] 2019: d16: ex1: add input --- 2019/d16/ex1/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d16/ex1/input diff --git a/2019/d16/ex1/input b/2019/d16/ex1/input new file mode 100644 index 0000000..c2f8a5f --- /dev/null +++ b/2019/d16/ex1/input @@ -0,0 +1 @@ +59793513516782374825915243993822865203688298721919339628274587775705006728427921751430533510981343323758576985437451867752936052153192753660463974146842169169504066730474876587016668826124639010922391218906707376662919204980583671961374243713362170277231101686574078221791965458164785925384486127508173239563372833776841606271237694768938831709136453354321708319835083666223956618272981294631469954624760620412170069396383335680428214399523030064601263676270903213996956414287336234682903859823675958155009987384202594409175930384736760416642456784909043049471828143167853096088824339425988907292558707480725410676823614387254696304038713756368483311 From 78954b23e55fe8b4ad6516ea09976bc7b2255a2d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 16 Dec 2019 11:37:47 +0100 Subject: [PATCH 013/129] 2019: d16: ex1: add solution --- 2019/d16/ex1/ex1.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 2019/d16/ex1/ex1.py diff --git a/2019/d16/ex1/ex1.py b/2019/d16/ex1/ex1.py new file mode 100755 index 0000000..0d8d731 --- /dev/null +++ b/2019/d16/ex1/ex1.py @@ -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() From c1c5abc0a40b4c20497e8b6ba66c045e86bb03f5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 16 Dec 2019 14:34:17 +0100 Subject: [PATCH 014/129] 2019: d16: ex2: add input --- 2019/d16/ex2/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d16/ex2/input diff --git a/2019/d16/ex2/input b/2019/d16/ex2/input new file mode 100644 index 0000000..c2f8a5f --- /dev/null +++ b/2019/d16/ex2/input @@ -0,0 +1 @@ +59793513516782374825915243993822865203688298721919339628274587775705006728427921751430533510981343323758576985437451867752936052153192753660463974146842169169504066730474876587016668826124639010922391218906707376662919204980583671961374243713362170277231101686574078221791965458164785925384486127508173239563372833776841606271237694768938831709136453354321708319835083666223956618272981294631469954624760620412170069396383335680428214399523030064601263676270903213996956414287336234682903859823675958155009987384202594409175930384736760416642456784909043049471828143167853096088824339425988907292558707480725410676823614387254696304038713756368483311 From 704cf451cbac9738e187bfb91abe244a56c46059 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 16 Dec 2019 14:34:26 +0100 Subject: [PATCH 015/129] 2019: d16: ex2: add solution --- 2019/d16/ex2/ex2.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 2019/d16/ex2/ex2.py diff --git a/2019/d16/ex2/ex2.py b/2019/d16/ex2/ex2.py new file mode 100755 index 0000000..a13a0bf --- /dev/null +++ b/2019/d16/ex2/ex2.py @@ -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() From 035b8b5a0faafe64b7a91e8418dc1cd7123f4f84 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 17 Dec 2019 11:04:34 +0100 Subject: [PATCH 016/129] 2019: d17: ex1: add input --- 2019/d17/ex1/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d17/ex1/input diff --git a/2019/d17/ex1/input b/2019/d17/ex1/input new file mode 100644 index 0000000..75af154 --- /dev/null +++ b/2019/d17/ex1/input @@ -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 From ffe7fa42d5df7eb39d5bbd50ff080e4f2d21ff9f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 17 Dec 2019 11:04:40 +0100 Subject: [PATCH 017/129] 2019: d17: ex1: add solution --- 2019/d17/ex1/ex1.py | 223 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100755 2019/d17/ex1/ex1.py diff --git a/2019/d17/ex1/ex1.py b/2019/d17/ex1/ex1.py new file mode 100755 index 0000000..838d696 --- /dev/null +++ b/2019/d17/ex1/ex1.py @@ -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() From 254093a24d22ceecd27fadd84ada2d4c4965c2a7 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 17 Dec 2019 13:40:40 +0100 Subject: [PATCH 018/129] 2019: d17: ex2: add input --- 2019/d17/ex2/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d17/ex2/input diff --git a/2019/d17/ex2/input b/2019/d17/ex2/input new file mode 100644 index 0000000..75af154 --- /dev/null +++ b/2019/d17/ex2/input @@ -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 From 07223f9d30bb38cc830956622d994d39a801eee0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 17 Dec 2019 13:40:47 +0100 Subject: [PATCH 019/129] 2019: d17: ex2: add solution --- 2019/d17/ex2/ex2.py | 350 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 350 insertions(+) create mode 100755 2019/d17/ex2/ex2.py diff --git a/2019/d17/ex2/ex2.py b/2019/d17/ex2/ex2.py new file mode 100755 index 0000000..62d5dd0 --- /dev/null +++ b/2019/d17/ex2/ex2.py @@ -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() From dad9912dd245902e25024188b27dc73a9a870079 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 1 Dec 2020 16:36:34 +0100 Subject: [PATCH 020/129] 2020: d01: ex1: add input --- 2020/d01/ex1/input | 200 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 2020/d01/ex1/input diff --git a/2020/d01/ex1/input b/2020/d01/ex1/input new file mode 100644 index 0000000..45d090d --- /dev/null +++ b/2020/d01/ex1/input @@ -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 From 82f57ddea53b3851f22820c417db5db3b1c61de3 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 1 Dec 2020 16:36:39 +0100 Subject: [PATCH 021/129] 2020: d01: ex1: add solution --- 2020/d01/ex1/ex1.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 2020/d01/ex1/ex1.py diff --git a/2020/d01/ex1/ex1.py b/2020/d01/ex1/ex1.py new file mode 100755 index 0000000..50358b7 --- /dev/null +++ b/2020/d01/ex1/ex1.py @@ -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() From 30a7a7da33bab0af0544d00be7b90a6ca8e6c995 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 1 Dec 2020 16:36:50 +0100 Subject: [PATCH 022/129] 2020: d01: ex2: add input --- 2020/d01/ex2/input | 200 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 2020/d01/ex2/input diff --git a/2020/d01/ex2/input b/2020/d01/ex2/input new file mode 100644 index 0000000..45d090d --- /dev/null +++ b/2020/d01/ex2/input @@ -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 From 6d30ed5992a19cf3fc57416348366fdf3cffeb78 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 1 Dec 2020 16:36:56 +0100 Subject: [PATCH 023/129] 2020: d01: ex2: add solution --- 2020/d01/ex2/ex2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 2020/d01/ex2/ex2.py diff --git a/2020/d01/ex2/ex2.py b/2020/d01/ex2/ex2.py new file mode 100755 index 0000000..0dac64e --- /dev/null +++ b/2020/d01/ex2/ex2.py @@ -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() From 17a428630769f96022cd4a2508b9b53bcfa179cc Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 11:20:04 +0100 Subject: [PATCH 024/129] 2020: d02: ex1: add input --- 2020/d02/ex1/input | 1000 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1000 insertions(+) create mode 100644 2020/d02/ex1/input diff --git a/2020/d02/ex1/input b/2020/d02/ex1/input new file mode 100644 index 0000000..0f3ccea --- /dev/null +++ b/2020/d02/ex1/input @@ -0,0 +1,1000 @@ +7-9 l: vslmtglbc +2-3 s: hpbs +1-3 v: pvvr +2-8 h: hhhhvhhh +9-10 x: xxxxxxxxzv +2-5 q: xdqbjj +17-19 n: nnnnnnnnnnnnnnnnrnsn +5-7 f: fxfkffffff +4-7 h: hrjhxlhh +11-12 v: vvvwdvvvvvvvvv +6-7 q: tqqqqvqqq +2-4 b: vlmndngvbkptbb +1-4 t: mttwt +3-4 v: vmgdcj +4-17 n: nwnnnnnnwqncnxxnn +3-4 c: gscc +3-4 w: wwwwww +8-12 j: jdjjtjxjjjjj +1-5 b: bmbfbbb +5-11 k: kkkkkkdkkkkk +1-4 m: mmmm +5-6 z: zzzzhzzz +8-10 z: zmqzzzzgzlzdz +14-15 r: rrrrrrrrrrrrvnr +11-13 q: qqqqqqqpqvpqwq +3-7 q: qnqhqcqq +11-17 r: vrrrrrrjrrrrrrrrrrrr +2-5 g: srqmltncfgdg +7-11 w: wwwwwwtwwwqj +5-14 j: hhwjmjzmjjxjjkjgjj +11-14 x: xffrxxxxxxzxrxxmxqlw +14-16 c: hqcchcjwrxbcgclctx +10-14 k: kkvkkdbqnqkkbfftxm +10-12 c: cccccccccccc +7-13 x: dbjtkxxfjsvvx +9-11 d: ddddddddxdb +4-8 h: mhbhrsvtl +8-13 h: hbhrhjhhjhhqpthxnwhh +10-11 s: sssksssrsssss +6-8 m: mmfmmmmm +4-14 h: bhhnhvhhhhhhlvhmqkh +1-17 c: cccccccccccccccccc +10-11 r: rsrprprrrnr +10-13 d: dddddddddhdddd +5-7 s: msfscsndswsl +3-8 b: bbzzbhbwb +9-20 b: cbbcrbwjfrddqbvzrfxb +9-15 h: shpdthhhhhshhhhh +5-6 n: nnnnnn +1-7 f: dfffffffff +10-11 f: fffffffffvf +3-4 z: xmkkvcrqdz +15-19 h: hhghhhhhhhmhhhhhhhh +4-7 m: lmxkhmmm +3-4 l: zlllkfzcldctlmhq +2-5 j: jxjjqj +10-11 s: sssssssjsgw +2-4 j: vjkjp +9-18 l: lffnlbmrmrvlkrpchj +3-6 q: qqhqqdqq +18-19 d: ddddddddddddddddddd +1-8 m: mmsmzwbchmmlmljslkk +2-6 m: tmbtmmgmmwm +2-8 j: jrjjjjjp +8-12 d: ddddxdbtvdnbdk +8-13 t: tttttttxttrtr +8-13 w: wwwwjgwzdxwwp +3-14 j: jjkjjjrjjcjqjjj +3-4 q: qgpx +6-9 p: ppppppppp +6-8 f: fdffffff +5-10 x: xsmxxxxkxxhtxxmx +1-4 j: dzrhcjljjv +13-14 s: sdxcbwfsprkpss +9-13 n: nnnnnnnnnnnnnn +3-7 r: rrrcrkrrrrm +4-11 f: fmfrfgphxqf +4-13 t: tttrtptttzgttwj +10-12 w: wwwwwwwwwfhh +10-11 q: qvqqqqqjqptqq +8-10 s: sssssxsssv +12-15 c: dsmccckcccbccwcccdc +5-7 l: nllffcmrwkdhw +8-10 t: tttzttvttgtqt +7-8 m: mmmbmmjmm +7-9 c: ckccqmmcccjckdc +3-4 w: twwwd +11-13 g: ghgpggggwggclgfggtzm +10-11 m: lvwmmmmmbfmm +9-12 g: gggggnggtgdgg +5-7 k: kkkkkkk +11-13 g: ghgggggggbrgzgg +3-7 z: zzzzzgzz +7-10 z: zzzzzmszzdzzz +15-20 w: wwwwwlwwwwwwwwwwwwwc +7-9 z: zzzzzzzzz +1-8 q: qqnhbczhtzg +11-14 s: sgcssssvsssvsslvss +2-4 w: mcztwwt +3-7 w: wtwtdwpb +5-8 r: rrrrrrrsr +7-8 v: vnvvvvvv +7-8 j: jjjjjglwj +5-6 w: ktkvwwgqbxgckq +7-9 f: ffffzfffff +12-14 n: nnnnnnnnnnnnngn +3-5 z: zzzzdz +5-11 j: xmjjtjjbjngk +3-5 l: llvldllllvl +7-8 h: hhhhhhhnhh +17-18 p: ptpppppppppppppprq +2-6 s: sssdnlgqjxcvssh +3-6 h: dhhthhhhch +6-18 k: khkkkkzkmkkkvttkkkkk +3-4 x: dxsxxx +4-11 b: bbbbbpbbbbb +5-7 t: ttzthtx +3-6 k: kkrkkxkkhkkk +2-7 b: mbzbjfnb +9-12 l: fglllllllllkl +11-14 l: plctdxwbmnbqnczwvjlv +2-10 f: jfdtpsntnf +18-19 d: dddddddpddddddddddd +4-6 h: gkhbkhhhkhppb +7-9 f: ffqvffffffnfr +3-4 l: llzl +2-12 d: dccfdbdddddndd +12-17 b: bbbbbbbbbbbbbbbbbbbb +2-3 k: bkkp +5-9 h: hlhhjhhhl +4-12 f: ffffrffffffffffflffz +1-5 v: vvvvvwvv +8-9 l: lllllllgb +15-18 t: ttttttttntttltvtts +6-7 q: zqpqcgbqqq +5-11 w: lgrktkmkqzjvwg +8-9 p: ppppppppp +3-4 c: cccc +7-15 b: bqbxzbbbdtbbbmbb +9-11 k: kkkkkkvkdkktk +4-6 t: bktttttt +6-10 m: bwtpbsmmnmmlmfd +5-12 z: zzckszrdzzpmzzzzk +4-5 q: qqqck +3-6 k: kkwpsbbqkntgz +1-6 k: kkkkkk +1-7 f: fffzffffffffffjq +3-4 p: jqpxgn +7-13 v: wvhzbmvvvvvvgvvv +3-5 p: ppvdfgr +16-18 c: ccccqcccwccgcbctsk +5-8 p: ppgpgpjgpzqpw +1-3 t: tspmnttttfm +2-9 b: bmbbbhbbxbb +2-7 n: dnnngnnnmnnnnckn +12-14 c: cccccccccbccrm +12-14 q: qqqqqqqqqhnmlpqqqq +2-3 n: whnnmf +13-15 h: hhhhhhhhhhhhchp +4-5 k: kkcmw +6-7 z: wfqwfkhdvd +3-4 h: bqnhhhncph +3-4 j: kjgkj +16-17 s: ssssssssssssssfqx +4-6 r: rrzbpw +2-3 m: vzmmmm +17-19 z: zzzxzzzzzzzzzzzzfzz +7-12 s: nmpsssdhszssssssnhs +4-5 l: lfqlcl +3-5 d: fdtdb +6-9 b: mlbbjhbbbbbbl +1-5 g: gggggg +4-7 x: xxbxxhxxkxsx +3-6 j: kspjgjzxfpdclkrzk +2-7 s: ffwpjssskscsv +4-5 n: nnndf +5-15 g: gtljgmrlggmghbv +13-16 v: vvvvjvqbvvvvvvvhvvs +6-9 b: dldbmbsmb +5-7 f: sfvffffft +1-3 b: ztblbcxnrmkvnfvz +10-12 r: dljvqxnjttjvtfrcxgh +14-16 w: hgwslvnzbhhxwwvwprww +6-8 s: vssnsssgptshmkst +6-8 s: scssssshs +6-12 g: gggggfgggtnhm +6-10 j: hlcjjlfpljpwjjrvpl +2-8 m: zbbmxlzlrckhrcmksf +1-7 v: vvvnmvl +3-4 x: fxpt +3-12 h: hhhhhhhhqhhhh +8-9 t: tttttttftt +12-18 r: rrrrrrrrrrrrvrrrrdr +10-14 d: dbdddddddvddddd +15-17 r: dvrhrrrrbnrrprrrrrr +7-11 v: fvjgvgvvvsvz +5-6 m: dsmjmm +7-12 k: kkkkkkknkkpkkz +4-7 h: fhdhmhmvwfsh +8-9 f: ffffffffgf +2-4 h: hhhk +5-9 r: mdrcwmllvgnjfzfcwztt +8-9 g: gggggggnjggg +11-16 v: vlgfvvnvvvvvvvvv +12-16 t: tttttttwtttptttk +4-6 w: jfvkvwx +12-17 w: phmrqwdwwqwwwwbwzbwr +16-17 m: mmrmmmmmmmmmmmmdm +9-10 z: jzhzzzzzzzz +11-14 x: xxxxxxxjxxxcxm +11-12 b: bbbbbbbbrbgq +3-5 j: sxjjmxjrztjjldkpbcq +10-16 l: lhlldlldljlllmlm +2-10 t: szsnwnkttt +7-9 q: ppxcslxzj +14-15 c: ccczcccccccccnm +2-9 l: dllppswblllkltl +1-7 z: kcklcmt +8-9 p: ppppppfhjp +4-8 f: ffjkkffl +5-11 g: hgxgggcgjglbgzcdzg +2-4 d: ccdq +11-14 r: rvrtrrrrrtrnrqrrr +9-11 k: kkckkgkzsmkkkrwknkm +7-9 x: sgmxhhjxnpgcx +6-8 t: qhbpjtjtttttttt +7-8 q: wqqrqqqqqn +3-4 z: jzqgm +4-19 g: gdgmgjggkgpghgggggg +2-11 g: ggtgggggsgs +3-5 j: xdtjdjpjwljmd +1-5 h: hbnwh +2-4 h: hhfhhzhdqzhwchql +3-11 k: kjgjltkkmkkm +17-20 d: ddfnglddnddpqdqwdwbd +1-4 x: gxkpxx +2-3 b: zbbmkb +2-9 r: hrhphqrcr +7-10 d: dkdvddddddn +3-4 x: dsxbt +18-19 p: npnnpwpppgvxwmzpszv +14-16 v: vvgvvvvvvvvvvjvvv +1-8 h: nhthchpdnh +7-14 s: ssgssfsmrsssldgscfd +8-9 h: hhhhghhpv +4-5 g: kggslg +3-9 g: gggglngjzgg +11-13 h: hhhhhhhhhhhhhh +4-7 l: lllslgll +2-4 c: cccccnk +1-11 l: hltwqljjlzllhq +1-2 x: bkxtxx +4-5 v: vvvvg +7-8 x: xxxxxxqd +13-14 n: nwvcqqtwttfhnn +2-7 c: cccchcs +2-5 p: pbpgv +16-17 t: tttttvttttttmttlvttt +1-2 j: fbjj +2-5 n: knznnncnfnvn +11-12 l: llglllcnlfllllkllr +7-8 v: vvvvvvtr +8-9 k: kkkkvkkkp +6-7 q: tpxqqqr +5-7 s: sssnssshvxs +13-18 m: mmfmmmmmmmmwlmmmmn +7-11 p: ppppppppppp +6-7 s: bsssssds +3-7 q: qmqwqqqqqqhfp +4-5 r: tffrr +9-11 c: ccccccccccc +1-3 w: vvlhw +1-8 g: vgggggghg +5-6 p: txlxppppspkplxf +7-13 f: fffffffffffff +2-8 g: gggggsgggg +2-5 w: wbwwz +2-3 p: spsrhtmjzpmgvj +1-4 d: vbtd +4-5 g: ggggf +14-16 v: dvvfhdjcvvvmvdvnm +6-8 x: xxxxxxxxx +5-6 j: jjnjjj +13-15 m: mmpmmvmmmmszmdgkm +4-16 z: zzzzzzzzzzzzzzzq +4-10 x: xxxxxxxxxxxx +4-5 r: rrrrr +10-11 m: rmmdmmmmmmdnm +2-3 q: qqqs +7-11 m: mmmmmmmcmmmmx +2-4 x: dcfr +2-4 p: cpppgpp +1-3 n: vnqgqbhn +3-4 p: pppx +13-14 f: fffgfpfffffffqftfn +2-5 h: hsdhhhh +3-6 q: pdqvtq +6-8 l: lllllmlll +5-6 v: vvvvld +10-11 x: jxhxdchxjwx +7-8 h: hhhhhhhh +11-19 z: dtzzxcztmzzzzzzjqzzz +3-4 h: thcchhh +3-5 b: dbbwjbbnb +11-12 q: qqtgqqldkqqqqqqctqq +12-13 l: lllllllklllcxl +2-8 s: sppbsvjfp +10-20 g: xgswhgldgggdkxjggzzg +2-4 n: nnnnn +3-5 c: xmtccjj +1-7 w: wbqwwwsc +3-6 g: wgghgngg +4-6 p: pppptpppwp +1-3 j: jjjjjjjjjjjjjjjsjjjj +2-6 r: drbwrrmtjnzrfsrxwq +1-5 v: rcvvd +2-3 w: dwnzf +4-6 l: lrlbld +3-7 h: hhhhhhkhh +6-12 b: bktbzmzlbbmvmbpm +1-7 n: znfnngntfsh +2-14 z: jzzsgxsqkqmzlzhzljz +3-8 q: qmqfzhfq +8-9 d: ddzdddddd +11-14 k: gkwtwksxrdwxkkh +3-5 v: vvvvnv +6-12 s: pksrzgvspsswsxrpsvss +6-8 w: whpwhwjwwpkww +8-10 w: wdwwbbwwsw +13-19 z: zzzfzzzzzzzzwzzzzzr +3-4 v: vkbv +7-10 x: wxxxkjkxxxdfxx +1-3 g: gpgsgqgb +15-17 r: pfntnqmbtcfcsrlgprqk +7-10 s: sjdssmsssbssssl +3-16 p: ppnjzcppkpppmwvkp +3-7 r: srkrvrjrgrrrr +3-4 x: xmxx +1-5 k: zkkhqdgrt +1-13 c: rcncccdclcccc +4-7 n: nxfmnnbn +8-9 g: gngggpgfwggg +2-5 m: smmfs +1-12 p: snppbhspvzpppnwpwjpp +2-6 s: rczxxsvknqcpwklsbc +4-9 d: ddndgtdddqddddqd +10-13 f: ffffffffftfff +8-9 x: xxxxxxxxxx +4-7 r: krkrsgrfvqzxpcrrgjr +3-4 c: chdc +13-14 k: xkkkkkkkkkkkkq +4-8 t: tmmvccgxfbtttttttt +14-16 l: trkllqstdlclqzlv +1-3 x: qkxx +2-6 s: nsfhklqbnvs +4-5 g: rlggcgg +10-12 l: llzlllllllll +12-14 w: wwwwwwwwdwwtwl +3-4 m: qmvp +2-3 d: dddd +2-6 j: mwqfjdjlnb +7-9 z: zlzwzrzshd +5-8 k: jmkjkqdcwkrtvb +17-18 s: sssssgssssstssssxcds +1-3 k: qfxkt +3-11 j: tsjjvpcnsmd +12-14 v: vfvvdvvvvvvbvjvvvvvv +4-12 v: wvxmcvzlrvtv +4-8 q: qqqqqqqqqqqqq +16-17 s: sssssssssssssssvqs +3-4 d: ddwx +3-4 h: hhhh +8-9 z: znbzzzzgzzz +1-3 b: tkffshrzkxwjbrxkkv +3-8 n: nnqnnnnbnn +6-8 n: bnpnnhfnnnqndxncpgq +10-16 d: sddddlddjszdddtc +6-8 x: wwwmqxzwl +12-16 j: jjjjjmjjjjbxjjjtpv +15-18 z: zzzzzzzzdzzzczhzznf +1-18 n: nvhddhnqnnrbvpnnwn +14-17 z: lbznszzzzzzzzzzzm +7-9 l: jfqxkllcll +8-14 l: lllllllllnllllc +7-13 m: ncmkkmmhwsvhmmsk +2-5 t: ttttth +4-5 k: kgkkkk +4-9 d: ddddddddd +3-6 n: nnntnnn +9-10 h: bbjqqhhhwr +12-16 g: ggfgsjggghcfggbpjggp +2-3 x: dktxtxh +1-2 x: grnz +5-7 x: txxcgddxnwxxx +12-15 b: bbbbbbbbbbjbbbj +11-17 f: fffffrfffcfpfcffff +3-9 l: lllllsvllhltll +1-4 g: lggfg +6-7 l: lgllltl +10-11 c: cccxcwchchcccn +1-2 m: mmmm +8-10 h: hhhhdhhbhh +5-8 d: dnddddtdd +16-20 l: llrlllgldllllllslllt +9-13 w: wwwwwwwwswwww +1-5 f: fpzffwffhrnfdtl +5-12 w: blwkbsstnvhmw +7-13 g: ggjngkmgfkngggggg +1-3 r: rrzr +17-19 d: ddddnddbddddddddqdz +9-13 v: zvvhgkvbvqvvvv +10-14 n: vxxmbptzjnnnxnqshqq +9-10 h: hlhhhhhqpthhhdds +3-5 v: vvcsv +1-5 g: dmggng +2-8 q: pnprhcxqhmf +6-7 z: zzstfvm +6-15 d: ddddddddjdddddd +2-13 c: fgqtczjthccjcc +5-6 j: jjgwjjjjs +11-13 b: bbbbbhbwbzwbqb +1-4 q: jpqdqqr +9-12 p: hpwpqppwpbhj +7-9 l: lllllljfln +13-14 z: zzzzzzzzzzzzzz +10-14 w: qjgqwwzrjwpjcjp +12-13 j: jjxrjjjjjjjsvj +10-12 n: nrnnnnnpnnnb +14-19 s: sszssszsssssswssssms +6-11 z: tzcvzzzlzzmtqzzzh +14-16 f: zfffkfffffqvffff +3-4 f: dfzf +3-5 g: ggsgx +9-11 f: fffjrfffffpfdfqdff +5-8 f: ffffvfgfm +5-8 c: ccccccclc +4-6 p: ppppppp +11-16 b: bbbbbbbbbgvbbbbbbbb +11-12 r: rrnrrrtrrrlbrr +3-4 d: ldqdp +11-13 s: lssnssssssssls +3-4 v: vvvvq +5-6 d: dkdddd +7-17 g: ggggggbgggggggggg +11-12 h: fhpbcfbbhlsj +5-12 d: hdpdddftmdrhdndjfj +2-13 m: stmmmmmmmmmmlbmm +2-6 r: vhqlrnr +13-18 n: dpmnnwnwgpnhnngndn +16-18 m: mmmmmmmmmmmmmmmpmm +13-17 h: vhmhchmthqzshhdthf +4-12 h: hhhkhhhhhhhmhh +2-3 p: pppppp +4-9 g: gmfgxgsgg +3-5 n: fnnhnn +6-7 j: gbdjhrjh +3-4 g: fvgggbgxgk +4-9 v: lvkdlmhvl +1-3 d: dddd +3-5 j: jjjkj +7-10 w: kzsbhmgjwdsvvqcqwlw +1-6 v: vldvvvldvvhvx +3-4 s: hspss +6-7 k: gpkkkkvkpxk +1-13 w: whwwwwzwgwdrwzfx +3-12 k: kkvkkkkkkkkkk +10-12 s: ssscvmsslsgsshsmss +3-9 s: msbncdgwbqsksh +5-9 l: kwlllnwwlhlmlqxdjn +1-10 l: llldldlllglllj +4-5 b: bbbbtbbbbbbbbbbbbbbb +5-7 b: bhbmwsgdcdpbxbfbjls +4-5 b: bbbnz +6-8 z: zzzzzzzz +9-16 q: qmqjqqqxqqqwqqqqpqq +2-4 s: ssssl +10-11 t: tlfttttktgbt +10-11 b: bbbbbbbbbbx +3-6 p: nvpgwlbfdvtjwzqt +14-15 x: xxxgxxxmxxxgxwqrxxx +13-14 w: wwwwwwwwwwwwws +5-6 t: vprgttk +3-4 n: hnnx +14-20 m: vxjbmmfwdhfvmmnnhwrm +9-10 f: ffpxfwfrjffffff +2-10 c: cccctcccccfc +6-10 v: vvvvgkvvvjv +10-14 x: xxxxpsxxxxnlxvfvx +3-4 h: gthpwdbhbmtbgsqwpht +1-2 r: dvfgmprq +1-4 z: hzzlnjbfgrzlzm +4-5 x: rxgcxjxxjxsld +2-14 j: tjmjjgbklphjjbr +2-4 v: vbvv +5-6 v: vvvvnw +4-12 z: zzqzzzzxczzzzz +1-4 l: mhllllwzd +17-18 p: zmsrkxhwghxkfbbsgp +3-8 k: gxvkhkkkb +1-2 c: cctvchzgnmznck +14-16 g: wgggmgggggggggglg +3-8 b: zbrbpbfp +9-10 b: bbbbbbbbwt +1-5 t: tgtvl +11-13 k: kkgkkkkkkkkkk +9-10 h: hbwhjhjfrvhhhhh +4-5 w: zdwdw +1-4 k: kwkkx +5-6 h: hhhhnhhhh +2-4 q: npqxsqgqqs +7-10 j: jjjsljjljjjj +5-9 d: dwhddqddsdnn +4-6 d: ddddddd +5-6 w: wwwkzwnw +3-4 s: rrksrs +2-3 x: cgkg +1-10 t: tfthtmhttz +1-4 b: mlckbj +5-10 t: htttjctltkf +4-5 w: wwnwh +2-15 j: dvqjjjjsjjmjjgb +12-13 l: llkllllllzlggll +3-15 h: hzrlhwcvnhhvhtztvhh +5-7 r: krrrbrn +1-20 d: dfddpddddddddddddddd +2-15 h: kdhhmvshhhpghhphhhh +4-8 k: wfbkcxkkpsktks +3-5 v: pfnmkv +4-5 f: fffff +3-6 k: rnpnkkkg +4-7 j: jjjjjjwb +12-14 r: rrrrrprrrrrrrrrrfw +3-5 v: vvvvv +2-4 b: bbqbb +1-8 j: jbjgnwzj +4-5 s: sssxm +1-3 g: zgggrbzjsk +4-10 w: wgwwwwxtjwf +2-12 p: jrpjhnpppzplk +3-11 q: gpqqwqqqqqq +8-13 m: nmjcmckjmqlmmmnqmmm +7-8 x: wxxxxxxx +11-14 s: dsssssshssnsxpsv +16-18 s: skssssssssssssssss +5-7 d: gzxmjddx +3-8 k: kkkkkkkvkk +9-12 w: wlwwwwtwfwgwnwwwh +5-7 l: llllllnl +1-3 h: mhhh +7-19 w: wkfwpvlmwqcpwmqscws +3-8 k: srtkpksf +6-13 q: hxqqtqrqnqpqqpjqqv +4-6 l: llkllkllllllqs +17-18 q: qjsqqqmqqqqqqqsqqq +5-9 l: llllvlllbll +17-18 m: mmmmmmmmmmmmgmmmff +2-5 z: zzzzzzz +1-15 q: pqqqrfqkkqqbqqfqhnk +11-12 w: wwwwwwwwwwcw +2-11 f: sffqtlfhffdfgfwff +5-6 l: llllll +9-14 f: fvffffffmffffff +1-5 j: jrjmfl +1-11 b: wbbbbxbbbqv +11-13 x: xxxxxxxxxxwxsxx +9-12 p: qpppplphppppps +3-4 k: kkvs +10-20 f: rffqfgthxvfqwffrmmms +13-16 x: xxxxxxxxxxwxxxxm +6-9 z: lzzxnbzwjzgzgz +11-14 c: qrhwwxczldwcdl +3-7 f: fpffffff +3-6 n: nnnnnnn +7-8 z: zzzzzzpm +3-7 w: wwmwwwz +5-9 w: wfwtwjwlwddqlrw +9-12 k: kkkkkkkkkkkk +7-12 q: qbqwqqqqqbzrqcq +4-7 h: hhkhkhhh +7-10 t: fkktttttkfsrtqt +2-3 d: tbclbd +6-8 l: lllllhlll +8-9 v: vlcvtvvvvvvv +4-8 x: njcxxtpxbhv +3-6 k: kxkkkdjxbkh +4-7 j: xjjjfjjsjjsnfjjdd +4-6 d: bkddhddvdsdq +13-17 k: kkkfkkkckkkkkkkkp +5-8 m: xrptnmpbcmfmm +9-10 k: khkkkkkkkq +2-3 n: nnjjn +6-8 p: kkppdsqp +10-11 s: sssshssssbd +8-16 n: tnnrngnnnnnvnnsznn +10-11 m: mdmmmmnmmmlmmm +1-7 k: tkggrkkkkw +7-11 h: hhvhhfrhhhfh +3-7 g: gmggzmggrsw +3-8 h: hwvldcwddhthsk +4-7 f: fskfvlfdfsfs +2-14 d: vdwsmsgjhftncg +14-18 q: qqqfqqqqqqqqnqqqqqq +10-12 l: jllllllllzcdllll +1-9 k: jkpkbhkkd +1-2 n: nnvhbn +6-7 q: rzqsqvqqqdw +2-5 s: wclgs +1-17 b: tbrbbbbnbbbbbwbrp +1-3 x: xxxx +2-3 k: kknkkkk +2-9 j: btjjpbjzmrjbjj +4-8 r: rrjkqrwn +2-5 x: vncxpjxqmsx +1-15 c: zmfgtshnzwhqskchtc +1-6 g: gqgkbqtz +13-17 z: zzbdzzzzzzjzzzzzdzzz +6-7 n: nxnnnnnn +5-6 k: dzsrsknkkkwbk +3-11 s: kzsljkcgkhmpfssssr +2-3 q: pqtq +17-20 p: pppsppkpppppppppvppl +2-6 h: hfbhmkh +3-13 d: qhdlvhddldnxwtvrndx +10-12 v: vvvvvvvvmfvhv +6-7 g: gggtlgggg +11-14 s: ssssssspscssssshrq +3-7 z: zdzgzqkcvzhzsb +3-4 h: hhdkhhhhhhg +2-4 s: sswps +4-10 p: zpsppzppczpd +3-14 j: jjxjjjjjjjjjjvjjjjjj +2-3 m: fmmmm +3-9 h: hhzbjrhhg +2-12 c: cccccccqwcpvccpc +5-8 h: hbhhfhhv +1-5 p: pppprp +3-6 z: zzzzzz +4-5 d: dddgddd +5-6 p: nxfhvqpqpnpmpmp +3-8 q: qqqqqmqqqqmdqq +6-8 b: bbbbzrbhbbbzp +17-18 t: ttttttttttttvttflgt +7-13 m: vsmmmjmbmmzwmmhbs +5-11 h: bbzxzdhhhhhndtfhgv +6-9 x: xxxtqxxxxfxxxh +8-9 r: rrrqrrrxr +5-6 p: ppspqp +9-11 d: qqqddddpdddtzd +4-6 s: sszlssk +15-16 s: ssjssssssssssssssst +5-6 f: ffffff +6-7 k: kkkkkns +10-11 h: hhmvhhhndhchhxshhhh +14-15 w: wwwwwwwwwwwwwrx +3-15 g: gzggggggggggglgg +11-12 n: nnntnnnnnnnn +4-10 r: rrrrrrrrbrcv +2-4 r: vrxtk +13-14 v: vvvvvvvvvvvvvc +3-5 v: vhrvnvnvd +2-15 f: dnfnkzbfvlfnfqfh +1-2 j: jjfj +3-5 w: wwwwwg +3-5 m: bmmmlp +5-6 w: wwwwww +13-14 n: nnnnnhnnnnnnnj +6-7 f: ffcffhbgzkt +6-9 f: kzffzzffjffgfxzf +18-19 g: gggggwgggggggggggpr +13-15 x: xlxxxxxxxxxxcxx +1-6 j: tjjjjhj +3-4 h: shpqdhl +9-15 l: rslpllllkplflqlhpzl +2-7 r: rrvrprl +15-18 d: gdddddddddddpddddddd +13-19 n: nnnnmnnxnxntnnnnnkn +10-11 x: xjxxxpxxxxxxqx +7-10 w: wwwwwwwwww +2-10 l: xllqjvzlwzpl +13-15 m: mmmmmmmmqmmwmmr +9-10 t: zptjnttktttttkvttvt +16-17 j: jjjjfjjgjjjjjjjpjjj +3-6 w: bnjnqwhhqpxcrgx +7-8 z: zzzzqdzzzz +2-4 g: dgkggk +1-3 q: mqqq +9-12 n: twqnnnsxlnnpnnn +12-18 z: czzpzzzzzzztzzzzznz +3-4 x: xglr +8-9 n: nnnhnnnnnn +1-2 v: vgxstl +10-12 p: qvpwpnjpkwpp +13-14 r: qrrrrrrrjnrrrq +3-8 d: ddhddddpddddddd +4-13 k: kkkkkrkckkgkpkkk +8-9 q: qvtbqdscg +3-6 f: fxjqfwdrqxmffhd +6-7 g: gggggjt +14-18 x: prxxtgxmxxhrfxtxkx +11-15 l: lllllllllllllllll +10-14 n: nnnnnznmnnntnn +1-3 d: dddd +16-17 s: sssssssssssssssss +14-15 w: wwwwlwgwwwwswwwww +3-9 f: dfblnfrfffrff +6-7 g: wggfpggggg +1-9 z: kxjqqkzczx +3-9 q: qqqqbqqqq +6-9 w: whwwcwqwwkxwpsbwpnw +7-15 g: rwggggggggzssmggjx +2-5 t: dtxbttt +1-5 x: xxtxxjdxxn +12-13 n: nnnnnnnnnnnznn +2-6 b: bxrpbbq +6-11 n: nnnnndrnnnnn +10-11 k: kkpkkkbkkpkkjk +6-8 c: gccccccm +2-3 x: ptxktrxtv +13-14 x: xxtxxxxdxxxxmhx +10-11 v: vvvdlvvvvlvvv +2-3 k: rtcdksdxk +17-18 w: zmhvwnndrjbvsmnhlw +11-12 m: dmmmmmmmmmml +7-8 g: gvndbzzbsjkpxg +9-16 c: cccggcqtdkcccccj +7-10 m: mqmmmmmmmmnmgbgmmbcq +5-13 c: pcbqcwcnjtvccccfgjx +3-8 f: ffpffffffffffff +9-11 n: cdndnntnnnnnnn +10-16 n: nnnnnnncntnnnmnwnn +6-10 r: rrrwrrrrpn +4-8 v: vcwsvvxvwvcvvh +4-5 g: ggghdg +8-10 v: vmvdvlrvtvtvvjvvd +13-16 j: vrgplxbmgwvljtjgzbw +2-9 s: ssssssnskss +18-20 v: vvvvvvvvvvvldvvvvfvv +8-13 r: rrrprrrhrrrgj +4-6 g: dgjkrhwggg +2-3 n: nnnw +7-11 s: sssscsgsssqs +7-10 c: cccccctccg +9-16 m: mmhmjwzmmgmdmnmmmm +1-4 c: ccvcc +11-15 m: mmmmmmmmmlvmrmmm +10-11 l: zgcnmxlplml +2-11 m: fmsmnmlhmmmmmbgm +6-7 g: hqggggggg +7-9 z: zzzzkznxzzzz +3-5 n: ngntcnnpsdnqnnmnrj +3-9 h: dhhhhfgkthxh +14-15 x: zbxmkfmtznnnxjjtsr +4-7 l: tlklltcll +5-10 s: hffslrssgrsrcwncmqw +5-12 f: ffffjffpfpfp +5-6 h: hhwhhhh +8-10 v: vvvvvzvvvfv +1-8 n: wqnnnglnrnln +11-15 q: qqqqqqqfgqnqqqnwql +2-7 d: wkdwddt +2-5 m: mxmmm +8-15 d: ddddddddddddddxld +6-9 s: sssssgscds +6-8 z: zzwzzzzzz +4-8 x: xfxxxxkxsckrwg +1-9 b: pnlbgtsfwp +6-10 l: dfrrklhrvp +15-16 n: qnnnnnnnnnnnnnlh +16-18 z: zzfczncnztzzkzzzqzz +12-13 r: rwrrqnrrrrrrkrrr +1-2 q: qkqqq +4-8 f: sfpffjfgfw +5-10 q: qqqqqqqqlqq +13-14 q: qqqqqqqqqqqqqd +1-6 v: vvvvtvmqfwvgjjgbtvm +3-8 f: dfffkdjftf +1-4 t: hgtttttttw +5-7 k: kzmkzkmkr +15-17 w: wwwwwwwwwwwwwwxpw +2-14 z: mnzkfkzbzhwfzbkzzzz +13-15 x: xtgxxqxxxxxxvpgrxx +9-10 q: qcqqvqsqssqqq +8-12 g: qghgrlggggggggszg +15-20 l: llllllwllllvllllllll +2-4 b: whhdhlzp +6-7 t: tttxtxct +1-9 g: bgtnvszsk +6-8 g: gggggggg +7-10 z: zqzzzzzszzpzkz +4-8 x: xxxxxxxxx +7-8 n: ztnnnknhpknvzn +11-12 g: gggggzpgxggg +10-13 b: bbbjbbbdbwbbrbq +1-5 w: whzmwwzwwlwwl +4-12 p: pbppdzcxhlllpxqxjm +8-10 f: fzbfpfrdfzff +6-7 v: vvvvrxh +1-4 t: gtjt +3-5 b: jzhpbbbwp +1-2 t: dtttn +3-9 r: dqrfrtvsxbrjwbrg +4-5 p: spppxqpb +4-12 c: sntctfrcsmwcmrlst +1-13 n: nnnnnnnncnnncfnn +4-5 z: zzzzz +11-15 n: nwnnsnfnntnnsnnxnnn +3-13 f: ffnfffffffsfffffff +11-12 b: brfbbqtpbhzrd +5-9 r: krrmrrrrjr +9-10 g: gggggggksc +6-12 m: mmmmmsmmmmth +11-12 w: wwwwwwwwwwww +10-11 x: xxxxxxpxxxs +3-8 j: qgzjmkqhqjszwxjj +4-6 g: kgggwgfg +16-18 r: rrdgrrrrrrrrrrrrrkfl +18-19 r: rrnrrrrrrrrrrrrrrrr +1-7 d: dprhvrdzdjxddd +3-4 p: ppxr +6-13 b: bbwbbbbbbbbhbbh +10-12 g: hrggghfkqtgswxdjcb +8-9 p: pcppppppm +3-4 w: vwlkwbwvp +11-15 f: fnhfffhfdffffffffff +2-7 c: kfccccrlc +9-17 z: zphgvhzrzzzwjzzczxf +3-4 v: vnxvkdrvvf +1-11 w: xxnlwlbzmpgwcw +10-12 v: vvvvvvxlvvvvvvvv +12-13 t: xtrctttpwptjb +6-7 z: zzzzzzz +3-19 m: fmgfmmjpfxmmprmmqhsm +18-19 m: fkmkpdrrbxzwgvdhqmm +2-3 h: xchwlphpkhlc +4-10 j: xrjjjjrjfjjjj +6-9 z: zzzzzvzzz +1-7 d: jdddddddd +4-9 x: xxxrxxxxxx +1-6 w: dwnwws +9-13 l: llllllljkllhlhlvx +4-7 t: tvsttbsqzcwzthtx +11-13 s: sbssrssssscsdsrss +5-6 n: bnnnncnznm +10-15 g: ggggrggggggggwggg +10-15 g: gggrfggxjgbgggjgs +3-5 v: vvvbvmvzvcv +2-5 r: rrrrrr +4-5 k: bkjkkkkf +4-8 z: mxddnzzjpbzm +2-3 r: frrkfzjrncrgpwsf +10-15 m: mmmmshmmmgmskcv +5-8 c: ctcchhczcq +7-8 b: skbqjbbwbncbtbb +6-7 d: ddddjjxgdd +6-13 v: tvcmvbvvvdvvvrzgk +5-10 x: xgsxdxqxxsxxjx +3-12 f: xfbqfffcftkh +4-5 j: wmjkhjj +7-11 n: nnnnpwpnnnrn +8-13 l: lqnlllllmlwll +8-12 s: sssssssssssssss +1-8 g: lggggggwgg +15-17 w: wwwwwwwwwwfwwwwwww +4-17 r: qrrlfhrrlrjrrrkcrrbr +4-5 n: rsrnplnttvxnnkhnvtxz +4-5 n: nnhts +5-6 x: xxxxxxn +1-4 s: gssss +4-6 p: qpppsgjppz +12-16 n: zcnkhqnnnnwtqnrnknnn +13-14 m: mmcmmmmmmmmmmn +9-11 d: kdpdddbdpgdddhd +3-8 k: krkbxgvq +2-6 t: tbhtslxhtfcphkwnth +3-8 z: gzzxzzzmjzzzz +4-5 c: cccwp +3-9 s: skszskstjs +4-10 l: qljlllzqlllvhlls +7-11 c: cccclccccccc +1-2 v: vgfv +14-17 m: hmmmmmmmmmmmmmmmm +2-4 p: pppp +2-3 c: cccs +2-3 k: xppklhkhsfw +5-7 m: mmmmzmqs +3-12 n: nnnqxdvbxnhnrnzfnnp +15-16 s: kssmjbzlwktbddltd +8-9 j: jjjjjjjjkntjh +3-5 g: ggvgpggggmggggg +6-11 t: rstjsmttmkdtttmttttp +5-6 r: rrrrbb +7-8 q: qqqqqtbbq +3-8 c: ccsccccbcccb +6-10 q: qplqqlmqqqq +5-6 v: vvvvvv +1-3 q: sqdqqqqgqqqqqqqq +11-12 j: lnjjjjpjjpwjjjjl +5-7 b: bsdsbbrbqbrpb +5-6 m: rmxmmmjdrvvmmmt +1-4 l: llfwh +1-2 d: hcsd +2-5 m: mmrjmnnmmmm +7-11 k: kkkwkbkkkkk +15-16 g: xsmrgbbgwzqrjgfk +7-8 x: xxxxxxxxxxx +3-7 n: nrmnnnndj +6-10 x: xxkzxpxxxwx +10-14 x: pxxxxxxpxxxxxxfxb +7-9 j: pjwjjjjjjjwp +9-10 r: rfspfrrlrf +1-5 r: rrrpfr +6-11 k: qjsqjnkckqfkcvkk +1-2 b: bbpqjnpbb +5-11 c: kcjxmstklbcjwktcwgk +2-3 h: phcshb +6-18 d: dddhdddddddvpdpdddd +3-7 t: qtkttttqtttn +8-10 j: jfjwjjjbsjjjj +9-11 m: mmmmmmfmmscm +3-4 v: ldvfvvllh +5-11 b: wbbbbvzmckbbtl +2-4 m: msmm +2-3 f: ffffvjff +3-13 c: pmchdcwhdwdnchs +7-12 s: sskdsssssssss +1-4 x: kwqtxnhhxp +13-14 n: nnnnnhnnnnnnnl +11-15 f: nrffwclmlgxgdblj +3-15 w: wvwwllsksktbbbdxmgmh +6-7 g: gggggtgg +12-13 r: rrrrrrrrrrjrrr +4-5 k: lkkkkkxv +8-10 h: hhhhhhhkhh +17-18 q: qqqqqqqqqzqvqqqqxvdq +3-6 w: wwvwsxj +8-15 z: zxczhwthhhzrzzpzfzs +3-5 q: qqqqk +11-18 z: zzzzzzzzzzlhbzzzzzz +6-8 m: mmmphqmt +2-4 h: hnsrkhv +4-9 x: xxxrxfxxvxwxx +1-4 d: ddsxjrmdnwswd +3-6 r: rprvrwrrnflvhnlrv +7-10 r: rrrrrrrcrwtrh +13-14 g: gntfgtrbgdfsgk +12-13 c: cccnbcccccjtkccl +2-3 f: fgsf +2-5 f: dfftfsrkz +6-8 p: wpppprmpp +8-9 k: kkkxkkkkdk +8-10 l: lrmlzpllllltlrblgcld +3-6 z: tfqzzzpz +4-5 r: nrrrrrj +5-10 l: llllsrnslglllqcl +10-17 j: jjjjhjjkjcjjjxjjhj +10-13 h: hhnlhhhhhhhhh +15-16 h: chrhphvhxhjphhxk +5-18 c: cccctcccccccccccccc +14-15 h: hhhhhhhhrhhhhxb +5-6 w: wwwtsdq +2-5 s: slsscz +8-9 f: fffffffdx +7-10 s: fdsssgkrpgssss +16-19 n: nnnnnnnnnnnnnnnnnnnn +8-18 d: dxdvkddjddddzddddgg +12-13 q: qqqqqvqqqqqvq +6-7 l: pvmnlfwzb +3-5 c: cfnclcfrccxstc +4-10 m: mmmjmmmmmmmm +15-17 s: sssssssssssssshsmss +8-10 q: qqwwktqtqsqtb +3-4 n: nbxnn +6-7 p: pppvpvr +1-5 h: dmqlb +9-15 g: gplxmjgdgjgzqlgkxhg +7-11 l: llsltxlllmblgp +7-8 h: hhhhhghhhw +12-13 x: xxxxxxxxxxxxx +2-7 m: tmxtdmmfgn +12-14 r: wrrrrrrmrrrwrn +10-16 t: tlttqdtttgcstttntt +2-10 z: zzzzzzzhzpzzzzzz +8-10 s: sssssssssss +5-7 z: zvzzzzzczzzq +12-13 c: scccwccccccccc +14-18 v: vvqvvvvvxvvvvvdvvv +14-16 v: vvvvvvvvvvvvvtvzv +4-9 d: zddgpddqwdtdd +7-11 l: xllvlzclflzlnhtls +6-7 l: lllllczl +4-12 s: slbsmstssscs +8-11 b: xbqbtjsfbbgq +5-15 r: frrrqwcnrrrrhrrqk +2-3 n: nmtxqfxnnnnnh +14-17 l: glwlzllglblwlmlll +10-12 g: ggggggnjggggg +9-10 b: bbbbbbbbkt +4-9 m: mcmmmmnfmwmwfmmljxmv +7-11 l: lxmllrqllwlhl +9-13 p: bppxpjpmpwcpppdprpp From a304a380461664a4163200972f88e62180a74e39 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 11:20:12 +0100 Subject: [PATCH 025/129] 2020: d02: ex1: add solution --- 2020/d02/ex1/ex1.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 2020/d02/ex1/ex1.py diff --git a/2020/d02/ex1/ex1.py b/2020/d02/ex1/ex1.py new file mode 100755 index 0000000..fca2919 --- /dev/null +++ b/2020/d02/ex1/ex1.py @@ -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() From 776577c118d33e6402e00ce055b48ea3965064c4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 11:20:25 +0100 Subject: [PATCH 026/129] 2020: d02: ex2: add input --- 2020/d02/ex2/input | 1000 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1000 insertions(+) create mode 100644 2020/d02/ex2/input diff --git a/2020/d02/ex2/input b/2020/d02/ex2/input new file mode 100644 index 0000000..0f3ccea --- /dev/null +++ b/2020/d02/ex2/input @@ -0,0 +1,1000 @@ +7-9 l: vslmtglbc +2-3 s: hpbs +1-3 v: pvvr +2-8 h: hhhhvhhh +9-10 x: xxxxxxxxzv +2-5 q: xdqbjj +17-19 n: nnnnnnnnnnnnnnnnrnsn +5-7 f: fxfkffffff +4-7 h: hrjhxlhh +11-12 v: vvvwdvvvvvvvvv +6-7 q: tqqqqvqqq +2-4 b: vlmndngvbkptbb +1-4 t: mttwt +3-4 v: vmgdcj +4-17 n: nwnnnnnnwqncnxxnn +3-4 c: gscc +3-4 w: wwwwww +8-12 j: jdjjtjxjjjjj +1-5 b: bmbfbbb +5-11 k: kkkkkkdkkkkk +1-4 m: mmmm +5-6 z: zzzzhzzz +8-10 z: zmqzzzzgzlzdz +14-15 r: rrrrrrrrrrrrvnr +11-13 q: qqqqqqqpqvpqwq +3-7 q: qnqhqcqq +11-17 r: vrrrrrrjrrrrrrrrrrrr +2-5 g: srqmltncfgdg +7-11 w: wwwwwwtwwwqj +5-14 j: hhwjmjzmjjxjjkjgjj +11-14 x: xffrxxxxxxzxrxxmxqlw +14-16 c: hqcchcjwrxbcgclctx +10-14 k: kkvkkdbqnqkkbfftxm +10-12 c: cccccccccccc +7-13 x: dbjtkxxfjsvvx +9-11 d: ddddddddxdb +4-8 h: mhbhrsvtl +8-13 h: hbhrhjhhjhhqpthxnwhh +10-11 s: sssksssrsssss +6-8 m: mmfmmmmm +4-14 h: bhhnhvhhhhhhlvhmqkh +1-17 c: cccccccccccccccccc +10-11 r: rsrprprrrnr +10-13 d: dddddddddhdddd +5-7 s: msfscsndswsl +3-8 b: bbzzbhbwb +9-20 b: cbbcrbwjfrddqbvzrfxb +9-15 h: shpdthhhhhshhhhh +5-6 n: nnnnnn +1-7 f: dfffffffff +10-11 f: fffffffffvf +3-4 z: xmkkvcrqdz +15-19 h: hhghhhhhhhmhhhhhhhh +4-7 m: lmxkhmmm +3-4 l: zlllkfzcldctlmhq +2-5 j: jxjjqj +10-11 s: sssssssjsgw +2-4 j: vjkjp +9-18 l: lffnlbmrmrvlkrpchj +3-6 q: qqhqqdqq +18-19 d: ddddddddddddddddddd +1-8 m: mmsmzwbchmmlmljslkk +2-6 m: tmbtmmgmmwm +2-8 j: jrjjjjjp +8-12 d: ddddxdbtvdnbdk +8-13 t: tttttttxttrtr +8-13 w: wwwwjgwzdxwwp +3-14 j: jjkjjjrjjcjqjjj +3-4 q: qgpx +6-9 p: ppppppppp +6-8 f: fdffffff +5-10 x: xsmxxxxkxxhtxxmx +1-4 j: dzrhcjljjv +13-14 s: sdxcbwfsprkpss +9-13 n: nnnnnnnnnnnnnn +3-7 r: rrrcrkrrrrm +4-11 f: fmfrfgphxqf +4-13 t: tttrtptttzgttwj +10-12 w: wwwwwwwwwfhh +10-11 q: qvqqqqqjqptqq +8-10 s: sssssxsssv +12-15 c: dsmccckcccbccwcccdc +5-7 l: nllffcmrwkdhw +8-10 t: tttzttvttgtqt +7-8 m: mmmbmmjmm +7-9 c: ckccqmmcccjckdc +3-4 w: twwwd +11-13 g: ghgpggggwggclgfggtzm +10-11 m: lvwmmmmmbfmm +9-12 g: gggggnggtgdgg +5-7 k: kkkkkkk +11-13 g: ghgggggggbrgzgg +3-7 z: zzzzzgzz +7-10 z: zzzzzmszzdzzz +15-20 w: wwwwwlwwwwwwwwwwwwwc +7-9 z: zzzzzzzzz +1-8 q: qqnhbczhtzg +11-14 s: sgcssssvsssvsslvss +2-4 w: mcztwwt +3-7 w: wtwtdwpb +5-8 r: rrrrrrrsr +7-8 v: vnvvvvvv +7-8 j: jjjjjglwj +5-6 w: ktkvwwgqbxgckq +7-9 f: ffffzfffff +12-14 n: nnnnnnnnnnnnngn +3-5 z: zzzzdz +5-11 j: xmjjtjjbjngk +3-5 l: llvldllllvl +7-8 h: hhhhhhhnhh +17-18 p: ptpppppppppppppprq +2-6 s: sssdnlgqjxcvssh +3-6 h: dhhthhhhch +6-18 k: khkkkkzkmkkkvttkkkkk +3-4 x: dxsxxx +4-11 b: bbbbbpbbbbb +5-7 t: ttzthtx +3-6 k: kkrkkxkkhkkk +2-7 b: mbzbjfnb +9-12 l: fglllllllllkl +11-14 l: plctdxwbmnbqnczwvjlv +2-10 f: jfdtpsntnf +18-19 d: dddddddpddddddddddd +4-6 h: gkhbkhhhkhppb +7-9 f: ffqvffffffnfr +3-4 l: llzl +2-12 d: dccfdbdddddndd +12-17 b: bbbbbbbbbbbbbbbbbbbb +2-3 k: bkkp +5-9 h: hlhhjhhhl +4-12 f: ffffrffffffffffflffz +1-5 v: vvvvvwvv +8-9 l: lllllllgb +15-18 t: ttttttttntttltvtts +6-7 q: zqpqcgbqqq +5-11 w: lgrktkmkqzjvwg +8-9 p: ppppppppp +3-4 c: cccc +7-15 b: bqbxzbbbdtbbbmbb +9-11 k: kkkkkkvkdkktk +4-6 t: bktttttt +6-10 m: bwtpbsmmnmmlmfd +5-12 z: zzckszrdzzpmzzzzk +4-5 q: qqqck +3-6 k: kkwpsbbqkntgz +1-6 k: kkkkkk +1-7 f: fffzffffffffffjq +3-4 p: jqpxgn +7-13 v: wvhzbmvvvvvvgvvv +3-5 p: ppvdfgr +16-18 c: ccccqcccwccgcbctsk +5-8 p: ppgpgpjgpzqpw +1-3 t: tspmnttttfm +2-9 b: bmbbbhbbxbb +2-7 n: dnnngnnnmnnnnckn +12-14 c: cccccccccbccrm +12-14 q: qqqqqqqqqhnmlpqqqq +2-3 n: whnnmf +13-15 h: hhhhhhhhhhhhchp +4-5 k: kkcmw +6-7 z: wfqwfkhdvd +3-4 h: bqnhhhncph +3-4 j: kjgkj +16-17 s: ssssssssssssssfqx +4-6 r: rrzbpw +2-3 m: vzmmmm +17-19 z: zzzxzzzzzzzzzzzzfzz +7-12 s: nmpsssdhszssssssnhs +4-5 l: lfqlcl +3-5 d: fdtdb +6-9 b: mlbbjhbbbbbbl +1-5 g: gggggg +4-7 x: xxbxxhxxkxsx +3-6 j: kspjgjzxfpdclkrzk +2-7 s: ffwpjssskscsv +4-5 n: nnndf +5-15 g: gtljgmrlggmghbv +13-16 v: vvvvjvqbvvvvvvvhvvs +6-9 b: dldbmbsmb +5-7 f: sfvffffft +1-3 b: ztblbcxnrmkvnfvz +10-12 r: dljvqxnjttjvtfrcxgh +14-16 w: hgwslvnzbhhxwwvwprww +6-8 s: vssnsssgptshmkst +6-8 s: scssssshs +6-12 g: gggggfgggtnhm +6-10 j: hlcjjlfpljpwjjrvpl +2-8 m: zbbmxlzlrckhrcmksf +1-7 v: vvvnmvl +3-4 x: fxpt +3-12 h: hhhhhhhhqhhhh +8-9 t: tttttttftt +12-18 r: rrrrrrrrrrrrvrrrrdr +10-14 d: dbdddddddvddddd +15-17 r: dvrhrrrrbnrrprrrrrr +7-11 v: fvjgvgvvvsvz +5-6 m: dsmjmm +7-12 k: kkkkkkknkkpkkz +4-7 h: fhdhmhmvwfsh +8-9 f: ffffffffgf +2-4 h: hhhk +5-9 r: mdrcwmllvgnjfzfcwztt +8-9 g: gggggggnjggg +11-16 v: vlgfvvnvvvvvvvvv +12-16 t: tttttttwtttptttk +4-6 w: jfvkvwx +12-17 w: phmrqwdwwqwwwwbwzbwr +16-17 m: mmrmmmmmmmmmmmmdm +9-10 z: jzhzzzzzzzz +11-14 x: xxxxxxxjxxxcxm +11-12 b: bbbbbbbbrbgq +3-5 j: sxjjmxjrztjjldkpbcq +10-16 l: lhlldlldljlllmlm +2-10 t: szsnwnkttt +7-9 q: ppxcslxzj +14-15 c: ccczcccccccccnm +2-9 l: dllppswblllkltl +1-7 z: kcklcmt +8-9 p: ppppppfhjp +4-8 f: ffjkkffl +5-11 g: hgxgggcgjglbgzcdzg +2-4 d: ccdq +11-14 r: rvrtrrrrrtrnrqrrr +9-11 k: kkckkgkzsmkkkrwknkm +7-9 x: sgmxhhjxnpgcx +6-8 t: qhbpjtjtttttttt +7-8 q: wqqrqqqqqn +3-4 z: jzqgm +4-19 g: gdgmgjggkgpghgggggg +2-11 g: ggtgggggsgs +3-5 j: xdtjdjpjwljmd +1-5 h: hbnwh +2-4 h: hhfhhzhdqzhwchql +3-11 k: kjgjltkkmkkm +17-20 d: ddfnglddnddpqdqwdwbd +1-4 x: gxkpxx +2-3 b: zbbmkb +2-9 r: hrhphqrcr +7-10 d: dkdvddddddn +3-4 x: dsxbt +18-19 p: npnnpwpppgvxwmzpszv +14-16 v: vvgvvvvvvvvvvjvvv +1-8 h: nhthchpdnh +7-14 s: ssgssfsmrsssldgscfd +8-9 h: hhhhghhpv +4-5 g: kggslg +3-9 g: gggglngjzgg +11-13 h: hhhhhhhhhhhhhh +4-7 l: lllslgll +2-4 c: cccccnk +1-11 l: hltwqljjlzllhq +1-2 x: bkxtxx +4-5 v: vvvvg +7-8 x: xxxxxxqd +13-14 n: nwvcqqtwttfhnn +2-7 c: cccchcs +2-5 p: pbpgv +16-17 t: tttttvttttttmttlvttt +1-2 j: fbjj +2-5 n: knznnncnfnvn +11-12 l: llglllcnlfllllkllr +7-8 v: vvvvvvtr +8-9 k: kkkkvkkkp +6-7 q: tpxqqqr +5-7 s: sssnssshvxs +13-18 m: mmfmmmmmmmmwlmmmmn +7-11 p: ppppppppppp +6-7 s: bsssssds +3-7 q: qmqwqqqqqqhfp +4-5 r: tffrr +9-11 c: ccccccccccc +1-3 w: vvlhw +1-8 g: vgggggghg +5-6 p: txlxppppspkplxf +7-13 f: fffffffffffff +2-8 g: gggggsgggg +2-5 w: wbwwz +2-3 p: spsrhtmjzpmgvj +1-4 d: vbtd +4-5 g: ggggf +14-16 v: dvvfhdjcvvvmvdvnm +6-8 x: xxxxxxxxx +5-6 j: jjnjjj +13-15 m: mmpmmvmmmmszmdgkm +4-16 z: zzzzzzzzzzzzzzzq +4-10 x: xxxxxxxxxxxx +4-5 r: rrrrr +10-11 m: rmmdmmmmmmdnm +2-3 q: qqqs +7-11 m: mmmmmmmcmmmmx +2-4 x: dcfr +2-4 p: cpppgpp +1-3 n: vnqgqbhn +3-4 p: pppx +13-14 f: fffgfpfffffffqftfn +2-5 h: hsdhhhh +3-6 q: pdqvtq +6-8 l: lllllmlll +5-6 v: vvvvld +10-11 x: jxhxdchxjwx +7-8 h: hhhhhhhh +11-19 z: dtzzxcztmzzzzzzjqzzz +3-4 h: thcchhh +3-5 b: dbbwjbbnb +11-12 q: qqtgqqldkqqqqqqctqq +12-13 l: lllllllklllcxl +2-8 s: sppbsvjfp +10-20 g: xgswhgldgggdkxjggzzg +2-4 n: nnnnn +3-5 c: xmtccjj +1-7 w: wbqwwwsc +3-6 g: wgghgngg +4-6 p: pppptpppwp +1-3 j: jjjjjjjjjjjjjjjsjjjj +2-6 r: drbwrrmtjnzrfsrxwq +1-5 v: rcvvd +2-3 w: dwnzf +4-6 l: lrlbld +3-7 h: hhhhhhkhh +6-12 b: bktbzmzlbbmvmbpm +1-7 n: znfnngntfsh +2-14 z: jzzsgxsqkqmzlzhzljz +3-8 q: qmqfzhfq +8-9 d: ddzdddddd +11-14 k: gkwtwksxrdwxkkh +3-5 v: vvvvnv +6-12 s: pksrzgvspsswsxrpsvss +6-8 w: whpwhwjwwpkww +8-10 w: wdwwbbwwsw +13-19 z: zzzfzzzzzzzzwzzzzzr +3-4 v: vkbv +7-10 x: wxxxkjkxxxdfxx +1-3 g: gpgsgqgb +15-17 r: pfntnqmbtcfcsrlgprqk +7-10 s: sjdssmsssbssssl +3-16 p: ppnjzcppkpppmwvkp +3-7 r: srkrvrjrgrrrr +3-4 x: xmxx +1-5 k: zkkhqdgrt +1-13 c: rcncccdclcccc +4-7 n: nxfmnnbn +8-9 g: gngggpgfwggg +2-5 m: smmfs +1-12 p: snppbhspvzpppnwpwjpp +2-6 s: rczxxsvknqcpwklsbc +4-9 d: ddndgtdddqddddqd +10-13 f: ffffffffftfff +8-9 x: xxxxxxxxxx +4-7 r: krkrsgrfvqzxpcrrgjr +3-4 c: chdc +13-14 k: xkkkkkkkkkkkkq +4-8 t: tmmvccgxfbtttttttt +14-16 l: trkllqstdlclqzlv +1-3 x: qkxx +2-6 s: nsfhklqbnvs +4-5 g: rlggcgg +10-12 l: llzlllllllll +12-14 w: wwwwwwwwdwwtwl +3-4 m: qmvp +2-3 d: dddd +2-6 j: mwqfjdjlnb +7-9 z: zlzwzrzshd +5-8 k: jmkjkqdcwkrtvb +17-18 s: sssssgssssstssssxcds +1-3 k: qfxkt +3-11 j: tsjjvpcnsmd +12-14 v: vfvvdvvvvvvbvjvvvvvv +4-12 v: wvxmcvzlrvtv +4-8 q: qqqqqqqqqqqqq +16-17 s: sssssssssssssssvqs +3-4 d: ddwx +3-4 h: hhhh +8-9 z: znbzzzzgzzz +1-3 b: tkffshrzkxwjbrxkkv +3-8 n: nnqnnnnbnn +6-8 n: bnpnnhfnnnqndxncpgq +10-16 d: sddddlddjszdddtc +6-8 x: wwwmqxzwl +12-16 j: jjjjjmjjjjbxjjjtpv +15-18 z: zzzzzzzzdzzzczhzznf +1-18 n: nvhddhnqnnrbvpnnwn +14-17 z: lbznszzzzzzzzzzzm +7-9 l: jfqxkllcll +8-14 l: lllllllllnllllc +7-13 m: ncmkkmmhwsvhmmsk +2-5 t: ttttth +4-5 k: kgkkkk +4-9 d: ddddddddd +3-6 n: nnntnnn +9-10 h: bbjqqhhhwr +12-16 g: ggfgsjggghcfggbpjggp +2-3 x: dktxtxh +1-2 x: grnz +5-7 x: txxcgddxnwxxx +12-15 b: bbbbbbbbbbjbbbj +11-17 f: fffffrfffcfpfcffff +3-9 l: lllllsvllhltll +1-4 g: lggfg +6-7 l: lgllltl +10-11 c: cccxcwchchcccn +1-2 m: mmmm +8-10 h: hhhhdhhbhh +5-8 d: dnddddtdd +16-20 l: llrlllgldllllllslllt +9-13 w: wwwwwwwwswwww +1-5 f: fpzffwffhrnfdtl +5-12 w: blwkbsstnvhmw +7-13 g: ggjngkmgfkngggggg +1-3 r: rrzr +17-19 d: ddddnddbddddddddqdz +9-13 v: zvvhgkvbvqvvvv +10-14 n: vxxmbptzjnnnxnqshqq +9-10 h: hlhhhhhqpthhhdds +3-5 v: vvcsv +1-5 g: dmggng +2-8 q: pnprhcxqhmf +6-7 z: zzstfvm +6-15 d: ddddddddjdddddd +2-13 c: fgqtczjthccjcc +5-6 j: jjgwjjjjs +11-13 b: bbbbbhbwbzwbqb +1-4 q: jpqdqqr +9-12 p: hpwpqppwpbhj +7-9 l: lllllljfln +13-14 z: zzzzzzzzzzzzzz +10-14 w: qjgqwwzrjwpjcjp +12-13 j: jjxrjjjjjjjsvj +10-12 n: nrnnnnnpnnnb +14-19 s: sszssszsssssswssssms +6-11 z: tzcvzzzlzzmtqzzzh +14-16 f: zfffkfffffqvffff +3-4 f: dfzf +3-5 g: ggsgx +9-11 f: fffjrfffffpfdfqdff +5-8 f: ffffvfgfm +5-8 c: ccccccclc +4-6 p: ppppppp +11-16 b: bbbbbbbbbgvbbbbbbbb +11-12 r: rrnrrrtrrrlbrr +3-4 d: ldqdp +11-13 s: lssnssssssssls +3-4 v: vvvvq +5-6 d: dkdddd +7-17 g: ggggggbgggggggggg +11-12 h: fhpbcfbbhlsj +5-12 d: hdpdddftmdrhdndjfj +2-13 m: stmmmmmmmmmmlbmm +2-6 r: vhqlrnr +13-18 n: dpmnnwnwgpnhnngndn +16-18 m: mmmmmmmmmmmmmmmpmm +13-17 h: vhmhchmthqzshhdthf +4-12 h: hhhkhhhhhhhmhh +2-3 p: pppppp +4-9 g: gmfgxgsgg +3-5 n: fnnhnn +6-7 j: gbdjhrjh +3-4 g: fvgggbgxgk +4-9 v: lvkdlmhvl +1-3 d: dddd +3-5 j: jjjkj +7-10 w: kzsbhmgjwdsvvqcqwlw +1-6 v: vldvvvldvvhvx +3-4 s: hspss +6-7 k: gpkkkkvkpxk +1-13 w: whwwwwzwgwdrwzfx +3-12 k: kkvkkkkkkkkkk +10-12 s: ssscvmsslsgsshsmss +3-9 s: msbncdgwbqsksh +5-9 l: kwlllnwwlhlmlqxdjn +1-10 l: llldldlllglllj +4-5 b: bbbbtbbbbbbbbbbbbbbb +5-7 b: bhbmwsgdcdpbxbfbjls +4-5 b: bbbnz +6-8 z: zzzzzzzz +9-16 q: qmqjqqqxqqqwqqqqpqq +2-4 s: ssssl +10-11 t: tlfttttktgbt +10-11 b: bbbbbbbbbbx +3-6 p: nvpgwlbfdvtjwzqt +14-15 x: xxxgxxxmxxxgxwqrxxx +13-14 w: wwwwwwwwwwwwws +5-6 t: vprgttk +3-4 n: hnnx +14-20 m: vxjbmmfwdhfvmmnnhwrm +9-10 f: ffpxfwfrjffffff +2-10 c: cccctcccccfc +6-10 v: vvvvgkvvvjv +10-14 x: xxxxpsxxxxnlxvfvx +3-4 h: gthpwdbhbmtbgsqwpht +1-2 r: dvfgmprq +1-4 z: hzzlnjbfgrzlzm +4-5 x: rxgcxjxxjxsld +2-14 j: tjmjjgbklphjjbr +2-4 v: vbvv +5-6 v: vvvvnw +4-12 z: zzqzzzzxczzzzz +1-4 l: mhllllwzd +17-18 p: zmsrkxhwghxkfbbsgp +3-8 k: gxvkhkkkb +1-2 c: cctvchzgnmznck +14-16 g: wgggmgggggggggglg +3-8 b: zbrbpbfp +9-10 b: bbbbbbbbwt +1-5 t: tgtvl +11-13 k: kkgkkkkkkkkkk +9-10 h: hbwhjhjfrvhhhhh +4-5 w: zdwdw +1-4 k: kwkkx +5-6 h: hhhhnhhhh +2-4 q: npqxsqgqqs +7-10 j: jjjsljjljjjj +5-9 d: dwhddqddsdnn +4-6 d: ddddddd +5-6 w: wwwkzwnw +3-4 s: rrksrs +2-3 x: cgkg +1-10 t: tfthtmhttz +1-4 b: mlckbj +5-10 t: htttjctltkf +4-5 w: wwnwh +2-15 j: dvqjjjjsjjmjjgb +12-13 l: llkllllllzlggll +3-15 h: hzrlhwcvnhhvhtztvhh +5-7 r: krrrbrn +1-20 d: dfddpddddddddddddddd +2-15 h: kdhhmvshhhpghhphhhh +4-8 k: wfbkcxkkpsktks +3-5 v: pfnmkv +4-5 f: fffff +3-6 k: rnpnkkkg +4-7 j: jjjjjjwb +12-14 r: rrrrrprrrrrrrrrrfw +3-5 v: vvvvv +2-4 b: bbqbb +1-8 j: jbjgnwzj +4-5 s: sssxm +1-3 g: zgggrbzjsk +4-10 w: wgwwwwxtjwf +2-12 p: jrpjhnpppzplk +3-11 q: gpqqwqqqqqq +8-13 m: nmjcmckjmqlmmmnqmmm +7-8 x: wxxxxxxx +11-14 s: dsssssshssnsxpsv +16-18 s: skssssssssssssssss +5-7 d: gzxmjddx +3-8 k: kkkkkkkvkk +9-12 w: wlwwwwtwfwgwnwwwh +5-7 l: llllllnl +1-3 h: mhhh +7-19 w: wkfwpvlmwqcpwmqscws +3-8 k: srtkpksf +6-13 q: hxqqtqrqnqpqqpjqqv +4-6 l: llkllkllllllqs +17-18 q: qjsqqqmqqqqqqqsqqq +5-9 l: llllvlllbll +17-18 m: mmmmmmmmmmmmgmmmff +2-5 z: zzzzzzz +1-15 q: pqqqrfqkkqqbqqfqhnk +11-12 w: wwwwwwwwwwcw +2-11 f: sffqtlfhffdfgfwff +5-6 l: llllll +9-14 f: fvffffffmffffff +1-5 j: jrjmfl +1-11 b: wbbbbxbbbqv +11-13 x: xxxxxxxxxxwxsxx +9-12 p: qpppplphppppps +3-4 k: kkvs +10-20 f: rffqfgthxvfqwffrmmms +13-16 x: xxxxxxxxxxwxxxxm +6-9 z: lzzxnbzwjzgzgz +11-14 c: qrhwwxczldwcdl +3-7 f: fpffffff +3-6 n: nnnnnnn +7-8 z: zzzzzzpm +3-7 w: wwmwwwz +5-9 w: wfwtwjwlwddqlrw +9-12 k: kkkkkkkkkkkk +7-12 q: qbqwqqqqqbzrqcq +4-7 h: hhkhkhhh +7-10 t: fkktttttkfsrtqt +2-3 d: tbclbd +6-8 l: lllllhlll +8-9 v: vlcvtvvvvvvv +4-8 x: njcxxtpxbhv +3-6 k: kxkkkdjxbkh +4-7 j: xjjjfjjsjjsnfjjdd +4-6 d: bkddhddvdsdq +13-17 k: kkkfkkkckkkkkkkkp +5-8 m: xrptnmpbcmfmm +9-10 k: khkkkkkkkq +2-3 n: nnjjn +6-8 p: kkppdsqp +10-11 s: sssshssssbd +8-16 n: tnnrngnnnnnvnnsznn +10-11 m: mdmmmmnmmmlmmm +1-7 k: tkggrkkkkw +7-11 h: hhvhhfrhhhfh +3-7 g: gmggzmggrsw +3-8 h: hwvldcwddhthsk +4-7 f: fskfvlfdfsfs +2-14 d: vdwsmsgjhftncg +14-18 q: qqqfqqqqqqqqnqqqqqq +10-12 l: jllllllllzcdllll +1-9 k: jkpkbhkkd +1-2 n: nnvhbn +6-7 q: rzqsqvqqqdw +2-5 s: wclgs +1-17 b: tbrbbbbnbbbbbwbrp +1-3 x: xxxx +2-3 k: kknkkkk +2-9 j: btjjpbjzmrjbjj +4-8 r: rrjkqrwn +2-5 x: vncxpjxqmsx +1-15 c: zmfgtshnzwhqskchtc +1-6 g: gqgkbqtz +13-17 z: zzbdzzzzzzjzzzzzdzzz +6-7 n: nxnnnnnn +5-6 k: dzsrsknkkkwbk +3-11 s: kzsljkcgkhmpfssssr +2-3 q: pqtq +17-20 p: pppsppkpppppppppvppl +2-6 h: hfbhmkh +3-13 d: qhdlvhddldnxwtvrndx +10-12 v: vvvvvvvvmfvhv +6-7 g: gggtlgggg +11-14 s: ssssssspscssssshrq +3-7 z: zdzgzqkcvzhzsb +3-4 h: hhdkhhhhhhg +2-4 s: sswps +4-10 p: zpsppzppczpd +3-14 j: jjxjjjjjjjjjjvjjjjjj +2-3 m: fmmmm +3-9 h: hhzbjrhhg +2-12 c: cccccccqwcpvccpc +5-8 h: hbhhfhhv +1-5 p: pppprp +3-6 z: zzzzzz +4-5 d: dddgddd +5-6 p: nxfhvqpqpnpmpmp +3-8 q: qqqqqmqqqqmdqq +6-8 b: bbbbzrbhbbbzp +17-18 t: ttttttttttttvttflgt +7-13 m: vsmmmjmbmmzwmmhbs +5-11 h: bbzxzdhhhhhndtfhgv +6-9 x: xxxtqxxxxfxxxh +8-9 r: rrrqrrrxr +5-6 p: ppspqp +9-11 d: qqqddddpdddtzd +4-6 s: sszlssk +15-16 s: ssjssssssssssssssst +5-6 f: ffffff +6-7 k: kkkkkns +10-11 h: hhmvhhhndhchhxshhhh +14-15 w: wwwwwwwwwwwwwrx +3-15 g: gzggggggggggglgg +11-12 n: nnntnnnnnnnn +4-10 r: rrrrrrrrbrcv +2-4 r: vrxtk +13-14 v: vvvvvvvvvvvvvc +3-5 v: vhrvnvnvd +2-15 f: dnfnkzbfvlfnfqfh +1-2 j: jjfj +3-5 w: wwwwwg +3-5 m: bmmmlp +5-6 w: wwwwww +13-14 n: nnnnnhnnnnnnnj +6-7 f: ffcffhbgzkt +6-9 f: kzffzzffjffgfxzf +18-19 g: gggggwgggggggggggpr +13-15 x: xlxxxxxxxxxxcxx +1-6 j: tjjjjhj +3-4 h: shpqdhl +9-15 l: rslpllllkplflqlhpzl +2-7 r: rrvrprl +15-18 d: gdddddddddddpddddddd +13-19 n: nnnnmnnxnxntnnnnnkn +10-11 x: xjxxxpxxxxxxqx +7-10 w: wwwwwwwwww +2-10 l: xllqjvzlwzpl +13-15 m: mmmmmmmmqmmwmmr +9-10 t: zptjnttktttttkvttvt +16-17 j: jjjjfjjgjjjjjjjpjjj +3-6 w: bnjnqwhhqpxcrgx +7-8 z: zzzzqdzzzz +2-4 g: dgkggk +1-3 q: mqqq +9-12 n: twqnnnsxlnnpnnn +12-18 z: czzpzzzzzzztzzzzznz +3-4 x: xglr +8-9 n: nnnhnnnnnn +1-2 v: vgxstl +10-12 p: qvpwpnjpkwpp +13-14 r: qrrrrrrrjnrrrq +3-8 d: ddhddddpddddddd +4-13 k: kkkkkrkckkgkpkkk +8-9 q: qvtbqdscg +3-6 f: fxjqfwdrqxmffhd +6-7 g: gggggjt +14-18 x: prxxtgxmxxhrfxtxkx +11-15 l: lllllllllllllllll +10-14 n: nnnnnznmnnntnn +1-3 d: dddd +16-17 s: sssssssssssssssss +14-15 w: wwwwlwgwwwwswwwww +3-9 f: dfblnfrfffrff +6-7 g: wggfpggggg +1-9 z: kxjqqkzczx +3-9 q: qqqqbqqqq +6-9 w: whwwcwqwwkxwpsbwpnw +7-15 g: rwggggggggzssmggjx +2-5 t: dtxbttt +1-5 x: xxtxxjdxxn +12-13 n: nnnnnnnnnnnznn +2-6 b: bxrpbbq +6-11 n: nnnnndrnnnnn +10-11 k: kkpkkkbkkpkkjk +6-8 c: gccccccm +2-3 x: ptxktrxtv +13-14 x: xxtxxxxdxxxxmhx +10-11 v: vvvdlvvvvlvvv +2-3 k: rtcdksdxk +17-18 w: zmhvwnndrjbvsmnhlw +11-12 m: dmmmmmmmmmml +7-8 g: gvndbzzbsjkpxg +9-16 c: cccggcqtdkcccccj +7-10 m: mqmmmmmmmmnmgbgmmbcq +5-13 c: pcbqcwcnjtvccccfgjx +3-8 f: ffpffffffffffff +9-11 n: cdndnntnnnnnnn +10-16 n: nnnnnnncntnnnmnwnn +6-10 r: rrrwrrrrpn +4-8 v: vcwsvvxvwvcvvh +4-5 g: ggghdg +8-10 v: vmvdvlrvtvtvvjvvd +13-16 j: vrgplxbmgwvljtjgzbw +2-9 s: ssssssnskss +18-20 v: vvvvvvvvvvvldvvvvfvv +8-13 r: rrrprrrhrrrgj +4-6 g: dgjkrhwggg +2-3 n: nnnw +7-11 s: sssscsgsssqs +7-10 c: cccccctccg +9-16 m: mmhmjwzmmgmdmnmmmm +1-4 c: ccvcc +11-15 m: mmmmmmmmmlvmrmmm +10-11 l: zgcnmxlplml +2-11 m: fmsmnmlhmmmmmbgm +6-7 g: hqggggggg +7-9 z: zzzzkznxzzzz +3-5 n: ngntcnnpsdnqnnmnrj +3-9 h: dhhhhfgkthxh +14-15 x: zbxmkfmtznnnxjjtsr +4-7 l: tlklltcll +5-10 s: hffslrssgrsrcwncmqw +5-12 f: ffffjffpfpfp +5-6 h: hhwhhhh +8-10 v: vvvvvzvvvfv +1-8 n: wqnnnglnrnln +11-15 q: qqqqqqqfgqnqqqnwql +2-7 d: wkdwddt +2-5 m: mxmmm +8-15 d: ddddddddddddddxld +6-9 s: sssssgscds +6-8 z: zzwzzzzzz +4-8 x: xfxxxxkxsckrwg +1-9 b: pnlbgtsfwp +6-10 l: dfrrklhrvp +15-16 n: qnnnnnnnnnnnnnlh +16-18 z: zzfczncnztzzkzzzqzz +12-13 r: rwrrqnrrrrrrkrrr +1-2 q: qkqqq +4-8 f: sfpffjfgfw +5-10 q: qqqqqqqqlqq +13-14 q: qqqqqqqqqqqqqd +1-6 v: vvvvtvmqfwvgjjgbtvm +3-8 f: dfffkdjftf +1-4 t: hgtttttttw +5-7 k: kzmkzkmkr +15-17 w: wwwwwwwwwwwwwwxpw +2-14 z: mnzkfkzbzhwfzbkzzzz +13-15 x: xtgxxqxxxxxxvpgrxx +9-10 q: qcqqvqsqssqqq +8-12 g: qghgrlggggggggszg +15-20 l: llllllwllllvllllllll +2-4 b: whhdhlzp +6-7 t: tttxtxct +1-9 g: bgtnvszsk +6-8 g: gggggggg +7-10 z: zqzzzzzszzpzkz +4-8 x: xxxxxxxxx +7-8 n: ztnnnknhpknvzn +11-12 g: gggggzpgxggg +10-13 b: bbbjbbbdbwbbrbq +1-5 w: whzmwwzwwlwwl +4-12 p: pbppdzcxhlllpxqxjm +8-10 f: fzbfpfrdfzff +6-7 v: vvvvrxh +1-4 t: gtjt +3-5 b: jzhpbbbwp +1-2 t: dtttn +3-9 r: dqrfrtvsxbrjwbrg +4-5 p: spppxqpb +4-12 c: sntctfrcsmwcmrlst +1-13 n: nnnnnnnncnnncfnn +4-5 z: zzzzz +11-15 n: nwnnsnfnntnnsnnxnnn +3-13 f: ffnfffffffsfffffff +11-12 b: brfbbqtpbhzrd +5-9 r: krrmrrrrjr +9-10 g: gggggggksc +6-12 m: mmmmmsmmmmth +11-12 w: wwwwwwwwwwww +10-11 x: xxxxxxpxxxs +3-8 j: qgzjmkqhqjszwxjj +4-6 g: kgggwgfg +16-18 r: rrdgrrrrrrrrrrrrrkfl +18-19 r: rrnrrrrrrrrrrrrrrrr +1-7 d: dprhvrdzdjxddd +3-4 p: ppxr +6-13 b: bbwbbbbbbbbhbbh +10-12 g: hrggghfkqtgswxdjcb +8-9 p: pcppppppm +3-4 w: vwlkwbwvp +11-15 f: fnhfffhfdffffffffff +2-7 c: kfccccrlc +9-17 z: zphgvhzrzzzwjzzczxf +3-4 v: vnxvkdrvvf +1-11 w: xxnlwlbzmpgwcw +10-12 v: vvvvvvxlvvvvvvvv +12-13 t: xtrctttpwptjb +6-7 z: zzzzzzz +3-19 m: fmgfmmjpfxmmprmmqhsm +18-19 m: fkmkpdrrbxzwgvdhqmm +2-3 h: xchwlphpkhlc +4-10 j: xrjjjjrjfjjjj +6-9 z: zzzzzvzzz +1-7 d: jdddddddd +4-9 x: xxxrxxxxxx +1-6 w: dwnwws +9-13 l: llllllljkllhlhlvx +4-7 t: tvsttbsqzcwzthtx +11-13 s: sbssrssssscsdsrss +5-6 n: bnnnncnznm +10-15 g: ggggrggggggggwggg +10-15 g: gggrfggxjgbgggjgs +3-5 v: vvvbvmvzvcv +2-5 r: rrrrrr +4-5 k: bkjkkkkf +4-8 z: mxddnzzjpbzm +2-3 r: frrkfzjrncrgpwsf +10-15 m: mmmmshmmmgmskcv +5-8 c: ctcchhczcq +7-8 b: skbqjbbwbncbtbb +6-7 d: ddddjjxgdd +6-13 v: tvcmvbvvvdvvvrzgk +5-10 x: xgsxdxqxxsxxjx +3-12 f: xfbqfffcftkh +4-5 j: wmjkhjj +7-11 n: nnnnpwpnnnrn +8-13 l: lqnlllllmlwll +8-12 s: sssssssssssssss +1-8 g: lggggggwgg +15-17 w: wwwwwwwwwwfwwwwwww +4-17 r: qrrlfhrrlrjrrrkcrrbr +4-5 n: rsrnplnttvxnnkhnvtxz +4-5 n: nnhts +5-6 x: xxxxxxn +1-4 s: gssss +4-6 p: qpppsgjppz +12-16 n: zcnkhqnnnnwtqnrnknnn +13-14 m: mmcmmmmmmmmmmn +9-11 d: kdpdddbdpgdddhd +3-8 k: krkbxgvq +2-6 t: tbhtslxhtfcphkwnth +3-8 z: gzzxzzzmjzzzz +4-5 c: cccwp +3-9 s: skszskstjs +4-10 l: qljlllzqlllvhlls +7-11 c: cccclccccccc +1-2 v: vgfv +14-17 m: hmmmmmmmmmmmmmmmm +2-4 p: pppp +2-3 c: cccs +2-3 k: xppklhkhsfw +5-7 m: mmmmzmqs +3-12 n: nnnqxdvbxnhnrnzfnnp +15-16 s: kssmjbzlwktbddltd +8-9 j: jjjjjjjjkntjh +3-5 g: ggvgpggggmggggg +6-11 t: rstjsmttmkdtttmttttp +5-6 r: rrrrbb +7-8 q: qqqqqtbbq +3-8 c: ccsccccbcccb +6-10 q: qplqqlmqqqq +5-6 v: vvvvvv +1-3 q: sqdqqqqgqqqqqqqq +11-12 j: lnjjjjpjjpwjjjjl +5-7 b: bsdsbbrbqbrpb +5-6 m: rmxmmmjdrvvmmmt +1-4 l: llfwh +1-2 d: hcsd +2-5 m: mmrjmnnmmmm +7-11 k: kkkwkbkkkkk +15-16 g: xsmrgbbgwzqrjgfk +7-8 x: xxxxxxxxxxx +3-7 n: nrmnnnndj +6-10 x: xxkzxpxxxwx +10-14 x: pxxxxxxpxxxxxxfxb +7-9 j: pjwjjjjjjjwp +9-10 r: rfspfrrlrf +1-5 r: rrrpfr +6-11 k: qjsqjnkckqfkcvkk +1-2 b: bbpqjnpbb +5-11 c: kcjxmstklbcjwktcwgk +2-3 h: phcshb +6-18 d: dddhdddddddvpdpdddd +3-7 t: qtkttttqtttn +8-10 j: jfjwjjjbsjjjj +9-11 m: mmmmmmfmmscm +3-4 v: ldvfvvllh +5-11 b: wbbbbvzmckbbtl +2-4 m: msmm +2-3 f: ffffvjff +3-13 c: pmchdcwhdwdnchs +7-12 s: sskdsssssssss +1-4 x: kwqtxnhhxp +13-14 n: nnnnnhnnnnnnnl +11-15 f: nrffwclmlgxgdblj +3-15 w: wvwwllsksktbbbdxmgmh +6-7 g: gggggtgg +12-13 r: rrrrrrrrrrjrrr +4-5 k: lkkkkkxv +8-10 h: hhhhhhhkhh +17-18 q: qqqqqqqqqzqvqqqqxvdq +3-6 w: wwvwsxj +8-15 z: zxczhwthhhzrzzpzfzs +3-5 q: qqqqk +11-18 z: zzzzzzzzzzlhbzzzzzz +6-8 m: mmmphqmt +2-4 h: hnsrkhv +4-9 x: xxxrxfxxvxwxx +1-4 d: ddsxjrmdnwswd +3-6 r: rprvrwrrnflvhnlrv +7-10 r: rrrrrrrcrwtrh +13-14 g: gntfgtrbgdfsgk +12-13 c: cccnbcccccjtkccl +2-3 f: fgsf +2-5 f: dfftfsrkz +6-8 p: wpppprmpp +8-9 k: kkkxkkkkdk +8-10 l: lrmlzpllllltlrblgcld +3-6 z: tfqzzzpz +4-5 r: nrrrrrj +5-10 l: llllsrnslglllqcl +10-17 j: jjjjhjjkjcjjjxjjhj +10-13 h: hhnlhhhhhhhhh +15-16 h: chrhphvhxhjphhxk +5-18 c: cccctcccccccccccccc +14-15 h: hhhhhhhhrhhhhxb +5-6 w: wwwtsdq +2-5 s: slsscz +8-9 f: fffffffdx +7-10 s: fdsssgkrpgssss +16-19 n: nnnnnnnnnnnnnnnnnnnn +8-18 d: dxdvkddjddddzddddgg +12-13 q: qqqqqvqqqqqvq +6-7 l: pvmnlfwzb +3-5 c: cfnclcfrccxstc +4-10 m: mmmjmmmmmmmm +15-17 s: sssssssssssssshsmss +8-10 q: qqwwktqtqsqtb +3-4 n: nbxnn +6-7 p: pppvpvr +1-5 h: dmqlb +9-15 g: gplxmjgdgjgzqlgkxhg +7-11 l: llsltxlllmblgp +7-8 h: hhhhhghhhw +12-13 x: xxxxxxxxxxxxx +2-7 m: tmxtdmmfgn +12-14 r: wrrrrrrmrrrwrn +10-16 t: tlttqdtttgcstttntt +2-10 z: zzzzzzzhzpzzzzzz +8-10 s: sssssssssss +5-7 z: zvzzzzzczzzq +12-13 c: scccwccccccccc +14-18 v: vvqvvvvvxvvvvvdvvv +14-16 v: vvvvvvvvvvvvvtvzv +4-9 d: zddgpddqwdtdd +7-11 l: xllvlzclflzlnhtls +6-7 l: lllllczl +4-12 s: slbsmstssscs +8-11 b: xbqbtjsfbbgq +5-15 r: frrrqwcnrrrrhrrqk +2-3 n: nmtxqfxnnnnnh +14-17 l: glwlzllglblwlmlll +10-12 g: ggggggnjggggg +9-10 b: bbbbbbbbkt +4-9 m: mcmmmmnfmwmwfmmljxmv +7-11 l: lxmllrqllwlhl +9-13 p: bppxpjpmpwcpppdprpp From 0d175c824fbd565794e5367145379f8ca759fa0a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 11:20:32 +0100 Subject: [PATCH 027/129] 2020: d02: ex2: add solution --- 2020/d02/ex2/ex2.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 2020/d02/ex2/ex2.py diff --git a/2020/d02/ex2/ex2.py b/2020/d02/ex2/ex2.py new file mode 100755 index 0000000..2e11cca --- /dev/null +++ b/2020/d02/ex2/ex2.py @@ -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() From 5f9288aa5f97ebb9aee9cb5d11fbb9717f02a349 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 15:49:22 +0100 Subject: [PATCH 028/129] 2019: d18: ex1: add input --- 2019/d18/ex1/input | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 2019/d18/ex1/input diff --git a/2019/d18/ex1/input b/2019/d18/ex1/input new file mode 100644 index 0000000..f376feb --- /dev/null +++ b/2019/d18/ex1/input @@ -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.#.#.......#.......#.......#.......#...............# +################################################################################# From 1014d1546b8c9748e0c87a8552b3e8efa0be2496 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 15:49:28 +0100 Subject: [PATCH 029/129] 2019: d18: ex1: add solution --- 2019/d18/ex1/ex1.py | 129 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100755 2019/d18/ex1/ex1.py diff --git a/2019/d18/ex1/ex1.py b/2019/d18/ex1/ex1.py new file mode 100755 index 0000000..6491052 --- /dev/null +++ b/2019/d18/ex1/ex1.py @@ -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() From 5929fd5f07d6c047214e4d91bdc65204e6341fa5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 16:43:38 +0100 Subject: [PATCH 030/129] 2019: d18: ex2: add input --- 2019/d18/ex2/input | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 2019/d18/ex2/input diff --git a/2019/d18/ex2/input b/2019/d18/ex2/input new file mode 100644 index 0000000..9596324 --- /dev/null +++ b/2019/d18/ex2/input @@ -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.#.#.......#.......#.......#.......#...............# +################################################################################# From 533fce5d69787a32ccc616e40a7ae86090e9315a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 16:43:49 +0100 Subject: [PATCH 031/129] 2019: d18: ex2: add solution --- 2019/d18/ex2/ex2.py | 131 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100755 2019/d18/ex2/ex2.py diff --git a/2019/d18/ex2/ex2.py b/2019/d18/ex2/ex2.py new file mode 100755 index 0000000..ec53d17 --- /dev/null +++ b/2019/d18/ex2/ex2.py @@ -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() From 8733c82b46c1c59c47bb821957bffd52e91d71cb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 18:16:20 +0100 Subject: [PATCH 032/129] 2019: d19: ex1: add input --- 2019/d19/ex1/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d19/ex1/input diff --git a/2019/d19/ex1/input b/2019/d19/ex1/input new file mode 100644 index 0000000..0647194 --- /dev/null +++ b/2019/d19/ex1/input @@ -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 From d868e9f5a909e44eb319f4d00917abba8f306a5b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 18:16:26 +0100 Subject: [PATCH 033/129] 2019: d19: ex1: add solution --- 2019/d19/ex1/ex1.py | 214 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100755 2019/d19/ex1/ex1.py diff --git a/2019/d19/ex1/ex1.py b/2019/d19/ex1/ex1.py new file mode 100755 index 0000000..0e1d70d --- /dev/null +++ b/2019/d19/ex1/ex1.py @@ -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() From e812fd424a1db5e8389fdfc3eecec51861b4a9db Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 18:16:38 +0100 Subject: [PATCH 034/129] 2019: d19: ex2: add input --- 2019/d19/ex2/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2019/d19/ex2/input diff --git a/2019/d19/ex2/input b/2019/d19/ex2/input new file mode 100644 index 0000000..0647194 --- /dev/null +++ b/2019/d19/ex2/input @@ -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 From 878b0a10d360d36765818c467d601ab0d85f7a96 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 2 Dec 2020 18:16:49 +0100 Subject: [PATCH 035/129] 2019: d19: ex2: add solution --- 2019/d19/ex2/ex2.py | 221 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100755 2019/d19/ex2/ex2.py diff --git a/2019/d19/ex2/ex2.py b/2019/d19/ex2/ex2.py new file mode 100755 index 0000000..138e45b --- /dev/null +++ b/2019/d19/ex2/ex2.py @@ -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() From 4125c20fb76d7b9c545a0a6e973dd103d1ad5018 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 3 Dec 2020 18:21:51 +0100 Subject: [PATCH 036/129] 2020: d03: ex1: add input --- 2020/d03/ex1/input | 323 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 2020/d03/ex1/input diff --git a/2020/d03/ex1/input b/2020/d03/ex1/input new file mode 100644 index 0000000..9256a36 --- /dev/null +++ b/2020/d03/ex1/input @@ -0,0 +1,323 @@ +...............#.#............. +##..#....................#...## +......#..#.#.....#..#.#.##..... +.........#...#..............#.# +............#.......##......... +...#.....#.....#...#.....#..#.. +..............#..##.#..#......# +.##.....#.....#......##.#...... +.#..........###....#...##....#. +.....#....#.#.......#......##.. +.#....#......#.......#........# +..#.#.......#..##.....##....... +...#.#....#.......#.......#...# +##.##...##..#......#.#.....#..# +.#.#.......#..#.#......#...#.#. +#.......##.......#...#......... +.....#......#.#.#.....#....##.. +.#.#........#....#..#..#....... +...#....#..###.........#.....#. +........#........#........#.... +..##..............#.....#.#..#. +.#...##.............#.#........ +....#..#...........#.......#... +..#....#.....................#. +#.#..................##......## +.#.##....#......#........#..... +.........##.....#....#...##..#. +#..........#..#.#.............# +.........#...#.#.#.#..##..##... +#...#.....#..#..#....#...#..... +..##.....#..................#.. +#..###.....#....#.......#..#... +...##.##..#............#......# +........###.........###......#. +#..##....#.........#.........#. +....#.....................#.... +#..#..##..#..####.##..#.....##. +..#...#.#....#....##.....#..... +...#.#.........#.....#.#....... +....#................#..#...##. +....#..#..........#...#.#.##... +........#..##............#....# +...#......##..........#.##...#. +.......##...................... +.......##..........#....#.#...# +......###.##..##..#....#...#..# +#.#...........##.....#........# +..#...........#..###....#.#.#.. +........#...........#......##.. +.........#...##.###...###..#... +.....#.....#..##.........##.... +...##..............#.....#...## +.##....#.......###.....#....... +.#...........##.............##. +......#..#..##.##......#......# +........###........#......#.#.. +#.#....#.....#........#......#. +.##..#.........##...##....#.... +.....#.........#...##.....#.... +.............#........###....#. +......#.......#.#........#.#... +..#....#.#...#....#...#.#...##. +#...#......##..##......#.##.### +...##.#....#...#....#.........# +...#..####.....##.#..#.#...##.. +##.#..#....##......#......##... +###.........#.#..#.#.....#..... +...#........#..##...#.#.#..#.#. +...###..#.###.#...#............ +....................###........ +...........#...........#....... +#..............#.#.........###. +....................##.....#..# +#.#.....#.......#...#.......... +.#...#......#....##...#...#.... +.....#.##..................###. +.........#.#..#.#......#....... +.......#.....##..#.##.#........ +..#..........#.###.....#....#.. +......#.............#.#........ +........##....#........#....... +...#.............#....#.#...... +#........#..####.....#.....#.#. +.##......##...#........#..#.#.. +....##....#...#...#..##...#.#.. +#.##...###..#....##.#.......... +....#.#...#.#...#..##.###...#.. +#.....##..#..#....#.#.....##... +.#..#..........##.#.....##..... +.#..#........#.#.#.#........... +.#..#.....#...........#...#.... +...#......##..........##..#.... +...#..#....#.##...#..#.....###. +#.#....#.....##................ +#..#......#.#.#.......#........ +......#....#.#....#..##....#..# +.#.....#.#....###.##.........#. +.###..#.....#........#.#....... +.#...#......#..#.#......#.....# +#...............####...#.....#. +.......#..........##.#........# +#........##....##.....###..##.. +#..#.....#..##.....#....#..#... +#.....#.......##......#.#.....# +#.##..#......##..#............. +##...#.....#........##......... +....#..##....#...#.......#.#... +....#...#...##..#....#..#...#.. +..............#.#...#....###... +...#....#..##...##..#....##.... +#.##.#..#..#......#.#.#.#...#.. +.......#..#..##........#......# +##.#....#....##.#......##.#.... +.#...#..............#........#. +.#.#....#.........#............ +.#..#..###.............#....#.. +#......#...#.#..##..#...#....#. +.......................#...#.#. +.............#..#...##......... +..#.#..#....#....#........#.... +#......#.##..#...#.#........... +.....#....#...........##.#..#.. +..#.#.....#..............#.#... +#.......#.....#................ +#..............#...#....#...#.. +...#...##..#..#............#... +......###.....................# +.........#.......##..#....#.... +........#...#.##..#.##......#.. +....###..#.#...#...#..#.#...### +##...#...##.#...#.#...#.#....#. +.........#...#.....###......... +...#........##..#.......##..... +.#.......##.........#.....##..# +.#..................#...#...... +.##..#..#.#.....#.###.......... +...#.....##..#.........#...#... +.#......#.#.......#.#.......... +.........#.#...#..........#.#.. +#..........#.##..#.##....#..... +.#.#....#.....#..##.....#...#.. +..#........##...##..#..#....#.. +#...........##....#..###....#.. +...........##.........####...#. +..#........###...#.#.........#. +.#...............#.##.#.#...#.. +.#.##..#.....#.#.....##..#..... +...#...#..#.##.##...#.......##. +..#...#...#......##.##.##...#.. +##....#...#...#...............# +...##...........#......#..#.#.. +#.........#......#.#.##.....#.. +........#..#.........##........ +..#.#....###.....##..#...#..... +.........#...#.......#.....##.. +##.....................#...##.. +.#.#..#......#................. +.....###..#......#..###..#..... +...#.....##.........#......#..# +......##.....#...#........#.#.. +..#.#...#......#...#.##.##..... +...#..........#...#.......#..## +.###........#........##........ +..#.#.#..........#.#...##...... +.........#........#......###..# +....##..#.........#...........# +..####..#............##.......# +.....##.#..##.........#...#.#.. +...#.........#.....#.....#..... +.......#...#..#...##.........#. +...#...#..#...#....#..#........ +#............##.##...#......... +.#.#.....#.......####.....#.... +..............#......#.#....... +..............#...........#...# +#...#........###....#.#....#.#. +##.#..#..#......#......#.#.#... +.#..#.....#..#.#..#.#.......##. +......##.#...#...#......#...#.. +#...........##....#.#.......... +....#.......###.#...#.......... +.......................#.....#. +........#...#..#...#.#.#.#.#... +.#.#...........#......##...#... +.........................#..... +.................#.##.#...##... +...#...##.....#.....##....#.#.. +...#...#...................#... +...#..#..#...#...#....#........ +#....#...#.....#............... +.......#...........#...#....... +....#....#.....##.......#...... +.......#..........##........... +.#.#........#..##....#......#.. +.....#.......#.#.........#...#. +.#..####.#.#...............#..# +.....###..#..#..........#.#..## +..#.......#...#.....##..#..#.#. +#....#......#.................. +........#.##.#....#...........# +....#.#....##..#.#.....##...... +...#..#.......#....#.....#.#.#. +#...#......#.....#.#..........# +....#....#...............#..... +..###......................###. +.##....#..#.......###.....#..#. +..###............#........#.##. +.#........#......#.....#..#.... +....#..##...#...#.###.......#.# +.......#.##...........#.#..#... +.....#...##.................... +....#....#...##......#......... +..#............##....###.#...#. +.#........#...............#.... +#..#.#.##.........#..##....##.. +#.#....#..#.##....##...#.#..... +.....#.....##....#.#........#.. +#..#...#...#....#....#......... +...#........#..#.#.....##...... +..#...#...#................##.. +#........#.#.##.......#.#...#.. +#......#..####.##.....#.#..#.#. +............#..#.#....#......## +..#.....##....#...#.#.......... +...#...#.........#...#.#....... +.###..#.......##.##.....#.#.#.. +...#....#...............##.#... +....##..#..#..#.#......##.....# +#.#..............##...##...#### +.....#.##...#.#...............# +.##.....#.........#.......#.#.# +#.#..#.....#.......#.......#..# +...#.#.....#.....#......#...... +.......#....#..#.#..........#.. +......#......#.##...#.......... +.....#.......###...#...#.#..... +#..#.#.........#.....#.##....#. +..#.#.........#..#..#..#.....#. +.#..##..#..#....#......#.##..#. +...##......###.....#.##.##..... +.#.....#...#..#...#............ +##..##..#.##....#..#........... +...#..##..#..#.............#.## +...............##............#. +..#.....##........##.#...#....# +.#.#...#.#.#..#.#.....#....#... +.#....#...............#..#..... +....#.##..#....#......#...###.. +#................###...#.#..... +...#...#......##..#.#....#..... +.#....#....#.#...##............ +....#...##..#..#........#.##... +..##.....#..#..##.............. +..#..##..#.#..##....#....#....# +...##.............#............ +#....#....#.#........#.....##.# +.....#..#.#.....####...###..... +................#......#....... +.....#.#.#.#.#....#..#........# +.##.#...#.#.......##....#....#. +.....#........#................ +..#.....#..#...#..#...........# +.#.....#...##.....##..#.#....## +......#.......#..#......##.#... +#.#..........#.##.#........#... +...#..#.............#.......... +#..#..#..........#..##.#....... +.#..#...............####..#.... +.......#.....#......#.....#.#.. +.#...............#...#......... +.#..#..........#..#.#..##..#..# +......##..#.....#..#......###.. +..........#...#..#.......#..... +.#.#.#..#.....#.##.#...#..#.... +........#.......#.....#.#...... +......#.....##.....#....##.#... +...............#......#.......# +..#.#...#.....#.#...##......#.. +#.#.........#.#...#........#### +#..........##..#..#........##.. +.............#..#.......##.#..# +..#........#.#....#........#.#. +.#......####..#..#............. +............###.......#.#..#... +#.##......##...#...#.........#. +....##.#.#.#......#....#..#...# +.#..#.#....#...#.........#..... +#...#.....##............#...#.. +#.#...#..#.................#... +............#.#..#.....#.#.#..# +...................#....#.##... +.....#...#.#....#....#.#......# +.......##.#.#......##.......... +.#..#...##.#...#..#......#..... +......#.#..#..###..##..##...... +.#.#.#.#.....#...###.....#..#.. +.#....#.....#.......#.......#.. +..........##.........####...... +.#.#.............#..#.#...#.... +........#........##...#.#....#. +........#...................... +..#.#....#...............#...## +.......#.#...#..#.....##......# +.#...#....#..........##........ +.#.........#.#............##... +.....#......##...#.......#..#.. +#.#..#.............#...#...#... +......#.......#............#... +...........##....#......##..... +.#.#..#.....................#.. +##..##.....###..##.#........... +...##......##....#...##.....#.. +#...#.##.............#......... +......#..#.........###.#......# +#.#.....#.....................# +....#####.....##........#.#..#. +...........##..##.###.......... +..........##.....#........#...# +.......#..#......#.....##..##.# +.....##.#........#.........#... +......##......................# +.#.......#.#.#............#..#. +.....##.#.......#.#........#... From 93dfa3ab8c66ae8da3f6f15bdb93a5a6d30e2df0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 3 Dec 2020 18:21:57 +0100 Subject: [PATCH 037/129] 2020: d03: ex1: add solution --- 2020/d03/ex1/ex1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 2020/d03/ex1/ex1.py diff --git a/2020/d03/ex1/ex1.py b/2020/d03/ex1/ex1.py new file mode 100755 index 0000000..c964770 --- /dev/null +++ b/2020/d03/ex1/ex1.py @@ -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() From 9c6b5bf887482c3318b6f6e24dc0f53971208929 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 3 Dec 2020 18:22:04 +0100 Subject: [PATCH 038/129] 2020: d03: ex2: add input --- 2020/d03/ex2/input | 323 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 2020/d03/ex2/input diff --git a/2020/d03/ex2/input b/2020/d03/ex2/input new file mode 100644 index 0000000..9256a36 --- /dev/null +++ b/2020/d03/ex2/input @@ -0,0 +1,323 @@ +...............#.#............. +##..#....................#...## +......#..#.#.....#..#.#.##..... +.........#...#..............#.# +............#.......##......... +...#.....#.....#...#.....#..#.. +..............#..##.#..#......# +.##.....#.....#......##.#...... +.#..........###....#...##....#. +.....#....#.#.......#......##.. +.#....#......#.......#........# +..#.#.......#..##.....##....... +...#.#....#.......#.......#...# +##.##...##..#......#.#.....#..# +.#.#.......#..#.#......#...#.#. +#.......##.......#...#......... +.....#......#.#.#.....#....##.. +.#.#........#....#..#..#....... +...#....#..###.........#.....#. +........#........#........#.... +..##..............#.....#.#..#. +.#...##.............#.#........ +....#..#...........#.......#... +..#....#.....................#. +#.#..................##......## +.#.##....#......#........#..... +.........##.....#....#...##..#. +#..........#..#.#.............# +.........#...#.#.#.#..##..##... +#...#.....#..#..#....#...#..... +..##.....#..................#.. +#..###.....#....#.......#..#... +...##.##..#............#......# +........###.........###......#. +#..##....#.........#.........#. +....#.....................#.... +#..#..##..#..####.##..#.....##. +..#...#.#....#....##.....#..... +...#.#.........#.....#.#....... +....#................#..#...##. +....#..#..........#...#.#.##... +........#..##............#....# +...#......##..........#.##...#. +.......##...................... +.......##..........#....#.#...# +......###.##..##..#....#...#..# +#.#...........##.....#........# +..#...........#..###....#.#.#.. +........#...........#......##.. +.........#...##.###...###..#... +.....#.....#..##.........##.... +...##..............#.....#...## +.##....#.......###.....#....... +.#...........##.............##. +......#..#..##.##......#......# +........###........#......#.#.. +#.#....#.....#........#......#. +.##..#.........##...##....#.... +.....#.........#...##.....#.... +.............#........###....#. +......#.......#.#........#.#... +..#....#.#...#....#...#.#...##. +#...#......##..##......#.##.### +...##.#....#...#....#.........# +...#..####.....##.#..#.#...##.. +##.#..#....##......#......##... +###.........#.#..#.#.....#..... +...#........#..##...#.#.#..#.#. +...###..#.###.#...#............ +....................###........ +...........#...........#....... +#..............#.#.........###. +....................##.....#..# +#.#.....#.......#...#.......... +.#...#......#....##...#...#.... +.....#.##..................###. +.........#.#..#.#......#....... +.......#.....##..#.##.#........ +..#..........#.###.....#....#.. +......#.............#.#........ +........##....#........#....... +...#.............#....#.#...... +#........#..####.....#.....#.#. +.##......##...#........#..#.#.. +....##....#...#...#..##...#.#.. +#.##...###..#....##.#.......... +....#.#...#.#...#..##.###...#.. +#.....##..#..#....#.#.....##... +.#..#..........##.#.....##..... +.#..#........#.#.#.#........... +.#..#.....#...........#...#.... +...#......##..........##..#.... +...#..#....#.##...#..#.....###. +#.#....#.....##................ +#..#......#.#.#.......#........ +......#....#.#....#..##....#..# +.#.....#.#....###.##.........#. +.###..#.....#........#.#....... +.#...#......#..#.#......#.....# +#...............####...#.....#. +.......#..........##.#........# +#........##....##.....###..##.. +#..#.....#..##.....#....#..#... +#.....#.......##......#.#.....# +#.##..#......##..#............. +##...#.....#........##......... +....#..##....#...#.......#.#... +....#...#...##..#....#..#...#.. +..............#.#...#....###... +...#....#..##...##..#....##.... +#.##.#..#..#......#.#.#.#...#.. +.......#..#..##........#......# +##.#....#....##.#......##.#.... +.#...#..............#........#. +.#.#....#.........#............ +.#..#..###.............#....#.. +#......#...#.#..##..#...#....#. +.......................#...#.#. +.............#..#...##......... +..#.#..#....#....#........#.... +#......#.##..#...#.#........... +.....#....#...........##.#..#.. +..#.#.....#..............#.#... +#.......#.....#................ +#..............#...#....#...#.. +...#...##..#..#............#... +......###.....................# +.........#.......##..#....#.... +........#...#.##..#.##......#.. +....###..#.#...#...#..#.#...### +##...#...##.#...#.#...#.#....#. +.........#...#.....###......... +...#........##..#.......##..... +.#.......##.........#.....##..# +.#..................#...#...... +.##..#..#.#.....#.###.......... +...#.....##..#.........#...#... +.#......#.#.......#.#.......... +.........#.#...#..........#.#.. +#..........#.##..#.##....#..... +.#.#....#.....#..##.....#...#.. +..#........##...##..#..#....#.. +#...........##....#..###....#.. +...........##.........####...#. +..#........###...#.#.........#. +.#...............#.##.#.#...#.. +.#.##..#.....#.#.....##..#..... +...#...#..#.##.##...#.......##. +..#...#...#......##.##.##...#.. +##....#...#...#...............# +...##...........#......#..#.#.. +#.........#......#.#.##.....#.. +........#..#.........##........ +..#.#....###.....##..#...#..... +.........#...#.......#.....##.. +##.....................#...##.. +.#.#..#......#................. +.....###..#......#..###..#..... +...#.....##.........#......#..# +......##.....#...#........#.#.. +..#.#...#......#...#.##.##..... +...#..........#...#.......#..## +.###........#........##........ +..#.#.#..........#.#...##...... +.........#........#......###..# +....##..#.........#...........# +..####..#............##.......# +.....##.#..##.........#...#.#.. +...#.........#.....#.....#..... +.......#...#..#...##.........#. +...#...#..#...#....#..#........ +#............##.##...#......... +.#.#.....#.......####.....#.... +..............#......#.#....... +..............#...........#...# +#...#........###....#.#....#.#. +##.#..#..#......#......#.#.#... +.#..#.....#..#.#..#.#.......##. +......##.#...#...#......#...#.. +#...........##....#.#.......... +....#.......###.#...#.......... +.......................#.....#. +........#...#..#...#.#.#.#.#... +.#.#...........#......##...#... +.........................#..... +.................#.##.#...##... +...#...##.....#.....##....#.#.. +...#...#...................#... +...#..#..#...#...#....#........ +#....#...#.....#............... +.......#...........#...#....... +....#....#.....##.......#...... +.......#..........##........... +.#.#........#..##....#......#.. +.....#.......#.#.........#...#. +.#..####.#.#...............#..# +.....###..#..#..........#.#..## +..#.......#...#.....##..#..#.#. +#....#......#.................. +........#.##.#....#...........# +....#.#....##..#.#.....##...... +...#..#.......#....#.....#.#.#. +#...#......#.....#.#..........# +....#....#...............#..... +..###......................###. +.##....#..#.......###.....#..#. +..###............#........#.##. +.#........#......#.....#..#.... +....#..##...#...#.###.......#.# +.......#.##...........#.#..#... +.....#...##.................... +....#....#...##......#......... +..#............##....###.#...#. +.#........#...............#.... +#..#.#.##.........#..##....##.. +#.#....#..#.##....##...#.#..... +.....#.....##....#.#........#.. +#..#...#...#....#....#......... +...#........#..#.#.....##...... +..#...#...#................##.. +#........#.#.##.......#.#...#.. +#......#..####.##.....#.#..#.#. +............#..#.#....#......## +..#.....##....#...#.#.......... +...#...#.........#...#.#....... +.###..#.......##.##.....#.#.#.. +...#....#...............##.#... +....##..#..#..#.#......##.....# +#.#..............##...##...#### +.....#.##...#.#...............# +.##.....#.........#.......#.#.# +#.#..#.....#.......#.......#..# +...#.#.....#.....#......#...... +.......#....#..#.#..........#.. +......#......#.##...#.......... +.....#.......###...#...#.#..... +#..#.#.........#.....#.##....#. +..#.#.........#..#..#..#.....#. +.#..##..#..#....#......#.##..#. +...##......###.....#.##.##..... +.#.....#...#..#...#............ +##..##..#.##....#..#........... +...#..##..#..#.............#.## +...............##............#. +..#.....##........##.#...#....# +.#.#...#.#.#..#.#.....#....#... +.#....#...............#..#..... +....#.##..#....#......#...###.. +#................###...#.#..... +...#...#......##..#.#....#..... +.#....#....#.#...##............ +....#...##..#..#........#.##... +..##.....#..#..##.............. +..#..##..#.#..##....#....#....# +...##.............#............ +#....#....#.#........#.....##.# +.....#..#.#.....####...###..... +................#......#....... +.....#.#.#.#.#....#..#........# +.##.#...#.#.......##....#....#. +.....#........#................ +..#.....#..#...#..#...........# +.#.....#...##.....##..#.#....## +......#.......#..#......##.#... +#.#..........#.##.#........#... +...#..#.............#.......... +#..#..#..........#..##.#....... +.#..#...............####..#.... +.......#.....#......#.....#.#.. +.#...............#...#......... +.#..#..........#..#.#..##..#..# +......##..#.....#..#......###.. +..........#...#..#.......#..... +.#.#.#..#.....#.##.#...#..#.... +........#.......#.....#.#...... +......#.....##.....#....##.#... +...............#......#.......# +..#.#...#.....#.#...##......#.. +#.#.........#.#...#........#### +#..........##..#..#........##.. +.............#..#.......##.#..# +..#........#.#....#........#.#. +.#......####..#..#............. +............###.......#.#..#... +#.##......##...#...#.........#. +....##.#.#.#......#....#..#...# +.#..#.#....#...#.........#..... +#...#.....##............#...#.. +#.#...#..#.................#... +............#.#..#.....#.#.#..# +...................#....#.##... +.....#...#.#....#....#.#......# +.......##.#.#......##.......... +.#..#...##.#...#..#......#..... +......#.#..#..###..##..##...... +.#.#.#.#.....#...###.....#..#.. +.#....#.....#.......#.......#.. +..........##.........####...... +.#.#.............#..#.#...#.... +........#........##...#.#....#. +........#...................... +..#.#....#...............#...## +.......#.#...#..#.....##......# +.#...#....#..........##........ +.#.........#.#............##... +.....#......##...#.......#..#.. +#.#..#.............#...#...#... +......#.......#............#... +...........##....#......##..... +.#.#..#.....................#.. +##..##.....###..##.#........... +...##......##....#...##.....#.. +#...#.##.............#......... +......#..#.........###.#......# +#.#.....#.....................# +....#####.....##........#.#..#. +...........##..##.###.......... +..........##.....#........#...# +.......#..#......#.....##..##.# +.....##.#........#.........#... +......##......................# +.#.......#.#.#............#..#. +.....##.#.......#.#........#... From 4121ef0880a7632450359f9b1ce7cc427cf7b8d8 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 3 Dec 2020 18:22:09 +0100 Subject: [PATCH 039/129] 2020: d03: ex2: add solution --- 2020/d03/ex2/ex2.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 2020/d03/ex2/ex2.py diff --git a/2020/d03/ex2/ex2.py b/2020/d03/ex2/ex2.py new file mode 100755 index 0000000..c061deb --- /dev/null +++ b/2020/d03/ex2/ex2.py @@ -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() From dd8a4569d26f85dca3ba35d40e0c3ff432b12bee Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 4 Dec 2020 09:50:17 +0100 Subject: [PATCH 040/129] 2020: d04: ex1: add input --- 2020/d04/ex1/input | 1069 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1069 insertions(+) create mode 100644 2020/d04/ex1/input diff --git a/2020/d04/ex1/input b/2020/d04/ex1/input new file mode 100644 index 0000000..710a26b --- /dev/null +++ b/2020/d04/ex1/input @@ -0,0 +1,1069 @@ +byr:2010 pid:#1bb4d8 eyr:2021 hgt:186cm iyr:2020 ecl:grt + +pid:937877382 eyr:2029 +ecl:amb hgt:187cm iyr:2019 +byr:1933 hcl:#888785 + +ecl:hzl +eyr:2020 +hcl:#18171d +iyr:2019 hgt:183cm +byr:1935 + +hcl:#7d3b0c hgt:183cm cid:135 +byr:1992 eyr:2024 iyr:2013 pid:138000309 +ecl:oth + +ecl:hzl +hgt:176cm pid:346059944 byr:1929 cid:150 eyr:1924 hcl:#fffffd iyr:2016 + +iyr:2011 +cid:99 ecl:amb +eyr:2030 hcl:#18171d +hgt:165cm pid:897123249 byr:1948 + +hcl:#cfa07d pid:827609097 ecl:gry iyr:2017 byr:1963 +eyr:2029 hgt:72in + +hcl:#6b5442 eyr:2028 iyr:2016 ecl:hzl +hgt:152cm +pid:432183209 byr:1984 + +hgt:169cm hcl:#888785 ecl:hzl pid:626107466 byr:1929 iyr:2013 cid:217 +eyr:2026 + +hcl:#bdb95d byr:1935 eyr:2023 ecl:blu iyr:2011 cid:90 hgt:64cm +pid:155167914 + +iyr:2017 +byr:1943 cid:56 +hcl:#888785 hgt:193cm pid:621305634 +ecl:amb +eyr:2024 + +ecl:gry +hcl:#a97842 pid:936999610 cid:169 byr:1991 eyr:2029 hgt:175cm iyr:2017 + +hcl:#866857 ecl:gry +byr:1975 hgt:71in +pid:180628540 eyr:2020 +iyr:2017 + +hcl:#cfa07d hgt:153cm byr:1962 cid:325 +iyr:2018 eyr:2020 +ecl:amb pid:579364506 + +hcl:#6b5442 iyr:2010 ecl:amb byr:2001 +eyr:2020 pid:406219444 +hgt:173cm + +pid:#430c70 +ecl:gry iyr:2018 hcl:#866857 eyr:2021 cid:97 byr:1997 +hgt:75cm + +iyr:2023 pid:#518780 +eyr:2034 +ecl:zzz +hgt:72cm +hcl:z byr:2010 + +pid:1961614335 hcl:#c0946f hgt:157 ecl:grn eyr:2031 byr:1972 iyr:1992 + +cid:142 +eyr:2022 ecl:amb +hgt:68in +hcl:#6b5442 byr:1927 pid:112372155 iyr:2012 + +byr:1972 +hgt:169cm +hcl:#888785 +cid:75 iyr:2015 eyr:2021 ecl:oth +pid:7889059161 + +ecl:brn +iyr:2020 +eyr:2026 hgt:151cm byr:1961 pid:468038868 hcl:#18171d + +ecl:blu +hcl:#b6652a +byr:1959 +hgt:151cm cid:109 pid:708689901 +eyr:2026 iyr:2012 + +ecl:grt byr:2024 iyr:1995 pid:225263933 hcl:z +eyr:2040 hgt:127 cid:162 + +pid:683129831 cid:144 +hcl:#a97842 hgt:155cm eyr:2030 byr:1962 +iyr:2015 +ecl:oth + +byr:2009 hcl:#866857 cid:329 iyr:1955 +eyr:1994 pid:085929595 + +byr:1940 +pid:936748944 hgt:160cm eyr:2024 iyr:2013 cid:205 +ecl:grn hcl:#c0946f + +hgt:193in cid:161 iyr:1984 +pid:#f82e35 +byr:2018 +hcl:b1a551 eyr:2014 ecl:#4d2d5b + +byr:1978 +iyr:2011 hgt:172cm hcl:#efcc98 ecl:brn pid:759624394 eyr:2020 + +eyr:2020 pid:622444743 +hcl:#a97842 +ecl:gry iyr:2014 hgt:157cm byr:1980 + +hgt:181cm eyr:2020 +iyr:2014 +hcl:#602927 ecl:brn byr:1934 + +hgt:188cm +ecl:blu eyr:2029 pid:757878469 hcl:#b6652a iyr:2017 + +byr:1995 ecl:blu hcl:#341e13 eyr:2027 iyr:2020 pid:283341241 +hgt:174cm + +byr:1960 iyr:2012 hcl:dc007d eyr:2011 hgt:166cm +pid:9889788504 +ecl:#a9b3a1 + +ecl:hzl hgt:70in pid:620966688 iyr:1998 hcl:z +eyr:2022 + +hgt:187cm cid:190 pid:818634983 byr:1925 ecl:gry hcl:#ceb3a1 +eyr:2021 iyr:2015 + +hcl:#c0946f iyr:2017 +byr:1953 eyr:2030 hgt:67in pid:085876735 ecl:hzl + +pid:205284134 +hcl:#cfa07d byr:1987 hgt:167cm +eyr:2022 ecl:oth iyr:2020 + +iyr:2018 +hgt:180cm pid:232535961 eyr:2027 byr:1999 +hcl:#18171d ecl:oth + +cid:342 hgt:171cm ecl:blu byr:1920 hcl:#18171d eyr:2023 iyr:2012 +pid:353601791 + +byr:1956 +ecl:brn pid:141896408 iyr:2012 cid:116 eyr:2028 hgt:164cm +hcl:#866857 + +hcl:#fffffd ecl:oth eyr:2030 hgt:67in pid:855777018 byr:1975 +iyr:2012 + +ecl:blu pid:45257034 hcl:#c5447e iyr:1928 cid:212 byr:1974 + +pid:080116868 cid:97 eyr:2021 iyr:2020 ecl:grn byr:1987 hgt:62in hcl:#efcc98 + +eyr:2027 hcl:#efcc98 iyr:2020 ecl:amb cid:111 +pid:143966954 +hgt:165cm + +iyr:2015 byr:1941 pid:798564127 +hgt:183cm ecl:oth eyr:2020 + +byr:1999 +iyr:2017 hcl:#ceb3a1 +pid:640883740 hgt:164cm +cid:105 ecl:hzl +eyr:2022 + +iyr:2014 eyr:2023 +ecl:grn hcl:#ceb3a1 +hgt:188cm byr:1981 pid:185076942 cid:342 + +hgt:150cm +iyr:2013 eyr:2035 cid:184 hcl:#341e13 pid:#e2dd63 byr:2014 ecl:brn + +eyr:2024 iyr:2015 ecl:brn hgt:76in +hcl:#866857 byr:1958 +pid:886486245 + +ecl:amb cid:113 byr:1931 pid:087380735 +iyr:2010 +eyr:2028 +hgt:161cm + +byr:1926 eyr:2024 iyr:2012 pid:036335738 hcl:#c0946f hgt:153cm ecl:brn + +hcl:bf952a +hgt:169in +eyr:1925 pid:166cm iyr:2028 ecl:lzr byr:1938 + +hgt:154cm hcl:#733820 ecl:oth iyr:2016 +byr:1925 +eyr:2020 pid:590365390 + +eyr:2029 hgt:166cm pid:670283165 +hcl:#ceb3a1 iyr:2018 +byr:1955 +ecl:gry + +hgt:181cm +iyr:2016 hcl:#866857 byr:1933 +eyr:2028 ecl:blu + +hgt:184cm +cid:138 hcl:#623a2f +pid:081880232 +byr:1929 ecl:hzl eyr:2030 +iyr:2015 + +pid:825698872 +eyr:2026 hgt:181cm iyr:2015 hcl:#866857 byr:1950 ecl:gry + +eyr:2022 byr:2002 iyr:2013 hcl:#fffffd ecl:hzl pid:687380398 +hgt:173cm + +byr:2016 ecl:zzz pid:0514910377 hcl:ebe8b2 eyr:2025 +iyr:2011 hgt:183cm + +ecl:amb hgt:67in +pid:602547016 byr:1985 +eyr:2021 +iyr:2014 + +iyr:2014 eyr:2020 ecl:grn pid:642261584 +byr:1970 hgt:190cm cid:278 hcl:#7d3b0c + +eyr:2035 cid:226 hcl:64ac73 +byr:2007 +pid:176cm ecl:#927fbf iyr:2006 + +iyr:2019 eyr:2026 ecl:brn hgt:162cm +cid:108 +hcl:#ceb3a1 pid:774441166 byr:1951 + +hgt:166cm eyr:2024 hcl:#b6652a byr:1934 pid:260873380 iyr:2016 + +hcl:z +iyr:2015 ecl:blu +eyr:2040 byr:1927 pid:431855667 +hgt:173cm +cid:209 + +eyr:2034 cid:139 +ecl:#cb7564 +byr:2023 hgt:172in iyr:2027 pid:2877047600 + +ecl:brn +cid:125 hcl:#888785 +iyr:2011 pid:739399822 hgt:184cm byr:1989 + +hcl:#c0946f +pid:891125961 +hgt:175cm +iyr:2010 eyr:2027 ecl:gry +byr:1930 + +hgt:164cm byr:1935 eyr:2023 pid:684366743 +ecl:oth +hcl:#18171d iyr:2013 + +hcl:#341e13 hgt:64in byr:1959 ecl:#c53bbb iyr:2014 eyr:2029 pid:174cm + +eyr:1943 ecl:#e52638 +hcl:06a964 byr:1959 cid:342 iyr:2029 hgt:178in pid:150cm + +byr:1966 hcl:#733820 iyr:2020 +ecl:gry eyr:2021 pid:229789071 + +pid:363947487 +ecl:blu +hcl:#623a2f +byr:1972 +iyr:2017 hgt:184cm +eyr:2023 + +ecl:oth pid:460855562 +iyr:2010 cid:148 hcl:z hgt:74cm byr:2005 + +eyr:2027 iyr:2017 hgt:172cm +byr:1975 +ecl:amb cid:97 hcl:#c0946f pid:591950054 + +eyr:2022 ecl:oth hgt:185cm +hcl:#6b5442 +byr:1978 +iyr:2018 pid:849124937 cid:78 + +iyr:1927 hgt:121 +eyr:2020 ecl:#c73b1a hcl:#cfa07d pid:4505701953 byr:2020 +cid:235 + +hgt:183cm hcl:#341e13 iyr:2019 byr:1932 ecl:#144539 +pid:184cm eyr:1954 + +iyr:2020 cid:332 byr:1930 hcl:#6b5442 hgt:168cm ecl:amb +eyr:2023 pid:332084752 + +ecl:blu +byr:1922 cid:135 iyr:2019 eyr:2028 pid:481801918 +hcl:#efcc98 hgt:76in + +ecl:grn pid:188906975 cid:153 hgt:173cm eyr:2029 iyr:2012 hcl:#733820 byr:2001 + +eyr:2029 +byr:1948 iyr:2020 +hgt:167cm ecl:brn hcl:#623a2f pid:577624152 + +hcl:#18171d +pid:262528276 byr:1949 +iyr:2020 +eyr:2023 + +hcl:#c0946f iyr:2016 byr:1967 ecl:brn +hgt:162cm +pid:139002508 eyr:2030 + +eyr:2030 +hgt:72in iyr:2013 pid:542944485 cid:112 +byr:1950 hcl:#a97842 ecl:amb + +pid:772544664 eyr:2023 ecl:gry hgt:159cm iyr:2012 +byr:1956 hcl:#602927 + +hgt:172in ecl:grt pid:668387651 byr:2019 +iyr:1995 hcl:bc51ff eyr:1921 + +pid:322272953 ecl:brn hcl:#a97842 byr:1990 +eyr:2021 +iyr:2017 +hgt:181cm + +eyr:2029 +iyr:2011 +pid:503169142 byr:1980 +hcl:#a97842 ecl:oth + +pid:514042929 +ecl:amb eyr:2030 hgt:154cm +iyr:2010 hcl:#623a2f +byr:1989 + +byr:1988 pid:156381939 iyr:2016 hgt:161cm eyr:2030 ecl:brn hcl:#7d3b0c + +pid:545819361 hgt:191cm iyr:2012 byr:1982 eyr:2025 ecl:zzz +hcl:z + +pid:872911892 +byr:1924 iyr:1974 +hcl:#602927 +ecl:brn hgt:154cm +eyr:2028 + +hcl:#602927 hgt:188cm +byr:2007 pid:503933918 ecl:utc +eyr:2030 iyr:2020 cid:132 + +ecl:hzl +eyr:2020 hcl:#888785 hgt:181cm +pid:721383537 +iyr:2018 +byr:1983 cid:50 + +pid:8590606 hcl:#18171d +eyr:2039 iyr:2024 +cid:161 byr:2027 + +hgt:160in byr:1956 +cid:214 pid:187cm iyr:2027 +hcl:z +eyr:2033 ecl:grn + +byr:2029 pid:90562860 hcl:4fa0d1 iyr:2024 +eyr:2040 cid:62 ecl:#07ae33 hgt:186in + +pid:557319679 byr:1945 hgt:182cm eyr:2026 iyr:2012 hcl:#866857 ecl:hzl cid:219 + +eyr:2028 iyr:2022 ecl:zzz cid:273 +hgt:133 pid:4084335529 byr:2011 hcl:z + +pid:69196974 hcl:z iyr:2014 ecl:amb byr:1928 + +hgt:183in +eyr:2028 pid:771762218 byr:2003 ecl:dne hcl:70eb58 iyr:2027 cid:330 + +ecl:hzl pid:195721774 hcl:#602927 byr:1945 hgt:186cm +eyr:2037 +iyr:2011 + +ecl:brn eyr:2028 hgt:171cm +byr:1980 hcl:#fffffd pid:563089389 iyr:2016 + +eyr:2027 iyr:2011 ecl:gry byr:1932 hcl:#18171d +pid:398526372 + +pid:97363921 hgt:178cm +ecl:oth eyr:2028 +byr:1930 cid:345 iyr:2018 hcl:#1fb2f0 + +ecl:amb iyr:2012 +byr:1961 pid:679312513 eyr:2026 hcl:#cfa07d +hgt:174cm + +byr:1980 +hcl:#80055d +cid:235 +ecl:oth pid:159696517 eyr:2030 +hgt:191cm +iyr:2012 + +iyr:2013 eyr:2027 hcl:#866857 +pid:621184472 cid:137 hgt:175cm byr:2000 +ecl:hzl + +byr:1998 hgt:166cm +ecl:oth eyr:2025 +iyr:2018 +hcl:#a97842 pid:358495679 + +byr:1928 ecl:oth cid:122 hcl:#6b5442 +hgt:189cm eyr:2020 iyr:2018 + +hgt:186cm +byr:2020 hcl:79d685 ecl:grt iyr:1944 pid:3659998623 eyr:2000 + +hgt:63in ecl:oth eyr:2029 +iyr:2013 pid:942282912 hcl:#c0946f byr:1989 + +byr:1997 hcl:#623a2f eyr:2026 cid:149 +pid:702981538 +ecl:amb hgt:178cm iyr:2017 + +ecl:brn iyr:2015 byr:1932 pid:191192548 cid:318 +hcl:#7d3b0c eyr:2020 + +hcl:#866857 eyr:2028 pid:341036511 cid:343 iyr:2020 hgt:173cm +byr:1973 ecl:blu + +iyr:2016 pid:165707654 hgt:181cm ecl:hzl +cid:119 byr:1973 hcl:#b6652a + +iyr:2014 pid:833337583 byr:1936 cid:91 hcl:#602927 ecl:amb hgt:165cm +eyr:2021 + +byr:1938 ecl:grn hcl:#a55daf eyr:2021 cid:199 pid:701515796 +iyr:2015 hgt:71in + +hcl:#a97842 +ecl:blu +eyr:2030 iyr:2020 +hgt:155cm byr:1927 +pid:524488639 + +pid:385084163 eyr:2025 +hcl:#866857 ecl:oth iyr:2020 hgt:177cm byr:2002 + +eyr:2029 hgt:177cm +cid:142 ecl:hzl hcl:#866857 +iyr:2015 byr:1946 pid:459543573 + +pid:826977286 eyr:2030 iyr:2016 byr:1996 +hcl:#efcc98 +ecl:gry hgt:180cm + +eyr:2029 +iyr:1976 pid:872821863 ecl:gry byr:2030 + +hgt:191cm byr:1924 pid:918753019 ecl:blu +iyr:2019 hcl:#5d69e0 eyr:2024 + +ecl:lzr iyr:2020 pid:991375034 byr:1947 +eyr:1923 hcl:8224f6 hgt:157 + +eyr:2021 byr:1946 +hgt:189cm ecl:grn iyr:2010 hcl:#cfa07d pid:246923037 + +iyr:2016 +ecl:oth hgt:155cm byr:1962 pid:924702739 eyr:2028 hcl:#7d3b0c + +pid:7358100461 hgt:183cm byr:2011 hcl:#a97842 +iyr:2020 eyr:1963 cid:71 + +ecl:hzl hcl:#c0946f +byr:1934 +hgt:183cm +iyr:2018 pid:433993423 eyr:2028 + +hgt:183cm hcl:#cfa07d iyr:2018 +byr:1975 eyr:2024 + +eyr:2021 ecl:amb byr:1992 hgt:164cm iyr:2020 +cid:302 + +pid:271720491 hgt:161cm +iyr:2012 byr:1947 hcl:#6b5442 ecl:grn eyr:2024 + +pid:860852799 eyr:2021 byr:1980 hcl:#6b5442 iyr:2010 hgt:174cm +ecl:hzl + +hcl:#623a2f eyr:2028 iyr:2016 pid:813453232 hgt:173cm cid:131 +byr:1962 + +byr:1975 +hgt:177cm +pid:290098810 cid:241 +ecl:oth hcl:#a5fc9f eyr:2021 iyr:2013 + +byr:1947 pid:762351259 hgt:178cm ecl:amb hcl:#d07b27 iyr:2017 eyr:2028 cid:271 + +iyr:2012 pid:053790533 eyr:2023 ecl:grn hcl:#623a2f byr:1939 cid:70 hgt:189cm + +hcl:#c0946f pid:891312170 byr:1986 iyr:2012 +hgt:163cm eyr:2023 cid:150 + +iyr:2015 +byr:1963 +pid:695024197 hcl:#efcc98 ecl:brn hgt:166cm eyr:2022 +cid:276 + +eyr:1945 hgt:150in byr:2007 +ecl:utc hcl:z cid:272 +pid:186cm iyr:1927 + +pid:956296646 iyr:2015 hgt:168cm +byr:1979 eyr:2029 ecl:gry hcl:#866857 + +pid:745452488 byr:1998 eyr:2025 hcl:#602927 +hgt:158cm iyr:2015 + +eyr:2027 +iyr:2017 +pid:6173634679 byr:2001 ecl:hzl +hcl:babc41 +hgt:76cm + +ecl:grn +iyr:2019 +hcl:#3881ca byr:1975 eyr:2023 hgt:162cm + +hcl:#ceb3a1 hgt:169in pid:398759957 +eyr:2020 byr:2016 +iyr:2011 ecl:#be3622 + +hgt:156cm +hcl:#b6652a pid:166cm iyr:2027 byr:2003 +eyr:2036 ecl:#6d4df1 +cid:109 + +eyr:2026 pid:295161300 ecl:gry +hgt:160cm byr:1950 hcl:#746f08 +iyr:2017 + +iyr:2010 cid:335 +eyr:2024 +hcl:#866857 +byr:1948 hgt:166cm pid:178927953 +ecl:blu + +hgt:161cm cid:210 eyr:2025 +byr:1920 +ecl:gry iyr:2020 +hcl:#7d3b0c pid:443548961 + +iyr:2019 +pid:320015839 eyr:2029 +hcl:#fffffd ecl:oth byr:1953 hgt:182cm + +eyr:2038 hcl:abb3ad iyr:2015 pid:174cm hgt:167cm +ecl:hzl + +byr:1982 pid:798153758 +ecl:brn +hgt:161cm hcl:#341e13 eyr:2023 +iyr:2014 + +byr:1938 +pid:193cm hgt:190cm ecl:amb iyr:2019 +eyr:2028 cid:270 +hcl:#18171d + +pid:711886098 byr:1962 +eyr:2028 ecl:grn +hgt:151cm +hcl:#cfa07d +iyr:2019 + +eyr:2028 iyr:2011 +ecl:gry +pid:550207629 hgt:183cm +hcl:#888785 byr:1920 cid:96 + +ecl:utc +eyr:2021 +byr:1962 hgt:175cm +pid:872298092 +hcl:z iyr:2017 cid:197 + +iyr:2010 +hcl:5b88b0 byr:2021 ecl:gmt +eyr:2040 hgt:179cm pid:161cm + +pid:56869473 eyr:2036 ecl:lzr +iyr:2027 hcl:z + +hcl:#602927 +hgt:151cm pid:780342729 ecl:oth iyr:2015 + +byr:2027 hcl:#fffffd +pid:5609758115 eyr:2037 +iyr:2017 +ecl:#6f0329 hgt:97 + +iyr:2025 hcl:z byr:2007 ecl:gmt +pid:#eda9ab +hgt:154in eyr:2028 cid:247 + +ecl:utc pid:216181141 +hgt:161cm eyr:2026 +hcl:#d38f20 byr:2028 + +ecl:grn byr:1955 hcl:#c0946f +iyr:2017 eyr:2027 pid:746303487 +hgt:72in + +pid:489225602 +iyr:2018 ecl:gry hgt:65in byr:1982 +cid:248 +eyr:2025 + +hcl:#ceb3a1 pid:663798116 byr:1937 iyr:2010 +hgt:167cm ecl:hzl + +pid:329032527 +hcl:#ceb3a1 +iyr:2014 ecl:gry +hgt:169cm +byr:1932 + +hcl:#545d0c +ecl:brn iyr:2023 hgt:186cm cid:209 +pid:886392748 +eyr:2030 byr:1984 + +hgt:80 iyr:1943 hcl:#733820 byr:1937 eyr:2029 pid:625851706 cid:309 + +pid:73586582 hgt:156 +cid:162 ecl:zzz eyr:2025 +iyr:1990 byr:1940 hcl:z + +iyr:2010 +eyr:2023 pid:162901454 +hcl:#733820 byr:1958 ecl:gry +hgt:159cm + +byr:2007 +hcl:#cfa07d +cid:261 pid:148538600 ecl:hzl +hgt:64cm iyr:2021 +eyr:2040 + +iyr:1997 byr:2007 ecl:#24adc8 +pid:55794137 cid:219 eyr:2037 +hgt:75cm hcl:z + +hcl:#efcc98 byr:1940 ecl:amb iyr:2012 +pid:594237790 eyr:2029 cid:112 +hgt:173cm + +byr:1941 cid:70 eyr:2026 hgt:178cm hcl:#733820 +ecl:brn iyr:2013 pid:425263722 + +eyr:2025 byr:1998 iyr:2014 ecl:amb pid:188113611 hcl:#341e13 + +byr:1950 +iyr:2017 hgt:74in cid:238 +pid:897969952 +ecl:hzl eyr:2022 hcl:#0a18bb + +eyr:2022 +iyr:2015 ecl:grn +hgt:179cm byr:1956 hcl:#7fd789 pid:201629099 + +eyr:2024 +pid:483257417 ecl:hzl iyr:2010 hgt:159cm +hcl:z +byr:1968 + +pid:916586207 ecl:amb iyr:2011 eyr:2022 hgt:191cm hcl:#602927 byr:1923 + +pid:175608183 +hgt:190cm hcl:#fffffd iyr:2017 byr:1993 +ecl:blu + +eyr:2029 hgt:173cm +pid:669662258 byr:1997 iyr:2015 ecl:brn cid:153 hcl:#888785 + +hcl:d899cf +ecl:#876029 hgt:76cm iyr:1997 pid:40406158 +eyr:2032 byr:2010 + +eyr:2023 ecl:hzl cid:162 hcl:#602927 iyr:2015 +pid:82885029 +hgt:75cm byr:1946 + +byr:1962 hgt:167in +ecl:brn +hcl:#c0946f iyr:2014 pid:488520708 eyr:2027 cid:271 + +hgt:180cm pid:358771245 eyr:2020 +ecl:grn iyr:2018 hcl:#efcc98 +byr:1979 + +cid:273 ecl:gry pid:424388351 iyr:2010 hcl:#c0946f byr:1988 +hgt:166cm +eyr:2027 + +ecl:gry hcl:#a97842 hgt:189cm +pid:743213778 iyr:2015 byr:1959 + +iyr:2021 byr:2021 +ecl:#a79d2e cid:89 +hcl:#5fb8d7 eyr:2001 pid:#5575b3 hgt:60cm + +eyr:2021 +iyr:2017 +cid:87 hgt:164cm pid:560394910 ecl:hzl hcl:#ceb3a1 +byr:1955 + +iyr:2018 +hcl:#27f7e6 hgt:160cm +eyr:2029 pid:033692111 +ecl:amb byr:1920 + +hgt:160cm eyr:2028 iyr:2010 ecl:blu byr:1974 pid:858060501 hcl:#733820 + +byr:1961 pid:818700605 cid:93 eyr:2024 +hgt:188cm hcl:#866857 +ecl:gry + +eyr:2029 +hgt:180cm iyr:2017 +ecl:hzl byr:1951 cid:158 +hcl:#888785 + +cid:290 +eyr:2027 byr:1986 +ecl:blu +pid:076339632 iyr:2010 +hcl:#341e13 +hgt:167cm + +eyr:2023 iyr:1990 +hcl:#623a2f byr:2005 hgt:116 + +hgt:167in iyr:1944 ecl:dne eyr:2031 hcl:465775 pid:2505694463 + +cid:93 eyr:2024 iyr:2010 +hgt:143 pid:154cm +ecl:#c6f352 +hcl:#a97842 byr:1925 + +pid:600685520 byr:1967 hcl:#ceb3a1 iyr:2014 ecl:oth cid:226 hgt:179cm eyr:2026 + +hcl:#ceb3a1 +pid:789956738 +byr:1938 hgt:171cm cid:183 eyr:2021 iyr:2011 ecl:amb + +hcl:#613f4b hgt:151cm eyr:2025 +ecl:amb byr:1985 pid:493339889 +iyr:2013 + +hcl:78cda6 pid:36823553 +iyr:2021 cid:235 byr:2028 eyr:2011 hgt:113 +ecl:#02ce86 + +pid:529274811 +iyr:2012 hgt:103 ecl:blu hcl:#341e13 eyr:2023 +byr:1959 + +hgt:166cm iyr:2014 ecl:xry cid:276 byr:2014 hcl:#7d3b0c pid:146851133 + +pid:359823289 hgt:181cm byr:1978 hcl:#c0946f +eyr:2022 +iyr:2011 ecl:hzl + +pid:029400877 +eyr:2026 +byr:1983 iyr:2015 hcl:#cfa07d cid:70 ecl:gry + +hcl:#ceb3a1 eyr:2021 hgt:190cm +ecl:amb iyr:2017 +pid:411804678 byr:1950 + +byr:1926 iyr:2017 ecl:blu pid:103821113 eyr:2026 hcl:#c0946f cid:71 hgt:152cm + +cid:108 byr:1955 +iyr:2010 eyr:2022 hgt:169cm hcl:#733820 +pid:208715596 ecl:gry + +pid:352807405 ecl:blu +hcl:#b1214c iyr:2012 hgt:165cm byr:1929 +cid:139 +eyr:2020 + +hcl:#cfa07d hgt:151cm byr:1987 +eyr:2024 +cid:140 pid:884441477 + +pid:#dade9c eyr:1979 hgt:191cm +byr:2026 iyr:2018 hcl:z ecl:lzr + +cid:259 +pid:644561358 +ecl:blu hgt:164cm iyr:2013 byr:1997 +eyr:2023 hcl:#108f16 + +ecl:oth +cid:141 hgt:66in pid:877258886 iyr:2019 byr:1949 hcl:#18171d +eyr:2027 + +byr:1932 cid:103 hgt:175cm pid:464473181 ecl:xry iyr:2013 hcl:51fd65 + +cid:175 iyr:2014 eyr:1959 +ecl:#d83076 hgt:182cm pid:863972537 hcl:#efcc98 byr:1986 + +hgt:181cm pid:869641194 hcl:#efcc98 cid:141 ecl:gmt iyr:2017 byr:1981 eyr:2027 + +eyr:1938 +iyr:2026 cid:278 ecl:brn byr:1936 hgt:150 pid:6902040050 + +eyr:2027 iyr:2014 pid:110887179 +hcl:#a97842 ecl:brn cid:262 hgt:66in +byr:1954 + +ecl:grn +pid:498972747 +eyr:2024 hcl:#341e13 iyr:2011 byr:1932 hgt:186cm + +cid:59 +hcl:#6b5442 iyr:2018 eyr:2028 pid:866696485 +hgt:178cm ecl:gry + +pid:598961001 +eyr:2024 iyr:2019 +byr:1963 ecl:grn +hcl:#c0946f + +eyr:2024 hgt:172cm pid:295056305 ecl:blu byr:1926 +iyr:2017 hcl:#341e13 + +byr:2001 hcl:#6b5442 hgt:164cm +pid:862982189 ecl:grn iyr:2019 eyr:2030 + +hgt:69cm eyr:2014 ecl:hzl iyr:2025 +hcl:2812c9 +cid:74 byr:1980 + +hcl:#888785 +pid:409489862 +iyr:2011 hgt:186cm ecl:gry byr:1985 +eyr:2028 + +cid:221 pid:6849250876 hgt:169cm hcl:z +iyr:2013 +byr:1950 eyr:2022 + +pid:189083891 byr:1983 hcl:#623a2f ecl:hzl iyr:2013 eyr:2026 hgt:66in + +pid:581546673 cid:269 eyr:2030 hgt:191cm byr:1945 hcl:#18171d +iyr:2015 +ecl:amb + +hgt:158cm ecl:hzl +cid:234 eyr:2023 +byr:1996 hcl:#7ac7ad +iyr:2020 pid:666748924 + +iyr:2013 ecl:grn cid:53 hgt:172cm eyr:2028 pid:406602771 hcl:#fffffd byr:1959 + +hgt:63cm hcl:eaaf60 byr:2026 iyr:1981 +pid:#baf2cf cid:117 ecl:hzl + +eyr:2035 byr:2014 +iyr:2028 hcl:z ecl:#acd426 +cid:261 pid:174cm hgt:182in + +ecl:amb pid:#4bb0a8 eyr:2027 hgt:155cm hcl:#623a2f +byr:1956 +iyr:2011 + +eyr:2012 cid:53 byr:2005 ecl:oth +hgt:183in iyr:1974 pid:150cm + +iyr:2020 pid:833821322 ecl:blu byr:1944 hgt:169cm hcl:#623a2f eyr:2020 + +hgt:60in ecl:oth byr:1962 eyr:2022 cid:99 +iyr:2019 +pid:281039464 hcl:#733820 + +ecl:hzl hcl:#7d3b0c hgt:191cm pid:771871096 +iyr:2012 eyr:2027 +byr:2025 + +hgt:188in hcl:z eyr:2032 iyr:1955 +byr:2027 ecl:#517bfe pid:#206bab + +hcl:#733820 iyr:2010 pid:784128823 +hgt:169cm cid:305 +ecl:grn byr:1962 + +cid:50 eyr:2022 +hcl:a916cf pid:407148034 iyr:1926 ecl:#fa1ba7 hgt:69 +byr:2028 + +hgt:193cm pid:507697987 cid:275 byr:1958 eyr:2023 ecl:brn iyr:2013 hcl:#326596 + +eyr:2025 hgt:192cm cid:95 iyr:2011 ecl:grn byr:2002 pid:399623583 hcl:#b6652a + +ecl:brn hcl:#602927 eyr:2023 pid:089068603 hgt:189cm +byr:1953 iyr:2018 +cid:160 + +hcl:f1bf94 byr:2030 +ecl:gry hgt:60in iyr:2016 +pid:4816152 + +hgt:154cm iyr:2015 ecl:gry +eyr:2024 pid:718845487 byr:1999 +hcl:#866857 + +cid:294 +hgt:186cm eyr:2026 byr:1984 +ecl:grn +hcl:#ceb3a1 pid:325370778 iyr:2010 + +pid:156980004 hcl:#c0946f iyr:2013 ecl:brn +hgt:181cm byr:1933 eyr:2023 + +hcl:#efcc98 byr:2002 hgt:158cm ecl:gmt iyr:1964 pid:195262032 +eyr:2021 + +hcl:#602927 eyr:2027 hgt:192cm byr:1945 iyr:2018 pid:366509171 ecl:oth + +pid:163cm iyr:2016 ecl:lzr hcl:#341e13 hgt:79 +cid:130 +eyr:2038 byr:2030 + +hcl:#efcc98 +byr:1979 +ecl:oth eyr:2020 pid:095314628 +hgt:162cm iyr:2015 + +byr:1998 cid:157 +pid:346442779 hcl:#b6652a hgt:162cm +ecl:amb +eyr:2023 iyr:2018 + +hcl:#d6a701 byr:1971 hgt:160cm ecl:#98c896 pid:627704105 eyr:2024 iyr:2010 + +byr:2021 +iyr:2023 +eyr:1981 hgt:68cm ecl:dne +hcl:z pid:20981493 + +pid:159037919 hgt:162cm +ecl:amb cid:244 +byr:1971 eyr:2027 +iyr:2017 hcl:#18171d + +iyr:2011 pid:086826874 +cid:162 +hgt:189cm ecl:gry +byr:1926 hcl:#888785 + +eyr:2022 hgt:152cm pid:919970712 byr:1955 hcl:#733820 iyr:2018 ecl:brn + +cid:111 ecl:#a1843f +byr:2015 hcl:z iyr:1956 +pid:186cm eyr:2030 + +byr:1991 +eyr:2024 pid:050818633 +hcl:#888785 cid:124 hgt:176cm ecl:gry iyr:2018 + +byr:1963 hgt:188cm +eyr:2021 cid:255 +ecl:oth +hcl:#a97842 +iyr:2010 pid:030540064 + +byr:1921 hgt:164cm pid:748078322 hcl:#c0946f ecl:blu +eyr:2027 +iyr:2020 + +eyr:2020 cid:214 hcl:7a942e hgt:191cm byr:1998 iyr:2012 ecl:grn pid:054135231 + +eyr:1927 pid:242147946 iyr:2010 +hcl:ea3cb1 byr:2028 +hgt:186cm ecl:dne + +ecl:brn hcl:#efcc98 eyr:2021 +hgt:160cm pid:333644730 byr:1999 +iyr:2019 + +iyr:2013 byr:1921 +hcl:#a97842 eyr:2027 +ecl:gry hgt:157cm pid:682013109 + +ecl:gry hcl:#733820 byr:1945 hgt:174cm +eyr:2020 pid:505827627 iyr:2019 + +eyr:2021 iyr:2015 ecl:oth hgt:162cm pid:137342936 byr:1922 hcl:#888785 + +hcl:#efcc98 +ecl:oth +hgt:151cm cid:312 byr:1983 +eyr:2030 pid:289512908 iyr:2020 + +byr:1989 iyr:2015 pid:057335770 ecl:grn eyr:2022 hgt:167cm hcl:#602927 + +hgt:184cm iyr:2013 hcl:#c0946f byr:1969 eyr:2028 +pid:802041641 +ecl:brn + +pid:155cm hcl:#b6652a cid:288 byr:2028 iyr:2028 hgt:150cm +ecl:#996e72 eyr:1960 + +eyr:2020 +iyr:2011 +pid:934576102 byr:1994 +ecl:amb +hcl:#18171d + +eyr:1993 byr:1995 +hgt:64cm iyr:2020 pid:15714997 hcl:#b6652a ecl:blu + +iyr:2014 +eyr:2030 pid:866047540 cid:59 hcl:#733820 byr:1951 +hgt:64in ecl:amb + +iyr:2015 +byr:1962 +hgt:69in ecl:brn +hcl:#623a2f eyr:2023 +pid:671492881 + +iyr:2020 ecl:oth hgt:154cm byr:1950 pid:924256973 +eyr:2028 +hcl:#b6652a + +byr:2021 +hgt:116 cid:348 iyr:1930 pid:76948864 hcl:z +eyr:2036 + +hgt:156cm iyr:2014 +byr:1960 +pid:720786216 +cid:99 +ecl:gry +hcl:#a97842 +eyr:2028 From 005501546fd858f28f05dd1f7912912329d1532c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 4 Dec 2020 09:50:23 +0100 Subject: [PATCH 041/129] 2020: d04: ex1: add solution --- 2020/d04/ex1/ex1.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 2020/d04/ex1/ex1.py diff --git a/2020/d04/ex1/ex1.py b/2020/d04/ex1/ex1.py new file mode 100755 index 0000000..5193652 --- /dev/null +++ b/2020/d04/ex1/ex1.py @@ -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() From 26e3bd00067962f27feae991717d1ac58fbadae4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 4 Dec 2020 09:50:31 +0100 Subject: [PATCH 042/129] 2020: d04: ex2: add input --- 2020/d04/ex2/input | 1069 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1069 insertions(+) create mode 100644 2020/d04/ex2/input diff --git a/2020/d04/ex2/input b/2020/d04/ex2/input new file mode 100644 index 0000000..710a26b --- /dev/null +++ b/2020/d04/ex2/input @@ -0,0 +1,1069 @@ +byr:2010 pid:#1bb4d8 eyr:2021 hgt:186cm iyr:2020 ecl:grt + +pid:937877382 eyr:2029 +ecl:amb hgt:187cm iyr:2019 +byr:1933 hcl:#888785 + +ecl:hzl +eyr:2020 +hcl:#18171d +iyr:2019 hgt:183cm +byr:1935 + +hcl:#7d3b0c hgt:183cm cid:135 +byr:1992 eyr:2024 iyr:2013 pid:138000309 +ecl:oth + +ecl:hzl +hgt:176cm pid:346059944 byr:1929 cid:150 eyr:1924 hcl:#fffffd iyr:2016 + +iyr:2011 +cid:99 ecl:amb +eyr:2030 hcl:#18171d +hgt:165cm pid:897123249 byr:1948 + +hcl:#cfa07d pid:827609097 ecl:gry iyr:2017 byr:1963 +eyr:2029 hgt:72in + +hcl:#6b5442 eyr:2028 iyr:2016 ecl:hzl +hgt:152cm +pid:432183209 byr:1984 + +hgt:169cm hcl:#888785 ecl:hzl pid:626107466 byr:1929 iyr:2013 cid:217 +eyr:2026 + +hcl:#bdb95d byr:1935 eyr:2023 ecl:blu iyr:2011 cid:90 hgt:64cm +pid:155167914 + +iyr:2017 +byr:1943 cid:56 +hcl:#888785 hgt:193cm pid:621305634 +ecl:amb +eyr:2024 + +ecl:gry +hcl:#a97842 pid:936999610 cid:169 byr:1991 eyr:2029 hgt:175cm iyr:2017 + +hcl:#866857 ecl:gry +byr:1975 hgt:71in +pid:180628540 eyr:2020 +iyr:2017 + +hcl:#cfa07d hgt:153cm byr:1962 cid:325 +iyr:2018 eyr:2020 +ecl:amb pid:579364506 + +hcl:#6b5442 iyr:2010 ecl:amb byr:2001 +eyr:2020 pid:406219444 +hgt:173cm + +pid:#430c70 +ecl:gry iyr:2018 hcl:#866857 eyr:2021 cid:97 byr:1997 +hgt:75cm + +iyr:2023 pid:#518780 +eyr:2034 +ecl:zzz +hgt:72cm +hcl:z byr:2010 + +pid:1961614335 hcl:#c0946f hgt:157 ecl:grn eyr:2031 byr:1972 iyr:1992 + +cid:142 +eyr:2022 ecl:amb +hgt:68in +hcl:#6b5442 byr:1927 pid:112372155 iyr:2012 + +byr:1972 +hgt:169cm +hcl:#888785 +cid:75 iyr:2015 eyr:2021 ecl:oth +pid:7889059161 + +ecl:brn +iyr:2020 +eyr:2026 hgt:151cm byr:1961 pid:468038868 hcl:#18171d + +ecl:blu +hcl:#b6652a +byr:1959 +hgt:151cm cid:109 pid:708689901 +eyr:2026 iyr:2012 + +ecl:grt byr:2024 iyr:1995 pid:225263933 hcl:z +eyr:2040 hgt:127 cid:162 + +pid:683129831 cid:144 +hcl:#a97842 hgt:155cm eyr:2030 byr:1962 +iyr:2015 +ecl:oth + +byr:2009 hcl:#866857 cid:329 iyr:1955 +eyr:1994 pid:085929595 + +byr:1940 +pid:936748944 hgt:160cm eyr:2024 iyr:2013 cid:205 +ecl:grn hcl:#c0946f + +hgt:193in cid:161 iyr:1984 +pid:#f82e35 +byr:2018 +hcl:b1a551 eyr:2014 ecl:#4d2d5b + +byr:1978 +iyr:2011 hgt:172cm hcl:#efcc98 ecl:brn pid:759624394 eyr:2020 + +eyr:2020 pid:622444743 +hcl:#a97842 +ecl:gry iyr:2014 hgt:157cm byr:1980 + +hgt:181cm eyr:2020 +iyr:2014 +hcl:#602927 ecl:brn byr:1934 + +hgt:188cm +ecl:blu eyr:2029 pid:757878469 hcl:#b6652a iyr:2017 + +byr:1995 ecl:blu hcl:#341e13 eyr:2027 iyr:2020 pid:283341241 +hgt:174cm + +byr:1960 iyr:2012 hcl:dc007d eyr:2011 hgt:166cm +pid:9889788504 +ecl:#a9b3a1 + +ecl:hzl hgt:70in pid:620966688 iyr:1998 hcl:z +eyr:2022 + +hgt:187cm cid:190 pid:818634983 byr:1925 ecl:gry hcl:#ceb3a1 +eyr:2021 iyr:2015 + +hcl:#c0946f iyr:2017 +byr:1953 eyr:2030 hgt:67in pid:085876735 ecl:hzl + +pid:205284134 +hcl:#cfa07d byr:1987 hgt:167cm +eyr:2022 ecl:oth iyr:2020 + +iyr:2018 +hgt:180cm pid:232535961 eyr:2027 byr:1999 +hcl:#18171d ecl:oth + +cid:342 hgt:171cm ecl:blu byr:1920 hcl:#18171d eyr:2023 iyr:2012 +pid:353601791 + +byr:1956 +ecl:brn pid:141896408 iyr:2012 cid:116 eyr:2028 hgt:164cm +hcl:#866857 + +hcl:#fffffd ecl:oth eyr:2030 hgt:67in pid:855777018 byr:1975 +iyr:2012 + +ecl:blu pid:45257034 hcl:#c5447e iyr:1928 cid:212 byr:1974 + +pid:080116868 cid:97 eyr:2021 iyr:2020 ecl:grn byr:1987 hgt:62in hcl:#efcc98 + +eyr:2027 hcl:#efcc98 iyr:2020 ecl:amb cid:111 +pid:143966954 +hgt:165cm + +iyr:2015 byr:1941 pid:798564127 +hgt:183cm ecl:oth eyr:2020 + +byr:1999 +iyr:2017 hcl:#ceb3a1 +pid:640883740 hgt:164cm +cid:105 ecl:hzl +eyr:2022 + +iyr:2014 eyr:2023 +ecl:grn hcl:#ceb3a1 +hgt:188cm byr:1981 pid:185076942 cid:342 + +hgt:150cm +iyr:2013 eyr:2035 cid:184 hcl:#341e13 pid:#e2dd63 byr:2014 ecl:brn + +eyr:2024 iyr:2015 ecl:brn hgt:76in +hcl:#866857 byr:1958 +pid:886486245 + +ecl:amb cid:113 byr:1931 pid:087380735 +iyr:2010 +eyr:2028 +hgt:161cm + +byr:1926 eyr:2024 iyr:2012 pid:036335738 hcl:#c0946f hgt:153cm ecl:brn + +hcl:bf952a +hgt:169in +eyr:1925 pid:166cm iyr:2028 ecl:lzr byr:1938 + +hgt:154cm hcl:#733820 ecl:oth iyr:2016 +byr:1925 +eyr:2020 pid:590365390 + +eyr:2029 hgt:166cm pid:670283165 +hcl:#ceb3a1 iyr:2018 +byr:1955 +ecl:gry + +hgt:181cm +iyr:2016 hcl:#866857 byr:1933 +eyr:2028 ecl:blu + +hgt:184cm +cid:138 hcl:#623a2f +pid:081880232 +byr:1929 ecl:hzl eyr:2030 +iyr:2015 + +pid:825698872 +eyr:2026 hgt:181cm iyr:2015 hcl:#866857 byr:1950 ecl:gry + +eyr:2022 byr:2002 iyr:2013 hcl:#fffffd ecl:hzl pid:687380398 +hgt:173cm + +byr:2016 ecl:zzz pid:0514910377 hcl:ebe8b2 eyr:2025 +iyr:2011 hgt:183cm + +ecl:amb hgt:67in +pid:602547016 byr:1985 +eyr:2021 +iyr:2014 + +iyr:2014 eyr:2020 ecl:grn pid:642261584 +byr:1970 hgt:190cm cid:278 hcl:#7d3b0c + +eyr:2035 cid:226 hcl:64ac73 +byr:2007 +pid:176cm ecl:#927fbf iyr:2006 + +iyr:2019 eyr:2026 ecl:brn hgt:162cm +cid:108 +hcl:#ceb3a1 pid:774441166 byr:1951 + +hgt:166cm eyr:2024 hcl:#b6652a byr:1934 pid:260873380 iyr:2016 + +hcl:z +iyr:2015 ecl:blu +eyr:2040 byr:1927 pid:431855667 +hgt:173cm +cid:209 + +eyr:2034 cid:139 +ecl:#cb7564 +byr:2023 hgt:172in iyr:2027 pid:2877047600 + +ecl:brn +cid:125 hcl:#888785 +iyr:2011 pid:739399822 hgt:184cm byr:1989 + +hcl:#c0946f +pid:891125961 +hgt:175cm +iyr:2010 eyr:2027 ecl:gry +byr:1930 + +hgt:164cm byr:1935 eyr:2023 pid:684366743 +ecl:oth +hcl:#18171d iyr:2013 + +hcl:#341e13 hgt:64in byr:1959 ecl:#c53bbb iyr:2014 eyr:2029 pid:174cm + +eyr:1943 ecl:#e52638 +hcl:06a964 byr:1959 cid:342 iyr:2029 hgt:178in pid:150cm + +byr:1966 hcl:#733820 iyr:2020 +ecl:gry eyr:2021 pid:229789071 + +pid:363947487 +ecl:blu +hcl:#623a2f +byr:1972 +iyr:2017 hgt:184cm +eyr:2023 + +ecl:oth pid:460855562 +iyr:2010 cid:148 hcl:z hgt:74cm byr:2005 + +eyr:2027 iyr:2017 hgt:172cm +byr:1975 +ecl:amb cid:97 hcl:#c0946f pid:591950054 + +eyr:2022 ecl:oth hgt:185cm +hcl:#6b5442 +byr:1978 +iyr:2018 pid:849124937 cid:78 + +iyr:1927 hgt:121 +eyr:2020 ecl:#c73b1a hcl:#cfa07d pid:4505701953 byr:2020 +cid:235 + +hgt:183cm hcl:#341e13 iyr:2019 byr:1932 ecl:#144539 +pid:184cm eyr:1954 + +iyr:2020 cid:332 byr:1930 hcl:#6b5442 hgt:168cm ecl:amb +eyr:2023 pid:332084752 + +ecl:blu +byr:1922 cid:135 iyr:2019 eyr:2028 pid:481801918 +hcl:#efcc98 hgt:76in + +ecl:grn pid:188906975 cid:153 hgt:173cm eyr:2029 iyr:2012 hcl:#733820 byr:2001 + +eyr:2029 +byr:1948 iyr:2020 +hgt:167cm ecl:brn hcl:#623a2f pid:577624152 + +hcl:#18171d +pid:262528276 byr:1949 +iyr:2020 +eyr:2023 + +hcl:#c0946f iyr:2016 byr:1967 ecl:brn +hgt:162cm +pid:139002508 eyr:2030 + +eyr:2030 +hgt:72in iyr:2013 pid:542944485 cid:112 +byr:1950 hcl:#a97842 ecl:amb + +pid:772544664 eyr:2023 ecl:gry hgt:159cm iyr:2012 +byr:1956 hcl:#602927 + +hgt:172in ecl:grt pid:668387651 byr:2019 +iyr:1995 hcl:bc51ff eyr:1921 + +pid:322272953 ecl:brn hcl:#a97842 byr:1990 +eyr:2021 +iyr:2017 +hgt:181cm + +eyr:2029 +iyr:2011 +pid:503169142 byr:1980 +hcl:#a97842 ecl:oth + +pid:514042929 +ecl:amb eyr:2030 hgt:154cm +iyr:2010 hcl:#623a2f +byr:1989 + +byr:1988 pid:156381939 iyr:2016 hgt:161cm eyr:2030 ecl:brn hcl:#7d3b0c + +pid:545819361 hgt:191cm iyr:2012 byr:1982 eyr:2025 ecl:zzz +hcl:z + +pid:872911892 +byr:1924 iyr:1974 +hcl:#602927 +ecl:brn hgt:154cm +eyr:2028 + +hcl:#602927 hgt:188cm +byr:2007 pid:503933918 ecl:utc +eyr:2030 iyr:2020 cid:132 + +ecl:hzl +eyr:2020 hcl:#888785 hgt:181cm +pid:721383537 +iyr:2018 +byr:1983 cid:50 + +pid:8590606 hcl:#18171d +eyr:2039 iyr:2024 +cid:161 byr:2027 + +hgt:160in byr:1956 +cid:214 pid:187cm iyr:2027 +hcl:z +eyr:2033 ecl:grn + +byr:2029 pid:90562860 hcl:4fa0d1 iyr:2024 +eyr:2040 cid:62 ecl:#07ae33 hgt:186in + +pid:557319679 byr:1945 hgt:182cm eyr:2026 iyr:2012 hcl:#866857 ecl:hzl cid:219 + +eyr:2028 iyr:2022 ecl:zzz cid:273 +hgt:133 pid:4084335529 byr:2011 hcl:z + +pid:69196974 hcl:z iyr:2014 ecl:amb byr:1928 + +hgt:183in +eyr:2028 pid:771762218 byr:2003 ecl:dne hcl:70eb58 iyr:2027 cid:330 + +ecl:hzl pid:195721774 hcl:#602927 byr:1945 hgt:186cm +eyr:2037 +iyr:2011 + +ecl:brn eyr:2028 hgt:171cm +byr:1980 hcl:#fffffd pid:563089389 iyr:2016 + +eyr:2027 iyr:2011 ecl:gry byr:1932 hcl:#18171d +pid:398526372 + +pid:97363921 hgt:178cm +ecl:oth eyr:2028 +byr:1930 cid:345 iyr:2018 hcl:#1fb2f0 + +ecl:amb iyr:2012 +byr:1961 pid:679312513 eyr:2026 hcl:#cfa07d +hgt:174cm + +byr:1980 +hcl:#80055d +cid:235 +ecl:oth pid:159696517 eyr:2030 +hgt:191cm +iyr:2012 + +iyr:2013 eyr:2027 hcl:#866857 +pid:621184472 cid:137 hgt:175cm byr:2000 +ecl:hzl + +byr:1998 hgt:166cm +ecl:oth eyr:2025 +iyr:2018 +hcl:#a97842 pid:358495679 + +byr:1928 ecl:oth cid:122 hcl:#6b5442 +hgt:189cm eyr:2020 iyr:2018 + +hgt:186cm +byr:2020 hcl:79d685 ecl:grt iyr:1944 pid:3659998623 eyr:2000 + +hgt:63in ecl:oth eyr:2029 +iyr:2013 pid:942282912 hcl:#c0946f byr:1989 + +byr:1997 hcl:#623a2f eyr:2026 cid:149 +pid:702981538 +ecl:amb hgt:178cm iyr:2017 + +ecl:brn iyr:2015 byr:1932 pid:191192548 cid:318 +hcl:#7d3b0c eyr:2020 + +hcl:#866857 eyr:2028 pid:341036511 cid:343 iyr:2020 hgt:173cm +byr:1973 ecl:blu + +iyr:2016 pid:165707654 hgt:181cm ecl:hzl +cid:119 byr:1973 hcl:#b6652a + +iyr:2014 pid:833337583 byr:1936 cid:91 hcl:#602927 ecl:amb hgt:165cm +eyr:2021 + +byr:1938 ecl:grn hcl:#a55daf eyr:2021 cid:199 pid:701515796 +iyr:2015 hgt:71in + +hcl:#a97842 +ecl:blu +eyr:2030 iyr:2020 +hgt:155cm byr:1927 +pid:524488639 + +pid:385084163 eyr:2025 +hcl:#866857 ecl:oth iyr:2020 hgt:177cm byr:2002 + +eyr:2029 hgt:177cm +cid:142 ecl:hzl hcl:#866857 +iyr:2015 byr:1946 pid:459543573 + +pid:826977286 eyr:2030 iyr:2016 byr:1996 +hcl:#efcc98 +ecl:gry hgt:180cm + +eyr:2029 +iyr:1976 pid:872821863 ecl:gry byr:2030 + +hgt:191cm byr:1924 pid:918753019 ecl:blu +iyr:2019 hcl:#5d69e0 eyr:2024 + +ecl:lzr iyr:2020 pid:991375034 byr:1947 +eyr:1923 hcl:8224f6 hgt:157 + +eyr:2021 byr:1946 +hgt:189cm ecl:grn iyr:2010 hcl:#cfa07d pid:246923037 + +iyr:2016 +ecl:oth hgt:155cm byr:1962 pid:924702739 eyr:2028 hcl:#7d3b0c + +pid:7358100461 hgt:183cm byr:2011 hcl:#a97842 +iyr:2020 eyr:1963 cid:71 + +ecl:hzl hcl:#c0946f +byr:1934 +hgt:183cm +iyr:2018 pid:433993423 eyr:2028 + +hgt:183cm hcl:#cfa07d iyr:2018 +byr:1975 eyr:2024 + +eyr:2021 ecl:amb byr:1992 hgt:164cm iyr:2020 +cid:302 + +pid:271720491 hgt:161cm +iyr:2012 byr:1947 hcl:#6b5442 ecl:grn eyr:2024 + +pid:860852799 eyr:2021 byr:1980 hcl:#6b5442 iyr:2010 hgt:174cm +ecl:hzl + +hcl:#623a2f eyr:2028 iyr:2016 pid:813453232 hgt:173cm cid:131 +byr:1962 + +byr:1975 +hgt:177cm +pid:290098810 cid:241 +ecl:oth hcl:#a5fc9f eyr:2021 iyr:2013 + +byr:1947 pid:762351259 hgt:178cm ecl:amb hcl:#d07b27 iyr:2017 eyr:2028 cid:271 + +iyr:2012 pid:053790533 eyr:2023 ecl:grn hcl:#623a2f byr:1939 cid:70 hgt:189cm + +hcl:#c0946f pid:891312170 byr:1986 iyr:2012 +hgt:163cm eyr:2023 cid:150 + +iyr:2015 +byr:1963 +pid:695024197 hcl:#efcc98 ecl:brn hgt:166cm eyr:2022 +cid:276 + +eyr:1945 hgt:150in byr:2007 +ecl:utc hcl:z cid:272 +pid:186cm iyr:1927 + +pid:956296646 iyr:2015 hgt:168cm +byr:1979 eyr:2029 ecl:gry hcl:#866857 + +pid:745452488 byr:1998 eyr:2025 hcl:#602927 +hgt:158cm iyr:2015 + +eyr:2027 +iyr:2017 +pid:6173634679 byr:2001 ecl:hzl +hcl:babc41 +hgt:76cm + +ecl:grn +iyr:2019 +hcl:#3881ca byr:1975 eyr:2023 hgt:162cm + +hcl:#ceb3a1 hgt:169in pid:398759957 +eyr:2020 byr:2016 +iyr:2011 ecl:#be3622 + +hgt:156cm +hcl:#b6652a pid:166cm iyr:2027 byr:2003 +eyr:2036 ecl:#6d4df1 +cid:109 + +eyr:2026 pid:295161300 ecl:gry +hgt:160cm byr:1950 hcl:#746f08 +iyr:2017 + +iyr:2010 cid:335 +eyr:2024 +hcl:#866857 +byr:1948 hgt:166cm pid:178927953 +ecl:blu + +hgt:161cm cid:210 eyr:2025 +byr:1920 +ecl:gry iyr:2020 +hcl:#7d3b0c pid:443548961 + +iyr:2019 +pid:320015839 eyr:2029 +hcl:#fffffd ecl:oth byr:1953 hgt:182cm + +eyr:2038 hcl:abb3ad iyr:2015 pid:174cm hgt:167cm +ecl:hzl + +byr:1982 pid:798153758 +ecl:brn +hgt:161cm hcl:#341e13 eyr:2023 +iyr:2014 + +byr:1938 +pid:193cm hgt:190cm ecl:amb iyr:2019 +eyr:2028 cid:270 +hcl:#18171d + +pid:711886098 byr:1962 +eyr:2028 ecl:grn +hgt:151cm +hcl:#cfa07d +iyr:2019 + +eyr:2028 iyr:2011 +ecl:gry +pid:550207629 hgt:183cm +hcl:#888785 byr:1920 cid:96 + +ecl:utc +eyr:2021 +byr:1962 hgt:175cm +pid:872298092 +hcl:z iyr:2017 cid:197 + +iyr:2010 +hcl:5b88b0 byr:2021 ecl:gmt +eyr:2040 hgt:179cm pid:161cm + +pid:56869473 eyr:2036 ecl:lzr +iyr:2027 hcl:z + +hcl:#602927 +hgt:151cm pid:780342729 ecl:oth iyr:2015 + +byr:2027 hcl:#fffffd +pid:5609758115 eyr:2037 +iyr:2017 +ecl:#6f0329 hgt:97 + +iyr:2025 hcl:z byr:2007 ecl:gmt +pid:#eda9ab +hgt:154in eyr:2028 cid:247 + +ecl:utc pid:216181141 +hgt:161cm eyr:2026 +hcl:#d38f20 byr:2028 + +ecl:grn byr:1955 hcl:#c0946f +iyr:2017 eyr:2027 pid:746303487 +hgt:72in + +pid:489225602 +iyr:2018 ecl:gry hgt:65in byr:1982 +cid:248 +eyr:2025 + +hcl:#ceb3a1 pid:663798116 byr:1937 iyr:2010 +hgt:167cm ecl:hzl + +pid:329032527 +hcl:#ceb3a1 +iyr:2014 ecl:gry +hgt:169cm +byr:1932 + +hcl:#545d0c +ecl:brn iyr:2023 hgt:186cm cid:209 +pid:886392748 +eyr:2030 byr:1984 + +hgt:80 iyr:1943 hcl:#733820 byr:1937 eyr:2029 pid:625851706 cid:309 + +pid:73586582 hgt:156 +cid:162 ecl:zzz eyr:2025 +iyr:1990 byr:1940 hcl:z + +iyr:2010 +eyr:2023 pid:162901454 +hcl:#733820 byr:1958 ecl:gry +hgt:159cm + +byr:2007 +hcl:#cfa07d +cid:261 pid:148538600 ecl:hzl +hgt:64cm iyr:2021 +eyr:2040 + +iyr:1997 byr:2007 ecl:#24adc8 +pid:55794137 cid:219 eyr:2037 +hgt:75cm hcl:z + +hcl:#efcc98 byr:1940 ecl:amb iyr:2012 +pid:594237790 eyr:2029 cid:112 +hgt:173cm + +byr:1941 cid:70 eyr:2026 hgt:178cm hcl:#733820 +ecl:brn iyr:2013 pid:425263722 + +eyr:2025 byr:1998 iyr:2014 ecl:amb pid:188113611 hcl:#341e13 + +byr:1950 +iyr:2017 hgt:74in cid:238 +pid:897969952 +ecl:hzl eyr:2022 hcl:#0a18bb + +eyr:2022 +iyr:2015 ecl:grn +hgt:179cm byr:1956 hcl:#7fd789 pid:201629099 + +eyr:2024 +pid:483257417 ecl:hzl iyr:2010 hgt:159cm +hcl:z +byr:1968 + +pid:916586207 ecl:amb iyr:2011 eyr:2022 hgt:191cm hcl:#602927 byr:1923 + +pid:175608183 +hgt:190cm hcl:#fffffd iyr:2017 byr:1993 +ecl:blu + +eyr:2029 hgt:173cm +pid:669662258 byr:1997 iyr:2015 ecl:brn cid:153 hcl:#888785 + +hcl:d899cf +ecl:#876029 hgt:76cm iyr:1997 pid:40406158 +eyr:2032 byr:2010 + +eyr:2023 ecl:hzl cid:162 hcl:#602927 iyr:2015 +pid:82885029 +hgt:75cm byr:1946 + +byr:1962 hgt:167in +ecl:brn +hcl:#c0946f iyr:2014 pid:488520708 eyr:2027 cid:271 + +hgt:180cm pid:358771245 eyr:2020 +ecl:grn iyr:2018 hcl:#efcc98 +byr:1979 + +cid:273 ecl:gry pid:424388351 iyr:2010 hcl:#c0946f byr:1988 +hgt:166cm +eyr:2027 + +ecl:gry hcl:#a97842 hgt:189cm +pid:743213778 iyr:2015 byr:1959 + +iyr:2021 byr:2021 +ecl:#a79d2e cid:89 +hcl:#5fb8d7 eyr:2001 pid:#5575b3 hgt:60cm + +eyr:2021 +iyr:2017 +cid:87 hgt:164cm pid:560394910 ecl:hzl hcl:#ceb3a1 +byr:1955 + +iyr:2018 +hcl:#27f7e6 hgt:160cm +eyr:2029 pid:033692111 +ecl:amb byr:1920 + +hgt:160cm eyr:2028 iyr:2010 ecl:blu byr:1974 pid:858060501 hcl:#733820 + +byr:1961 pid:818700605 cid:93 eyr:2024 +hgt:188cm hcl:#866857 +ecl:gry + +eyr:2029 +hgt:180cm iyr:2017 +ecl:hzl byr:1951 cid:158 +hcl:#888785 + +cid:290 +eyr:2027 byr:1986 +ecl:blu +pid:076339632 iyr:2010 +hcl:#341e13 +hgt:167cm + +eyr:2023 iyr:1990 +hcl:#623a2f byr:2005 hgt:116 + +hgt:167in iyr:1944 ecl:dne eyr:2031 hcl:465775 pid:2505694463 + +cid:93 eyr:2024 iyr:2010 +hgt:143 pid:154cm +ecl:#c6f352 +hcl:#a97842 byr:1925 + +pid:600685520 byr:1967 hcl:#ceb3a1 iyr:2014 ecl:oth cid:226 hgt:179cm eyr:2026 + +hcl:#ceb3a1 +pid:789956738 +byr:1938 hgt:171cm cid:183 eyr:2021 iyr:2011 ecl:amb + +hcl:#613f4b hgt:151cm eyr:2025 +ecl:amb byr:1985 pid:493339889 +iyr:2013 + +hcl:78cda6 pid:36823553 +iyr:2021 cid:235 byr:2028 eyr:2011 hgt:113 +ecl:#02ce86 + +pid:529274811 +iyr:2012 hgt:103 ecl:blu hcl:#341e13 eyr:2023 +byr:1959 + +hgt:166cm iyr:2014 ecl:xry cid:276 byr:2014 hcl:#7d3b0c pid:146851133 + +pid:359823289 hgt:181cm byr:1978 hcl:#c0946f +eyr:2022 +iyr:2011 ecl:hzl + +pid:029400877 +eyr:2026 +byr:1983 iyr:2015 hcl:#cfa07d cid:70 ecl:gry + +hcl:#ceb3a1 eyr:2021 hgt:190cm +ecl:amb iyr:2017 +pid:411804678 byr:1950 + +byr:1926 iyr:2017 ecl:blu pid:103821113 eyr:2026 hcl:#c0946f cid:71 hgt:152cm + +cid:108 byr:1955 +iyr:2010 eyr:2022 hgt:169cm hcl:#733820 +pid:208715596 ecl:gry + +pid:352807405 ecl:blu +hcl:#b1214c iyr:2012 hgt:165cm byr:1929 +cid:139 +eyr:2020 + +hcl:#cfa07d hgt:151cm byr:1987 +eyr:2024 +cid:140 pid:884441477 + +pid:#dade9c eyr:1979 hgt:191cm +byr:2026 iyr:2018 hcl:z ecl:lzr + +cid:259 +pid:644561358 +ecl:blu hgt:164cm iyr:2013 byr:1997 +eyr:2023 hcl:#108f16 + +ecl:oth +cid:141 hgt:66in pid:877258886 iyr:2019 byr:1949 hcl:#18171d +eyr:2027 + +byr:1932 cid:103 hgt:175cm pid:464473181 ecl:xry iyr:2013 hcl:51fd65 + +cid:175 iyr:2014 eyr:1959 +ecl:#d83076 hgt:182cm pid:863972537 hcl:#efcc98 byr:1986 + +hgt:181cm pid:869641194 hcl:#efcc98 cid:141 ecl:gmt iyr:2017 byr:1981 eyr:2027 + +eyr:1938 +iyr:2026 cid:278 ecl:brn byr:1936 hgt:150 pid:6902040050 + +eyr:2027 iyr:2014 pid:110887179 +hcl:#a97842 ecl:brn cid:262 hgt:66in +byr:1954 + +ecl:grn +pid:498972747 +eyr:2024 hcl:#341e13 iyr:2011 byr:1932 hgt:186cm + +cid:59 +hcl:#6b5442 iyr:2018 eyr:2028 pid:866696485 +hgt:178cm ecl:gry + +pid:598961001 +eyr:2024 iyr:2019 +byr:1963 ecl:grn +hcl:#c0946f + +eyr:2024 hgt:172cm pid:295056305 ecl:blu byr:1926 +iyr:2017 hcl:#341e13 + +byr:2001 hcl:#6b5442 hgt:164cm +pid:862982189 ecl:grn iyr:2019 eyr:2030 + +hgt:69cm eyr:2014 ecl:hzl iyr:2025 +hcl:2812c9 +cid:74 byr:1980 + +hcl:#888785 +pid:409489862 +iyr:2011 hgt:186cm ecl:gry byr:1985 +eyr:2028 + +cid:221 pid:6849250876 hgt:169cm hcl:z +iyr:2013 +byr:1950 eyr:2022 + +pid:189083891 byr:1983 hcl:#623a2f ecl:hzl iyr:2013 eyr:2026 hgt:66in + +pid:581546673 cid:269 eyr:2030 hgt:191cm byr:1945 hcl:#18171d +iyr:2015 +ecl:amb + +hgt:158cm ecl:hzl +cid:234 eyr:2023 +byr:1996 hcl:#7ac7ad +iyr:2020 pid:666748924 + +iyr:2013 ecl:grn cid:53 hgt:172cm eyr:2028 pid:406602771 hcl:#fffffd byr:1959 + +hgt:63cm hcl:eaaf60 byr:2026 iyr:1981 +pid:#baf2cf cid:117 ecl:hzl + +eyr:2035 byr:2014 +iyr:2028 hcl:z ecl:#acd426 +cid:261 pid:174cm hgt:182in + +ecl:amb pid:#4bb0a8 eyr:2027 hgt:155cm hcl:#623a2f +byr:1956 +iyr:2011 + +eyr:2012 cid:53 byr:2005 ecl:oth +hgt:183in iyr:1974 pid:150cm + +iyr:2020 pid:833821322 ecl:blu byr:1944 hgt:169cm hcl:#623a2f eyr:2020 + +hgt:60in ecl:oth byr:1962 eyr:2022 cid:99 +iyr:2019 +pid:281039464 hcl:#733820 + +ecl:hzl hcl:#7d3b0c hgt:191cm pid:771871096 +iyr:2012 eyr:2027 +byr:2025 + +hgt:188in hcl:z eyr:2032 iyr:1955 +byr:2027 ecl:#517bfe pid:#206bab + +hcl:#733820 iyr:2010 pid:784128823 +hgt:169cm cid:305 +ecl:grn byr:1962 + +cid:50 eyr:2022 +hcl:a916cf pid:407148034 iyr:1926 ecl:#fa1ba7 hgt:69 +byr:2028 + +hgt:193cm pid:507697987 cid:275 byr:1958 eyr:2023 ecl:brn iyr:2013 hcl:#326596 + +eyr:2025 hgt:192cm cid:95 iyr:2011 ecl:grn byr:2002 pid:399623583 hcl:#b6652a + +ecl:brn hcl:#602927 eyr:2023 pid:089068603 hgt:189cm +byr:1953 iyr:2018 +cid:160 + +hcl:f1bf94 byr:2030 +ecl:gry hgt:60in iyr:2016 +pid:4816152 + +hgt:154cm iyr:2015 ecl:gry +eyr:2024 pid:718845487 byr:1999 +hcl:#866857 + +cid:294 +hgt:186cm eyr:2026 byr:1984 +ecl:grn +hcl:#ceb3a1 pid:325370778 iyr:2010 + +pid:156980004 hcl:#c0946f iyr:2013 ecl:brn +hgt:181cm byr:1933 eyr:2023 + +hcl:#efcc98 byr:2002 hgt:158cm ecl:gmt iyr:1964 pid:195262032 +eyr:2021 + +hcl:#602927 eyr:2027 hgt:192cm byr:1945 iyr:2018 pid:366509171 ecl:oth + +pid:163cm iyr:2016 ecl:lzr hcl:#341e13 hgt:79 +cid:130 +eyr:2038 byr:2030 + +hcl:#efcc98 +byr:1979 +ecl:oth eyr:2020 pid:095314628 +hgt:162cm iyr:2015 + +byr:1998 cid:157 +pid:346442779 hcl:#b6652a hgt:162cm +ecl:amb +eyr:2023 iyr:2018 + +hcl:#d6a701 byr:1971 hgt:160cm ecl:#98c896 pid:627704105 eyr:2024 iyr:2010 + +byr:2021 +iyr:2023 +eyr:1981 hgt:68cm ecl:dne +hcl:z pid:20981493 + +pid:159037919 hgt:162cm +ecl:amb cid:244 +byr:1971 eyr:2027 +iyr:2017 hcl:#18171d + +iyr:2011 pid:086826874 +cid:162 +hgt:189cm ecl:gry +byr:1926 hcl:#888785 + +eyr:2022 hgt:152cm pid:919970712 byr:1955 hcl:#733820 iyr:2018 ecl:brn + +cid:111 ecl:#a1843f +byr:2015 hcl:z iyr:1956 +pid:186cm eyr:2030 + +byr:1991 +eyr:2024 pid:050818633 +hcl:#888785 cid:124 hgt:176cm ecl:gry iyr:2018 + +byr:1963 hgt:188cm +eyr:2021 cid:255 +ecl:oth +hcl:#a97842 +iyr:2010 pid:030540064 + +byr:1921 hgt:164cm pid:748078322 hcl:#c0946f ecl:blu +eyr:2027 +iyr:2020 + +eyr:2020 cid:214 hcl:7a942e hgt:191cm byr:1998 iyr:2012 ecl:grn pid:054135231 + +eyr:1927 pid:242147946 iyr:2010 +hcl:ea3cb1 byr:2028 +hgt:186cm ecl:dne + +ecl:brn hcl:#efcc98 eyr:2021 +hgt:160cm pid:333644730 byr:1999 +iyr:2019 + +iyr:2013 byr:1921 +hcl:#a97842 eyr:2027 +ecl:gry hgt:157cm pid:682013109 + +ecl:gry hcl:#733820 byr:1945 hgt:174cm +eyr:2020 pid:505827627 iyr:2019 + +eyr:2021 iyr:2015 ecl:oth hgt:162cm pid:137342936 byr:1922 hcl:#888785 + +hcl:#efcc98 +ecl:oth +hgt:151cm cid:312 byr:1983 +eyr:2030 pid:289512908 iyr:2020 + +byr:1989 iyr:2015 pid:057335770 ecl:grn eyr:2022 hgt:167cm hcl:#602927 + +hgt:184cm iyr:2013 hcl:#c0946f byr:1969 eyr:2028 +pid:802041641 +ecl:brn + +pid:155cm hcl:#b6652a cid:288 byr:2028 iyr:2028 hgt:150cm +ecl:#996e72 eyr:1960 + +eyr:2020 +iyr:2011 +pid:934576102 byr:1994 +ecl:amb +hcl:#18171d + +eyr:1993 byr:1995 +hgt:64cm iyr:2020 pid:15714997 hcl:#b6652a ecl:blu + +iyr:2014 +eyr:2030 pid:866047540 cid:59 hcl:#733820 byr:1951 +hgt:64in ecl:amb + +iyr:2015 +byr:1962 +hgt:69in ecl:brn +hcl:#623a2f eyr:2023 +pid:671492881 + +iyr:2020 ecl:oth hgt:154cm byr:1950 pid:924256973 +eyr:2028 +hcl:#b6652a + +byr:2021 +hgt:116 cid:348 iyr:1930 pid:76948864 hcl:z +eyr:2036 + +hgt:156cm iyr:2014 +byr:1960 +pid:720786216 +cid:99 +ecl:gry +hcl:#a97842 +eyr:2028 From 4cf562410a901100c718ddf3f9ad0b6fb560038c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 4 Dec 2020 09:50:41 +0100 Subject: [PATCH 043/129] 2020: d04: ex2: add solution --- 2020/d04/ex2/ex2.py | 109 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100755 2020/d04/ex2/ex2.py diff --git a/2020/d04/ex2/ex2.py b/2020/d04/ex2/ex2.py new file mode 100755 index 0000000..61cc674 --- /dev/null +++ b/2020/d04/ex2/ex2.py @@ -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() From b25f2908d5f2f736ee35b570f8772e5bd074a6c5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 5 Dec 2020 09:28:45 +0100 Subject: [PATCH 044/129] 2020: d05: ex1: add input --- 2020/d05/ex1/input | 781 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 781 insertions(+) create mode 100644 2020/d05/ex1/input diff --git a/2020/d05/ex1/input b/2020/d05/ex1/input new file mode 100644 index 0000000..5145d8e --- /dev/null +++ b/2020/d05/ex1/input @@ -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 +FBB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+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 From 390eb447ccaf1590c9dddb6c02cba8f62abaee28 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 5 Dec 2020 09:28:52 +0100 Subject: [PATCH 045/129] 2020: d05: ex1: add solution --- 2020/d05/ex1/ex1.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 2020/d05/ex1/ex1.py diff --git a/2020/d05/ex1/ex1.py b/2020/d05/ex1/ex1.py new file mode 100755 index 0000000..1d9d023 --- /dev/null +++ b/2020/d05/ex1/ex1.py @@ -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() From 18d95d86658f181246b8861d25aaf96b6cb48517 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 5 Dec 2020 09:29:06 +0100 Subject: [PATCH 046/129] 2020: d05: ex2: add input --- 2020/d05/ex2/input | 781 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 781 insertions(+) create mode 100644 2020/d05/ex2/input diff --git a/2020/d05/ex2/input b/2020/d05/ex2/input new file mode 100644 index 0000000..5145d8e --- /dev/null +++ b/2020/d05/ex2/input @@ -0,0 +1,781 @@ +FBFFBFFRLL +BFFFFBBRLR +FFFBBBBRLR +FBFFFBFLRL +FFBFBFFRRL +FFBBBBFRRR +FBFFBFBLRR +FFBBFBFRRL +FFFFBBFRRL +BFBBBBBLLL +FFBFBFBLLL +FFBFFFBLLL +FBBBFBFRLL +BBFFFBFRRR +FFFBFBBLLR +FBFBFBFRRR +BBFFBFBRLL +FBFBBBBLRL +FBFFFFFLLL +B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R +FBBFFBBRLL +FBBBFFFRRR +BFFBFBBRRL +FFBBFFBRRR +BFBBBFFLRR +FFFBFBBRRL +BFBFBBBLRR +FFFBBFBLRL +FBFFBBFRLR +BFFFBBFLRR +BBFFFBBLRL +FBBFFBFRLR +FFFBFBFLLL +FFFBFFFRRL +BBFBFFFLLL +FBFBFBFLRR +BFBFFFFRLL From 233caf8b115e8848f746f361f1d1055402d39e87 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 5 Dec 2020 09:29:34 +0100 Subject: [PATCH 047/129] 2020: d05: ex2: add solution --- 2020/d05/ex2/ex2.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 2020/d05/ex2/ex2.py diff --git a/2020/d05/ex2/ex2.py b/2020/d05/ex2/ex2.py new file mode 100755 index 0000000..05fa9b2 --- /dev/null +++ b/2020/d05/ex2/ex2.py @@ -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() From 032223781dfb0fcb217b4b0e9c32b74ba4f1c000 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 6 Dec 2020 07:22:31 +0100 Subject: [PATCH 048/129] 2020: d06: ex1: add input --- 2020/d06/ex1/input | 2246 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2246 insertions(+) create mode 100644 2020/d06/ex1/input diff --git a/2020/d06/ex1/input b/2020/d06/ex1/input new file mode 100644 index 0000000..7315fba --- /dev/null +++ b/2020/d06/ex1/input @@ -0,0 +1,2246 @@ +lfnghcsvpyrdjtxozimb +mdtbnorpfalcijxvhsy +elmwjkfbihydxcpqtovsrun +tlhmsdjingyxcbfrvpo + +a +a +xqh + +mxdeqcinvfg +vbncrgzxqefka + +oejsdfwm +fojsmewd +ewxfsouimdj +eodafjwsm +edjwsmfo + +d +d +j + +mgxywknlt +khgwmr +wkpezgboavm +mjgkwni +mwkcg + +mqzjtgskhadecwy +nhkjeqgdtfsa + +rc +cru +hcr + +vuaeqdcnty +nltovzycbeidu + +phcqe +chep +hpce + +smjuow +jwktu +ujw + +ljphnwtmugi +giltnpuwm +mgtulpkiwn +uxltinpgwm +jmglintwpu + +slbguajo +lqwardbuo +zlqmdobau +ucalqob +lobua + +uwtcp +umtlwc + +lrcpgjwqfaybxtisoznuhe +wjpnrsxiultyabgzhcqfe + +clmfrxgbqikzpsoduvjy +uoxibjmkygrsdqczplfnv + +oncmzsf +onzmds +snzmo + +zlmegxcnavjb +bmloajdecvwzxgn +pjgzecxvsmbhnla +fngpcvhaexzlbjm + +ulhkjzxadgvc +uejbgctld + +xuindfqzvpg +ugdofws + +qrpvexjlywfmgbintuzk +wrtnibqvuflkeypxg +kretgquypbinwxfvl + +tmrdpzxvily +itorywvlxjcd +rltdvygbxic +xyliotvrdc +xrvtdilygc + +uihswfvanoyzl +owgnzcshuvaqlfiy +whrtnuoyimzlsvqfac +jiekwxbznhfvuplo + +jgbtesurivfxclapnqdmkzhyw +dcnjhsqgkzyitwfplvearubxm + +umovhtgaekjixwfcdnq +fcoamwkvjeqxhdbgitn +datcxweqzhirmjfnkogv +vwahorqcxfilmkgtndej +myhkadptsgcxfojinqewv + +oys +syo +oys +yso +oys + +fatvyeruxnilcmpd +ydacelgfmrxtvin +tgdirmynaxclqwe +jstnbxmdlcezhraiy + +fkbnpgyhs +ktnhbya +ybhan +wqconhbey + +zicrfu +dblyczk +eshjmczvn +cdzgofpx +rawzc + +hcuypzdfalvt +dfplcsyvazrqh +lfcdvzrhyabtqup +lycegwaofdkmzpnihv +ayvzdhscplf + +rvowpcnbjlfhe +hsgbdivpcjlxo + +wbiplofhkmgvr +wvmrohkbfeglpi +bvklotpghrfiwm +wltkighfbrmvpo +bgvkflitwhmpor + +dwmorjebnchvuaz +hyikgfenl +nykhxegq + +pnsactlj +knytclorg + +w +wj +w + +gushnlqjctfvwiyz +shtqjuvzcgniy +cgdusyjpntzivqh +ivuzjgcnqhwtsy +vcusgtqinyzhj + +fjnacgiw +ngijcfw +gcwnifjo +wvhsncikgtfj + +tecvxgzsjridpa +azvtdgprjesixc +mxspejvzrdcaigkt +vristcjaexpzdg +jvipeagxdtczsr + +v +f +w +w + +wrsxdmlay +yxalwfs +xlatysmwe +bgqyohvpzswnlxujcak +silxayw + +zxelswo +slwzpxo + +aizvyoqg +ealnxdyczgpsrj +hkmwbutf + +cohalxbk +suiydp + +qebdumfwsjagk +cxaokgmr + +r +x +a + +xhey +exhy +hxey + +zchi +izhc + +dh +dsh +hd + +lfjcmoauvzxqitdspbw +febzhrmowptvsqiyaudjkgc +ijausfvcdznmpqowtb +vcsfzqbjoipuwadmt + +up +rkpy +nzjdbg +twkl + +tuepkzc +opzst + +rgszfijlxneuvqcmktpa +azcjfnkuvlpegmrsq +fgjzkvusqnmlcarep +kvrcpumgsfqalezjn + +tvqiwkmdf +qfdtvowsk +tvkifsrqdw +vgdxeubfkjhqzlpwt +dvkytawfqm + +yhiogvbkxlzjwsafd +fylwkxhotbasivdjzg +cdjfgnkshmwyxvaliozb +xusvawyhzklgjoifbd +vkisfrjowaxhglydubtz + +kqws +xqysrkw +lcjsqkmw +qwsk +koqsw + +wc +cjw +wc +cw +wc + +awrshieplc +ixelpycsrvw +qebsmzklpwiuocg + +cxf +xf +najxvf +xfh + +umgylpoz +fxwcyet + +yt +t + +gbeskji +ejbsqki + +grmdbezfou +ufzbredgom + +wmtvcfhk +cyleh +prseclyhz + +cyrwzamnoxhue +hxacmyenru +ndyrashxgmecu +eilychmuraxnfbtv + +fbgwal +ablhjg +agxlb + +cvw +vcoz +nvmrc + +prvbngaqh +qbhgpvarn +palgyevfrqnhb +vgqnbarhp +rbhavqpgn + +fztoevmhwgnb +nbhfweomvg +zfmghoevwbn +vhmsfgwcbeonq +negfvwobhm + +qbx +dev +hyzl +wr + +ltnibrq +qrbnil +rlbinq +qinrbl +irnqbl + +thfng +gfhkbd +hmucga +rhdg + +fqwalrhvpyxieu +plehrstgivfx +xbcvtrpefldih +efpxrlhvdi + +kculvzfnesawmty +vkztnuycwfamlse +ecvnzlumykwatsf +zatkulemcyfsvnw +tafczlusnywekmv + +a +a +a +a + +cktun +lnrdyfk + +rexndcwvkibpflzjqymu +exivdprnjzyblfmkwc +czbknjlrfdivxypmwe +fjvgyixpedkmrwzncbl +hricxbjypenlzfdwvkom + +vqebrauop +ebopavuc +upabhveo +vobeaup + +iaxlnehuycwkrmzqsbp +bynlcreqpswzmxikhau + +nb +ikqoh +ho +qjh + +oaixhtmeqc +envpiuhkqdmjx +xhforyeqwim +hcaezwimxq + +ctubrpd +dstub + +vchgnkea +hkegyxivc +fpychegtvk + +apxkiotyjzsqufvbld +daviftqlxopsbyjku +zblyqpajvkdsixuotf +lafqdsyjuckbtoixvp + +pmlwfdcbik +xzjebqshotrnygu + +cepzjtkamvnfuloqrig +vkoiepjfnztuglqmarc +pnjrlqgmkzotiuevfca +tluscvmjrzkgaeipnfqo + +k +k +r + +ae +ea +ae +ea +ae + +ypvtzi +mtu +tjs +fjust +ufmtj + +zilgoaqmr +aqopzmuvxlwrjg +ozrmnadbqgl + +rbfm +r +rep +vfmr + +ajrsgqiodfmwuezkltv +tqsfiwvgzmeurdkajlo +sqgywzoakturjlimfdev + +wplbfyivhasrujdgzqcmxnk +tklsezcwrihvj + +vshfrae +bhnocstidq +xlhsfmza +swlxah +mpksvhy + +uelktdbswyjpaxqmnr +ruvwjsnyadhmzepb + +jepzvwaqublirdftgcmx +lwncbxgqkvdjpztiuamf +vxmfwtlaibpjgzucdq +pfidxgumvtacwblqzj +dsgivqfnptwzmbaxucjl + +gotqzew +jdfn +dub +v + +nzj +jg +g +vp +n + +clbgtr +tgrlbc +rtbclg +rtbylgac + +uyit +iuqtpc +ituj +tui + +jlsipo +hpijl +solxjip +izplej +xlpitsj + +zd +grntma +w +iz + +lkxgcpywohifnu +hyglocfnkpqwux + +fjz +hj + +fxpjdrglkntmzce +qznmtgfpljcrhd + +w +hauesfy + +goixwvdy +dxivyow +dowvyix +idxowvy +dvowxyi + +bw +y +swg +uyw +aijx + +xhkdzbts +pedonw +gqld + +neslgchypjqavwr +aclkpygqtnwiosh + +vboyhcijednm +neyvjcd +yvdjnec +ednvjcy + +pezkudgxf +zpfxgkbedu +exkzgfdpu + +oulheigbsfjn +ltnagbieju + +vmyhslndzaroiqpgxutfk +dpilskvjutayrghzon +dctniozulkhpsvgrya +srhtzkyupavdngoli + +aeybn +slcoixqtkgh +bw +rvfzp +uynjmpd + +zexkwslndgyi +encftykmx +rhbenmkoyjx +xymnrke +kyxjbnumer + +egdq +efkxg +lmnscieutozapj +wye + +nk +ny +wn +nk + +wnmubxsrvqzcyhtpjf +sjymafxtzhcnriubwv + +msub +ubvyhkm +ulmocbq +blfcuepqm + +gtsfubrozwdiapm +oqkuvhncxbzip + +vfbklexjnhziwsayqtrpm +ntrzifljyqvesamhpk +hnvmkyprultqsifazoejc +ejcvmtnipfalyrhkzqs +qtiavmhrlneydpjgkszf + +yxst +hgtwy + +ymf +yv +zpdyb + +amdhqbzjkxilowtuvgnrfpsy +fugmwydqvsihkntlxjeazbo +rsvxyzqjoadibglfthunmkw + +qzbsk +bqzsk +zsbqhk +zkbsdq +qdbkzs + +dwlij +jldiwn +jiwnl +ljwrbi +jiwl + +nmbhlqkaovrgiudte +dbnotamqvikeglhzrx +ohgnmkrztblaidvqef +tbqvahorjgniewldmk +qrtvyobigemkdlhan + +par +rpx + +rq +r +r +r +r + +nuxaoymrctdsikpeghzqwjb +lrnpzwbyiksdcjeumxga +efzlgxyvdubrsmjwpnakci + +ftm +t + +zjydrsx +syrxjdz +sjrxyzd + +rxczvljiahfwmbok +olznqgdawfjtchibvmrx + +ydlwknjzhugeamq +jzvylqmgdewhaukn +zyluqhnewjdamgk +lnuygmwdaehkqzj +jindyaeqzulwghmk + +ujcbsanxhmltdvzeg +uznjaedcmlgstbhxv + +ejxp +dypjn +lan +bwgvkrm + +v +s +s +s +s + +rdswzekavfj +jubothxgani + +jazgdw +gazjdw +gajzdw +wdjzga + +mnecwfslyp +yfntmsl +mcnfghls +xlinzojsvm + +ocgxrsmheynbvuiw +handgupyeslixmwcbvr + +yfzhmrpdkustegwoalbq +lyftdmopzrewsgbu +rwuglfsbkdtcnpqozme +etzuwbsoyprfdglm +dmwtljgrszpfeobiux + +ealrftgbzy +blgearjyz +yngdbxclrzmea +jayfrezbglh +leargyszbf + +clkedspwxzqhfojb +nsxhezwcjpkdfoqb +czowphbeskfjqxdl + +pkzoadrt +dozrtapk +dtorzpka +atdpzrko + +vrjyxhnqfg +yjhrnvqag + +owgadqkfusicxrztl +qicupjdzgkolftw + +o +q + +csbaloz +cozblas +soczalb +lczabso +mtozcbsla + +faljzbneuxympogctdi +cailgjmzqexdptbvfynu +wjpknbfhelcimtxrdyzg +gmyebdfipnxljczvt + +j +j +j +j + +getbmjnwazok +czenqpftw +nlxzweqtf +drwuzetnyl + +ywmi +sgqdt +lnhzfxpbruovja +cqe +gyk + +vp +dxesf +krp +ar +gz + +xeo +q + +myfw +qnelw +jrodw + +ndajkhfmzxslvopb +ajsckbhdpqfnlgzmvx + +imldxsptvaqyhcgbjn +ghnyicdvpqtljasxbm +lqjesvdhtbaxpmcginy +andpytcblvsixmghjq +tdvyxcnimahlsjqgbp + +vsopuwdxhtabgej +gjahsudbxtwpeov +vsawxbgedzotphju +detawvgbouxhpsj + +xriwbfaocqgztydvnelkspj +xkjfpcaqibswtdelyrgzovn +zpdexnfwalqhyjsokgbvcirt +zevfqwxcrjplgoskyitadnb +jcsvkgtwezobdnxyfqprial + +uvigr +i +i +i + +zyatdpgjrle +ezsyrdhxptav +kapdyuzreotm +qeryptdagz + +z +z +z +z +z + +sizxwqmegyflndk +fnweyjdbckugxtmpv + +vjtkzol +hwjtzmqdykosv +jtzokev +xztkvojc + +o +utxgqfenh +d +yvkj +kswvm + +uefcqyzgalm +qafcezlmguy +cumafzlgeqy + +lmfzyt +mltf +tlgfm + +ne +eu +e +zen +e + +tepckxywbnuqahilvr +cwqpuveanixogmbtlyk + +mgyu +usyz +nyu +uy + +hvnilwjcgbekmt +mljgckftviwhneq + +rdaspohl +lfxjad +amdl +dla + +ncjmux +hxzemjuoqnc + +slhdpwkc +plhkwsc +wslphnkc + +kx +kx + +klbmqja +cbpikxjoaswyhg +lakbmuj +kbja + +do +dl +qd +d + +uwbktzrfax +xfvtkl + +pvylfnsder +dnfprelvys +srlpdefnoyv +fvnesrpldy +rdfyneplsv + +cietjkmyu +gkqjcrubel +gvjouc +ajuco +nsfjpdcwuh + +zeacqhdkltxi +mtldxqcha +adqcxlhwt +whatcdxql + +gsrhkdwnyt +wvngykhtd +otvwdnhgk +dkmtnhwg + +gdq +asgqd +gkuqd +cgdaq + +amoriyvlens +nfrdvltkyes + +bgemhciuqtnpw +jqwtgbpcnhmui +zyogtixnwmhcqbp +gqtwinhbcmepu + +jn +nj + +gkqz +gvjyzmk +kagwzf + +qimgwjex +qcxjemi +xjmqige +jqxgmei +emjxqi + +bftzjip +fkjvzbcy +kzjthybdm +nogjbrezl + +lukfvrc +lkrfucv +drbfuklvc +uflckrv + +tekijdqozns +djsiekoqtn +noektqjdis +hndojsiqekt +usndjteqiokg + +cw +c +cs +wc +cn + +lxfgopvmh +ckpatzifnwxsjum +bfemqdyrpx + +xosicnwrb +wsocbr +brwcasoy + +esiz +ise +ies + +dcungxvhipzorlbwsjqkt +pvgzlihbocskdnuwqxjr +jwqvrboixdchpsklzugn + +jsizhem +zjsbhi +tjhzu + +tgldmihkjb +hbekplin +borvflqchzauxi + +eosqa +zpqgusowa +okqslrae +qofskay +olaqst + +dbulmwerfxjoiha +jdiwhoumflbxra +rxbdihmofuwalj + +gqzwfumsipboyjnl +forhywgnulpsbmiz + +ql +qml +owq + +dpbxiqjy +bxyqjpdi +yisjxpqdb + +hxcrzpjvmnkgeuo +hryatdbx +rxlhytfwds + +ljdozibqytwnfhvkxp +fqxiwhcyzbptkjlvnod +iptkxndvjzlyqwmhofb +efgvoxydhpjqiztwlbkrnus +vfzqpjblnidytkxaowh + +onewvclt +vhcteos +vecnto + +fpoisndugqmb +fqkgntpwjbmdus +elfqmcnbudgshzp +gnqpdmbfsvu +snrqdupbvgfmj + +euvtmyohfqkscjdn +fydvukotsmpnjhqec +fhqumnvydstkoejc + +zcoupardbfvns +siufbpodcnlva + +dwkfe +nfdz +ibjodf +xdyhvltgpu +dzjnmrcasq + +k +k +k +bk +ckj + +tavfsckigh +hquzcnbdorlwm +ycgh + +qplvetmdc +qdmvetcpl +pqmdcvtel +lpetvmdqc + +lhcq +qcuk + +whmnsqpkjov +wtjgu +tlcjdw + +egicls +cioegs +cesgi + +lxaifjhyrqgsem +mafexiryqdsjghl +xemjlkgfqyraish + +zwrdcmavo +zvrcadfmo +madfozrcv + +slfagzbjwotdni +mdspebtajxfiwknzlc +dqsitfarvljnbzhw +auilefztdjonwbs +tsiebdwjlnfaz + +svgnwpr +nsaiguwl +xmplcdgsn +eotjkyshbqnzgf + +bl +ly +iafxle + +wnckbplriv +ixdbelhpgmqfscvwzj +lpwivbc +byptliwvuac +vbicwoklpyu + +eskwamyvgxzqbtprculijf +eipbrxystfkgucjazwqmvl +wvplyjkrbcguzqsfteimxa +vhtrlousjbpmfzanqkwgcxyei + +p +m + +ntfspeyqrj +pqyernsftj +tnrspejfqy + +gx +x +x +x + +gizducfvmtohe +genmuitdvzkhxf +tbpyaruimeshzgwldqv +kidmjnuovehzgt +mxthzudigve + +kudjgcbhna +lcajungkd +chdankjug +cekjgpanud + +zqlucvfkmnpoighxb +ohcpgetlvzufinkqmbx +cunpqvgkziflbxhom +cgklbnvfxouqmpzih +kjimlchzgxpqvyuofbn + +uwmz +nz +zbofx +zw + +r +or +av +j +j + +tvbqc +qedctbv +tqzvbc + +t +t +ts +t +t + +qhkbwa +awubqtzx +fqbyja +mbaiqhrt + +wzcuyqanpdtsghr +zpocrshdwynaqtxvge + +gpq +qeh +cq + +jfltaouwri +ygbxsqdz +skd + +jmlh +hlmj +hjlm +jmlh +umihknslj + +ute +ltdzqf + +ygkx +mywxcrd +apyx + +xy +y +dy + +mivusqxpzyljehgkotrf +ajlizqnpegckfohdvsxrwb + +pl +lp +pl +lp + +xmnaupwtcvozrfekbdshlq +dlafzmnhvpeskwoqucb +uzydhfovwmapneqlgkbcs +cjapswblfmnzqokeuvhid +dzlaovqnmsuwkhcyfpeb + +wpb +bp +bp +bp +bp + +pusm +umpshr +musp + +xdz +z +f +ecjo +nkxz + +tjmvdf +st +trn + +hkfgarys +rghfasy + +ljyixtumsfngvdwoqzpakecrbh +kfpuvicgrsnoetabmywjzqxlhd + +az +z + +rgkf +khrgn +nrgk +gkrfoc +werzgkpa + +vkg +k +k +ku +ik + +blruxyvehtsn +thdl +mtldh +lht +thil + +rnzqadiplhbegj +qlezpgnabdrji +lnrzaqjpdigeb +rbjlnpiegqazd +jprzlegqdbnia + +kgo +okg + +rjm +kiml +cuxstqpwod +kghb + +yckovthbrigazfxq +atriygxofzkcqh + +vudbtxjpgaqfzhlkmncswyi +lgfjahksybqmncoeuwvixtrd + +dmlyrgkwfjovqasxit +ylawsjxrftdegmkqvi +stqgmxfrjvlkhaydwie +mypcdrjnkgtsxvqawlfzi + +ethrvfnyasdkb +eanwdyfcsbhr +xayerdsbhlf +ejdrshvywbaf + +hqyfnrxjzsd +buly +yukpm +likmy + +zlpditkvsawocunjqyhmrx +rdtjsunpqymlhxkvcwzoai +oaprkqhumtvlcwxdnzsyij +uxmdclkpjqrotahysizvnw +olwhpitmraqdnkxuvjsycz + +srnhuf +hrsxfwynuo +gnzsfbutcrh +krnhusf + +l +lsb +ujqtvol + +cptnhxgdkivyjlsbrwmuf +nkbshfmrxgjdoclwivy +fxibalcmhydvkjnwgsr + +txye +cjvqsulagn +kihdbf +ohpmzwr +rbtw + +tgm +mgt + +nhucrjmq + +rubajlyszwn +nlbsjzwryau +zrwuynsjbla + +flvdypkxabzm +lipzbtrmqof +ljmghurbifpzns + +bsv +wsux +vs +s +sv + +vfqsehx +xseqvhf +svxefqh + +fipwjdl +jpilwfd +whflvdipjx + +oclrqnubyhpmdks +wmkchdsqujbpxlnyo +onulmdsbyhkqp +mlubkpyhnqods +tfmesqblonudihypk + +gcwf +a +v +q +o + +xpqlzcfvtjgr +fxwprjglmasiqev +xljpgbrfqvo +fbvqrcgxpdljt + +nxpktofqglvrsjbi +wvkotsgijlbnrufdxq + +rpfew +iflep + +tdy +teyvdjo +tdy + +ix +gzkwchaqd +oysure + +hxvkjmneycuspbwroqaligf +qkhpisjmxblnwezrgoauycfvt +emcqhiufkjbrlwyngapsovx +aixrbgcfynwelsoqkpmhjuv + +ckxhmridjbfalqo +yzunwpsdlgev + +ls +lzk +sl + +kdpzmau +gzamukp +kpfua +pkau + +usmywivnpgt +biqxymnosaklrehzj + +orwcjpkbiexz +bpzikgwn +winpbkz + +wobslxnhfyjtg +vqdecolzarnm + +rgfloc +yufcor + +tgwnebxyzkchqvoulmprdijasf +zmpdjlekigtswronhubqcvfa + +fyrbd +yfbr +frby +fbkghytr + +stexkgyiqpaodnm +opecuqrdnytkxaig +oxykdtnaegpiq +xtgaydoepqikn +oyktnixegqpbad + +irgbyxhwm +iwgykrbx +yibgrwx + +dxejzvrocb +tbxhmqscrid +cjrodlgbxz +zcbxwpjrd + +l +lg +g +lg +nfi + +ab +aw + +vlbi +zegtwnc + +dgbj +dgjybl +ardgupbsqjv + +xoquygizahnwpkvds +duaoyzvgqxhkiwspn +gpvyukzaiqdnwoxsh +qpwnyzihovukasxgd + +fcepzibvulyxhsjqdanwmtrg +bijrdfxcqhplwnymsezatuv +uxbcwnrmisvqhljpzdaetfy +umwzscitfjhxyrelpvdabnq +usahyzdmtqfibxcjvlepwnr + +tpk +gzetqkypuhj +pknct +mfticpk +akiwtfsp + +qedhju +lvdqtzehyj + +vyfe +vey +yve +yve +yev + +dseopbmfcuk +msfekpuodcb + +jm +jm +mj +jm + +jfgevdqxm +mqftev +fmeqv +etfmqv + +grhalzpfsjweuyt +zteylfsaugpj +jtuzpeyflgsa +zlajntyufgkspe +fjyapletgzsu + +ixhz +n + +mqekbhiu +ikgbhmeq + +xscglkt +ctglkxr +kxlctg + +siygouxkzhetdrqcfp +eiftxuyhpkczrqdsgo +qgfryxepotiucskhdz +pfruziqyxgedkthcso +pezofhisdcxygurqkt + +kp +kqyxp + +hzbtkxlyipegra +lkrgehiyapzxtb +zhliaprgbkexty +axgyhlpekbiztr + +mh +al +hien +zxkprdvo + +xfjokhuyszwt +ujotxwsfkzyh +tfhwozsujykx + +bqudfgvjeiy +djefqvibug +yvxuiedqjgbf +xuefjqgdvib +ibveujdqgnf + +liyqzxwogcdhvjsr +nvcigxswpoedq + +zjdgxfqwhcbm +qxhjgdwmbzcvf +cxgfmzjwbdqh +qjzwphxibcmfdg + +tdflsxicwmpar +iawprsxtmcfdl +rxpafwlihsdtcm +amtwplscxrfdi + +sgjmp +sojg +gsj +sjgu + +pjtayfvqgubsdzh +rxwbhcekljnm + +fhsmgpyblcitz +zmibgvhylwf +vigmfbzylh +iyfvglwhmzb + +bprqyialnmkveohuxs +iykvuxbpshemloarqn +ivnoqlxrpyabheukms +xvqnmyhbkueslipora + +ogdijpwtxuchrv +ovjhdwxptiugcr +jxutokrfwpighcvd + +oizhtyglwbnjfuverqps +syaiuqhzeltbovrwjpgn +eohzgwjbtrqulsivnpy + +uptch +igt + +up +uhy +u +oua +hu + +owtkc +oktwc +wkcto +wcokt + +qosvjmkcixhdb +upaweznmgjt + +pcnabt +bapct +dcbaqzuvyl +jcab + +siw +iws +wsi +siw +zskiw + +b +by + +vdljnuawqg +daluqjvwgn + +vqctdhulbpj +citavlqhjkdpe +glhsjpryofnzwvcqdt + +xo +xo +xo +ox + +l +vkjflgh +ld + +oftdbe +jutioleh +ebcrtgo + +dcwx +zgcxtb +dcqt +opfucrjikea + +kjogaebchpmxzudy +yvxmabpdgznjoe + +dtfrbceshaupizxqwl +wlefqdxbarzitscpuh +lrafisdhktxpzcbwuqe +tleibrqsazhufdpcxw + +mwjahec +wcjme +kjrwcme +cemjw + +jfgonrqkezumxdsbvaci +vgsindtuyzjbomrkqf +osfbklvjiumwznhdgp + +nwmgfludzhoyb +jwmgonfzhdkiuab +huvgwsfrbdcenmotzqp +zdhgxofwbijmnu + +wahstyxvugdmolp +tdalphmxsuoygwv +glpudovmtshawxy +hwstlopuyxmagvd +lgayovuwdnxptshjm + +a +a +a +rca + +szlidbpwxq +slbzpqdwx +qzwxhrpybls + +ewhjlxfcmuidsgnbrkyoq +enmiavrkwzlobjsuyq +pisbwokteznlqjuymr + +brnec +nwcrei +bnecor +ncerb +rnkedc + +pqw +kbct +hviudfjyars +wbe +b + +xtsbynudvwjkfalre +auwkntbfeyvxsrdlj +nyewflsxkjuartdbv +adexltvsbymrwnkujf + +yima +miay +amiy +czimay + +yagqmw +mwqgya +gqwyam + +acqibtfwlnyvjumrdgspoxz +dxzbqownsgylajucitmrpfv +ztpcrulxjomvwbdgyfinas +scbwynpftarmgjduxliovz +mpgtuyzhxwcoibdrsanflvj + +bdftwqgsaimhxvn +stmaqbxhgwvfdni +abmfshgnxvqitdw +thabinfgmvdqsxwy +dtwvbasxnhiqfgm + +siomckdrlhnytjaqpzwu +cqxytvoanbulrekzwfpd +uxadwqkgptrzlycon + +stwohnvrq +kfnpxvcy + +ijlkvrdacmuhotxwbsqpegyn +gopemwhirtcbynxaskvulqj +aweqlciybkguopsjtmxrhvn +pwelrvhicybstoqkujgaxmn + +ckpdbfs +kcdfqv +foecjkqsvbh +muzckif + +zsblxdetgovunfiqwhjpkmracy +wvkxysnjdraclzgemouphbt + +qmtx +xqt + +dmieulgon +jfmyra +fsjma +xmsq +tvcm + +xklcpvzje +lpjrvaez +zpjlev +fvpjlez + +bodrkvzcmhyxulswnijt +ynilmcwzrvohtsubkdx + +tewspzja +wjtsplzfega +atzsewjp + +tu +but +atdnsu + +y +u + +qbtawmldjsy +mjqdsylbatw +tyalbmqjswd +ljsdtwbqyma + +msgytaj +vygscje +qjciogk +nhpflxzrduw + +vcmrtws +srwyc +wursckd +cpwrs +wsrc + +ielm +pilfr +mhxlcaf +gvzosdytl + +ij +avi +ylio +kaim +ijamw + +cgxwjydavlhbpior +adckqejbhysinlo +ajwczfloydthbmvi +cubojhwagryild + +jyqagilxfsk +yfasltokjgqx + +impglqcwn +ngcaydziwp +ipbgnzwcu + +lj +j +jfrb + +xncgrjkpsmwailbdeouzqht +rayuhpxqsezkdlowicfnmjgbt +ijzwpaqtdxcuhegsmlkvborn +upndtklhgeoibmzcxrswaqj + +ohsckdiej +dochisejk +dcsiojkeh + +xcbnwtzqu +oeywhzn +jgfskirml + +dsrvqfctojm +facqi +yflgqcw +cqnlfz +qefkcy + +xvwadfktl +fltkxwa +wptxjalf +mtfaxlw +awtflx + +vzxqjbrwlpysguonctmf +orynmphcqbfuzwtaxjs +mrunfcqjxoytszbpw +podxzyserwjbqutnfcm +sxqdfercbnopmyujtwz + +anzbwplo +ingwuxc +dwrketnsv + +goz +go +goa + +msgopxyt +tsopygmx +gmxyustpko +xpmtsoyg +xptgmosy + +ohj +ojf +jo + +gvm +c +nrhjkwda + +ryqudzpvg +vzugpqr + +wya +wa +bajqno +gxa +da + +eobwrtihcqfp +rhbkdep + +spnlubhavkw +obiqgzyxdfercj + +jtfq +q + +jyx +wuz + +bhqnegu +uehqngo +ehvqgu +edquhg +ucgyqdhe + +cigbdtul +agicltduv +cgytuidl +utgcdilm +ulgejtcwfxdi + +efk +fd + +yekuojwtxp +odky +ngz +tpwyd + +vo +og +o +o +ofj + +wavejohibzrk +wijeafkrvzob +ierabjvkzwoq + +bxtkfhcyigulzdp +ihjfyukgltb +nafkrhwibgyulqvm + +wljfgnvr +aowxfliqpr + +swkxmvhcriylgt +cgitkxhlvmrwy + +ilnzkweohypu +axfcdrtsmjqbv + +xolcuzgfvitedbkyr +gkldfetvpuxyorzi +fxituzlqvokersgjhyd +btkzyxiedrlfvgou +koryuemagtixfdlzv + +hsubfgecvrjna +nctvf + +pyeaxfmr +eyxprfam + +zr +uez +zou +zqdxnsakmvifj +hz + +jhbwgfrpvdx +mcnrpehvufgtb +pvzubqhfgar +ofipybhktlqrvgs + +bsfu +hu + +xk +kx +uk +k +k + +qymaugnc +ajigmczroyxb + +dxjisapbrcqnltwv +anzrjtiqxslbce +qnxgjalrtiscmyb + +rkmxv +hmrkvx + +nha +pqjeh +h +ahv +vah + +ipl +svirqdjpmx +pjimx +whpekfzgtbi + +qlshkevani +eshaknilvq + +xpi +pxio +xpjoi +pnxi +piox + +kxub +dkmxu +nka +cku +quxzmk + +exthvjmbrl +ebsamihlxrvt +utfbrexmkljhvn +hbxmelrvtj +mlerbhxtv + +ykzvcm +vfackzmy +zvmkyc + +cdnqv +vcqdn +dcsqn +dcnzq + +odv +jdokvasx +dqvo +dwplnvo +qsodv + +ud +du +du + +sfoihm +oisf +siohf +sifo +qdjkifalso + +eabz +bpza +bz +ezb +bzuyvg + +d +x +d +d +d + +muf +m + +ohtfclrqkabuvynewidxgjp +lchojyerxwianpbtfkdvqu + +h +h +vh +h + +uthpecmangsirovj +itzrvywgmaushc +cumrhqtasvgnfi +mvgtorachqiebsu + +icrlaxzefw +ceibjhywlvzdrsao +xelqaiczmufwr +ialnczmewr + +v +frwckiy + +qne +zsgn + +ysaxl +xqwlasey +xsyalb + +ntevywd +hxungtl + +snzgpbyhtlamxroec +wczfumyrjhidgsqbkavot + +sapbxcfrthquln +kqafnsuhob + +eaxhmlnuwco +qigzs +gkfjy +jrvdg + +bztomjpxycqnkse +qcotlpesajmfk +oetdksqpcmj + +pwtjdilcyx +liejpwtcdyx +ticlpwyjxd +iwldjcpytx + +aoznvbfrxy +zbfvyxroan +fybavroznx +fbavnyzrox +xobyfvrnza + +ioxynh +xinyho + +io +uyiwon +oxi +ivo +cio + +y +ny + +l +lc +gl +cl +l + +akxs +asxk +akxs + +vglhiwm +hkv +rducpj + +iszjbtaouvcdkgfylxhqnrm +cagdmhlziutfxqrkjynovsb +kmcdrvgxynzoafusjlebqtih + +kqduelpmh +uplhedkmq +dupqelkh +eflyuhwqgdkp +hqplekdu + +gwkfxo +fowxgk +foxkwg +xkfwog +fwkgxo + +xpegdzcsoyjt +zpcsgetjydxo +stoxjgfzecvdpy +typecgxjzosd + +digfewr +psxv + +pntydfukzoecihxv +vtfzihungkcdxoey + +ktaqydchpr +kcalptydhx +ydkprcaht + +qep +pqew +qvpe +qepx + +l +o +o +n + +zubsojhtqep +bujqpsytoieh +upeqthsobyj + +regblhcjn +djgecrtblnh +jhebcnlrg +brehclngj + +lprbihju +jhzoplsnk + +hgnlwjfqczu +cjyuntigwzqeh +qhwlgunfzcajv + +adjmogquh +wpsodnth + +brueif +teiuqrfb +ufrbei +fbieru + +zeaufk +ukfeza + +qk +cqkf +kq +kq +qk + +dfw +ndwft +wfd + +sdevru +fdsr +nbtmord + +vlhxnguq +qvlgun + +nkcoszpaivjqybwt +qjdzgrumbsiopkveaylcx +szypwickvjfoqbha + +xbtzcjeimsnwf +vtkicgmnhbx +xnhabvqicmtdpr + +uxt +utx +utx + +yurfmzncxwbil +vyi +yovi +iya +ksyi + +vbkmdhjzf +vbhkjzmf +mfolkbhjzv + +bcl +blc +clb + +groy +n +mq +wiebc + +bpn +pnb +pbn +bpnw +nbzp + +blgdwivs +gvilsmwbd +bwgdklisnv +busdviwlg +mwlibsgvudc + +stafhuqw +aufhqs +hsqauf +xrkfmepbsnqac + +ajlhmnzqfbiskyxvuoc +svfalqujboincmxzkhy +sxvlznqfajhyboimukc +vljuykzxnsiabqchfmo +fbszjynvolhamucikqx + +tjhcwv +wc + +jobkfqrchsxeilu +jmfiaowhpkulqrx + +janucsmrw +lnjco +qgctnjz +vgjnfc +dcionzxj + +ouhskqaiydtjz +oisamqzehwlyutx +uqytfipahsvzco +uapehtyqziso +yqatsuizefhmow + +klsdvrhmfiqyptuebxwc +usdxgerciwlvnmpyfob +vbwxyedsrmlpiacfu + +mzcf +mwc +chm + +zuipejovcklydarwxqsft +cdevzkwmrjfpoqxtuylsia +frwldqezastuocvixpjyk +xkluzcosjtfvdeapwriqy + +yk +yk +ky +kgy +ykv + +vtrikmwcoju +qtphlzbjwovrg + +pujnbx +nbupjx +ubxpjn + +nikcbsdhge +hibkgcnle +nboehtpigck +likhecnbg + +cuhjlgofs +khsocg +sbfoghzv +ydsngtwop + +swfudijxtklq +xqvnajufkihwtdsl +ixjkwdsqtful + +mvajfubtpgxwocs +pvsbofxmjwaguc +asbgcfmowxujpv +oseuibcgxfvmawjp +pmbcageuojfxswv + +dvwqskngflbpx +ibtgczowdfljmhuaye +svlgnwfrpqbd + +ftxykloisajqwzun +qytozbimwxuafeknj +lazjyixqmotnuwk +voxhyjzknuticqwa + +tfszajmeokvupiy +tmqcvyjsuf +vtyufsmgnj + +kwzrisqu +zuskiqr + +v +h +h +h +w + +g +g +g +g +mg + +wmoigknfuqlerxcpd +xmcrguoeqfnpkwild +egmlufncqdvxropiwk +wagquoxrcfptekdinml +lxgfmeirdquowkcpn From 79ad4a26b51eaee381a096ca4e0e680f36d1ecc5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 6 Dec 2020 07:22:41 +0100 Subject: [PATCH 049/129] 2020: d06: ex1: add solution --- 2020/d06/ex1/ex1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 2020/d06/ex1/ex1.py diff --git a/2020/d06/ex1/ex1.py b/2020/d06/ex1/ex1.py new file mode 100755 index 0000000..ff38b71 --- /dev/null +++ b/2020/d06/ex1/ex1.py @@ -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() From 1c64a8f18bfdf728aa64d74b6fbe6e72eebc05d1 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 6 Dec 2020 07:23:22 +0100 Subject: [PATCH 050/129] 2020: d06: ex2: add input --- 2020/d06/ex2/input | 2246 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2246 insertions(+) create mode 100644 2020/d06/ex2/input diff --git a/2020/d06/ex2/input b/2020/d06/ex2/input new file mode 100644 index 0000000..7315fba --- /dev/null +++ b/2020/d06/ex2/input @@ -0,0 +1,2246 @@ +lfnghcsvpyrdjtxozimb +mdtbnorpfalcijxvhsy +elmwjkfbihydxcpqtovsrun +tlhmsdjingyxcbfrvpo + +a +a +xqh + +mxdeqcinvfg +vbncrgzxqefka + +oejsdfwm +fojsmewd +ewxfsouimdj +eodafjwsm +edjwsmfo + +d +d +j + +mgxywknlt +khgwmr +wkpezgboavm +mjgkwni +mwkcg + +mqzjtgskhadecwy +nhkjeqgdtfsa + +rc +cru +hcr + +vuaeqdcnty +nltovzycbeidu + +phcqe +chep +hpce + +smjuow +jwktu +ujw + +ljphnwtmugi +giltnpuwm +mgtulpkiwn +uxltinpgwm +jmglintwpu + +slbguajo +lqwardbuo +zlqmdobau +ucalqob +lobua + +uwtcp +umtlwc + +lrcpgjwqfaybxtisoznuhe +wjpnrsxiultyabgzhcqfe + +clmfrxgbqikzpsoduvjy +uoxibjmkygrsdqczplfnv + +oncmzsf +onzmds +snzmo + +zlmegxcnavjb +bmloajdecvwzxgn +pjgzecxvsmbhnla +fngpcvhaexzlbjm + +ulhkjzxadgvc +uejbgctld + +xuindfqzvpg +ugdofws + +qrpvexjlywfmgbintuzk +wrtnibqvuflkeypxg +kretgquypbinwxfvl + +tmrdpzxvily +itorywvlxjcd +rltdvygbxic +xyliotvrdc +xrvtdilygc + +uihswfvanoyzl +owgnzcshuvaqlfiy +whrtnuoyimzlsvqfac +jiekwxbznhfvuplo + +jgbtesurivfxclapnqdmkzhyw +dcnjhsqgkzyitwfplvearubxm + +umovhtgaekjixwfcdnq +fcoamwkvjeqxhdbgitn +datcxweqzhirmjfnkogv +vwahorqcxfilmkgtndej +myhkadptsgcxfojinqewv + +oys +syo +oys +yso +oys + +fatvyeruxnilcmpd +ydacelgfmrxtvin +tgdirmynaxclqwe +jstnbxmdlcezhraiy + +fkbnpgyhs +ktnhbya +ybhan +wqconhbey + +zicrfu +dblyczk +eshjmczvn +cdzgofpx +rawzc + +hcuypzdfalvt +dfplcsyvazrqh +lfcdvzrhyabtqup +lycegwaofdkmzpnihv +ayvzdhscplf + +rvowpcnbjlfhe +hsgbdivpcjlxo + +wbiplofhkmgvr +wvmrohkbfeglpi +bvklotpghrfiwm +wltkighfbrmvpo +bgvkflitwhmpor + +dwmorjebnchvuaz +hyikgfenl +nykhxegq + +pnsactlj +knytclorg + +w +wj +w + +gushnlqjctfvwiyz +shtqjuvzcgniy +cgdusyjpntzivqh +ivuzjgcnqhwtsy +vcusgtqinyzhj + +fjnacgiw +ngijcfw +gcwnifjo +wvhsncikgtfj + +tecvxgzsjridpa +azvtdgprjesixc +mxspejvzrdcaigkt +vristcjaexpzdg +jvipeagxdtczsr + +v +f +w +w + +wrsxdmlay +yxalwfs +xlatysmwe +bgqyohvpzswnlxujcak +silxayw + +zxelswo +slwzpxo + +aizvyoqg +ealnxdyczgpsrj +hkmwbutf + +cohalxbk +suiydp + +qebdumfwsjagk +cxaokgmr + +r +x +a + +xhey +exhy +hxey + +zchi +izhc + +dh +dsh +hd + +lfjcmoauvzxqitdspbw +febzhrmowptvsqiyaudjkgc +ijausfvcdznmpqowtb +vcsfzqbjoipuwadmt + +up +rkpy +nzjdbg +twkl + +tuepkzc +opzst + +rgszfijlxneuvqcmktpa +azcjfnkuvlpegmrsq +fgjzkvusqnmlcarep +kvrcpumgsfqalezjn + +tvqiwkmdf +qfdtvowsk +tvkifsrqdw +vgdxeubfkjhqzlpwt +dvkytawfqm + +yhiogvbkxlzjwsafd +fylwkxhotbasivdjzg +cdjfgnkshmwyxvaliozb +xusvawyhzklgjoifbd +vkisfrjowaxhglydubtz + +kqws +xqysrkw +lcjsqkmw +qwsk +koqsw + +wc +cjw +wc +cw +wc + +awrshieplc +ixelpycsrvw +qebsmzklpwiuocg + +cxf +xf +najxvf +xfh + +umgylpoz +fxwcyet + +yt +t + +gbeskji +ejbsqki + +grmdbezfou +ufzbredgom + +wmtvcfhk +cyleh +prseclyhz + +cyrwzamnoxhue +hxacmyenru +ndyrashxgmecu +eilychmuraxnfbtv + +fbgwal +ablhjg +agxlb + +cvw +vcoz +nvmrc + +prvbngaqh +qbhgpvarn +palgyevfrqnhb +vgqnbarhp +rbhavqpgn + +fztoevmhwgnb +nbhfweomvg +zfmghoevwbn +vhmsfgwcbeonq +negfvwobhm + +qbx +dev +hyzl +wr + +ltnibrq +qrbnil +rlbinq +qinrbl +irnqbl + +thfng +gfhkbd +hmucga +rhdg + +fqwalrhvpyxieu +plehrstgivfx +xbcvtrpefldih +efpxrlhvdi + +kculvzfnesawmty +vkztnuycwfamlse +ecvnzlumykwatsf +zatkulemcyfsvnw +tafczlusnywekmv + +a +a +a +a + +cktun +lnrdyfk + +rexndcwvkibpflzjqymu +exivdprnjzyblfmkwc +czbknjlrfdivxypmwe +fjvgyixpedkmrwzncbl +hricxbjypenlzfdwvkom + +vqebrauop +ebopavuc +upabhveo +vobeaup + +iaxlnehuycwkrmzqsbp +bynlcreqpswzmxikhau + +nb +ikqoh +ho +qjh + +oaixhtmeqc +envpiuhkqdmjx +xhforyeqwim +hcaezwimxq + +ctubrpd +dstub + +vchgnkea +hkegyxivc +fpychegtvk + +apxkiotyjzsqufvbld +daviftqlxopsbyjku +zblyqpajvkdsixuotf +lafqdsyjuckbtoixvp + +pmlwfdcbik +xzjebqshotrnygu + +cepzjtkamvnfuloqrig +vkoiepjfnztuglqmarc +pnjrlqgmkzotiuevfca +tluscvmjrzkgaeipnfqo + +k +k +r + +ae +ea +ae +ea +ae + +ypvtzi +mtu +tjs +fjust +ufmtj + +zilgoaqmr +aqopzmuvxlwrjg +ozrmnadbqgl + +rbfm +r +rep +vfmr + +ajrsgqiodfmwuezkltv +tqsfiwvgzmeurdkajlo +sqgywzoakturjlimfdev + +wplbfyivhasrujdgzqcmxnk +tklsezcwrihvj + +vshfrae +bhnocstidq +xlhsfmza +swlxah +mpksvhy + +uelktdbswyjpaxqmnr +ruvwjsnyadhmzepb + +jepzvwaqublirdftgcmx +lwncbxgqkvdjpztiuamf +vxmfwtlaibpjgzucdq +pfidxgumvtacwblqzj +dsgivqfnptwzmbaxucjl + +gotqzew +jdfn +dub +v + +nzj +jg +g +vp +n + +clbgtr +tgrlbc +rtbclg +rtbylgac + +uyit +iuqtpc +ituj +tui + +jlsipo +hpijl +solxjip +izplej +xlpitsj + +zd +grntma +w +iz + +lkxgcpywohifnu +hyglocfnkpqwux + +fjz +hj + +fxpjdrglkntmzce +qznmtgfpljcrhd + +w +hauesfy + +goixwvdy +dxivyow +dowvyix +idxowvy +dvowxyi + +bw +y +swg +uyw +aijx + +xhkdzbts +pedonw +gqld + +neslgchypjqavwr +aclkpygqtnwiosh + +vboyhcijednm +neyvjcd +yvdjnec +ednvjcy + +pezkudgxf +zpfxgkbedu +exkzgfdpu + +oulheigbsfjn +ltnagbieju + +vmyhslndzaroiqpgxutfk +dpilskvjutayrghzon +dctniozulkhpsvgrya +srhtzkyupavdngoli + +aeybn +slcoixqtkgh +bw +rvfzp +uynjmpd + +zexkwslndgyi +encftykmx +rhbenmkoyjx +xymnrke +kyxjbnumer + +egdq +efkxg +lmnscieutozapj +wye + +nk +ny +wn +nk + +wnmubxsrvqzcyhtpjf +sjymafxtzhcnriubwv + +msub +ubvyhkm +ulmocbq +blfcuepqm + +gtsfubrozwdiapm +oqkuvhncxbzip + +vfbklexjnhziwsayqtrpm +ntrzifljyqvesamhpk +hnvmkyprultqsifazoejc +ejcvmtnipfalyrhkzqs +qtiavmhrlneydpjgkszf + +yxst +hgtwy + +ymf +yv +zpdyb + +amdhqbzjkxilowtuvgnrfpsy +fugmwydqvsihkntlxjeazbo +rsvxyzqjoadibglfthunmkw + +qzbsk +bqzsk +zsbqhk +zkbsdq +qdbkzs + +dwlij +jldiwn +jiwnl +ljwrbi +jiwl + +nmbhlqkaovrgiudte +dbnotamqvikeglhzrx +ohgnmkrztblaidvqef +tbqvahorjgniewldmk +qrtvyobigemkdlhan + +par +rpx + +rq +r +r +r +r + +nuxaoymrctdsikpeghzqwjb +lrnpzwbyiksdcjeumxga +efzlgxyvdubrsmjwpnakci + +ftm +t + +zjydrsx +syrxjdz +sjrxyzd + +rxczvljiahfwmbok +olznqgdawfjtchibvmrx + +ydlwknjzhugeamq +jzvylqmgdewhaukn +zyluqhnewjdamgk +lnuygmwdaehkqzj +jindyaeqzulwghmk + +ujcbsanxhmltdvzeg +uznjaedcmlgstbhxv + +ejxp +dypjn +lan +bwgvkrm + +v +s +s +s +s + +rdswzekavfj +jubothxgani + +jazgdw +gazjdw +gajzdw +wdjzga + +mnecwfslyp +yfntmsl +mcnfghls +xlinzojsvm + +ocgxrsmheynbvuiw +handgupyeslixmwcbvr + +yfzhmrpdkustegwoalbq +lyftdmopzrewsgbu +rwuglfsbkdtcnpqozme +etzuwbsoyprfdglm +dmwtljgrszpfeobiux + +ealrftgbzy +blgearjyz +yngdbxclrzmea +jayfrezbglh +leargyszbf + +clkedspwxzqhfojb +nsxhezwcjpkdfoqb +czowphbeskfjqxdl + +pkzoadrt +dozrtapk +dtorzpka +atdpzrko + +vrjyxhnqfg +yjhrnvqag + +owgadqkfusicxrztl +qicupjdzgkolftw + +o +q + +csbaloz +cozblas +soczalb +lczabso +mtozcbsla + +faljzbneuxympogctdi +cailgjmzqexdptbvfynu +wjpknbfhelcimtxrdyzg +gmyebdfipnxljczvt + +j +j +j +j + +getbmjnwazok +czenqpftw +nlxzweqtf +drwuzetnyl + +ywmi +sgqdt +lnhzfxpbruovja +cqe +gyk + +vp +dxesf +krp +ar +gz + +xeo +q + +myfw +qnelw +jrodw + +ndajkhfmzxslvopb +ajsckbhdpqfnlgzmvx + +imldxsptvaqyhcgbjn +ghnyicdvpqtljasxbm +lqjesvdhtbaxpmcginy +andpytcblvsixmghjq +tdvyxcnimahlsjqgbp + +vsopuwdxhtabgej +gjahsudbxtwpeov +vsawxbgedzotphju +detawvgbouxhpsj + +xriwbfaocqgztydvnelkspj +xkjfpcaqibswtdelyrgzovn +zpdexnfwalqhyjsokgbvcirt +zevfqwxcrjplgoskyitadnb +jcsvkgtwezobdnxyfqprial + +uvigr +i +i +i + +zyatdpgjrle +ezsyrdhxptav +kapdyuzreotm +qeryptdagz + +z +z +z +z +z + +sizxwqmegyflndk +fnweyjdbckugxtmpv + +vjtkzol +hwjtzmqdykosv +jtzokev +xztkvojc + +o +utxgqfenh +d +yvkj +kswvm + +uefcqyzgalm +qafcezlmguy +cumafzlgeqy + +lmfzyt +mltf +tlgfm + +ne +eu +e +zen +e + +tepckxywbnuqahilvr +cwqpuveanixogmbtlyk + +mgyu +usyz +nyu +uy + +hvnilwjcgbekmt +mljgckftviwhneq + +rdaspohl +lfxjad +amdl +dla + +ncjmux +hxzemjuoqnc + +slhdpwkc +plhkwsc +wslphnkc + +kx +kx + +klbmqja +cbpikxjoaswyhg +lakbmuj +kbja + +do +dl +qd +d + +uwbktzrfax +xfvtkl + +pvylfnsder +dnfprelvys +srlpdefnoyv +fvnesrpldy +rdfyneplsv + +cietjkmyu +gkqjcrubel +gvjouc +ajuco +nsfjpdcwuh + +zeacqhdkltxi +mtldxqcha +adqcxlhwt +whatcdxql + +gsrhkdwnyt +wvngykhtd +otvwdnhgk +dkmtnhwg + +gdq +asgqd +gkuqd +cgdaq + +amoriyvlens +nfrdvltkyes + +bgemhciuqtnpw +jqwtgbpcnhmui +zyogtixnwmhcqbp +gqtwinhbcmepu + +jn +nj + +gkqz +gvjyzmk +kagwzf + +qimgwjex +qcxjemi +xjmqige +jqxgmei +emjxqi + +bftzjip +fkjvzbcy +kzjthybdm +nogjbrezl + +lukfvrc +lkrfucv +drbfuklvc +uflckrv + +tekijdqozns +djsiekoqtn +noektqjdis +hndojsiqekt +usndjteqiokg + +cw +c +cs +wc +cn + +lxfgopvmh +ckpatzifnwxsjum +bfemqdyrpx + +xosicnwrb +wsocbr +brwcasoy + +esiz +ise +ies + +dcungxvhipzorlbwsjqkt +pvgzlihbocskdnuwqxjr +jwqvrboixdchpsklzugn + +jsizhem +zjsbhi +tjhzu + +tgldmihkjb +hbekplin +borvflqchzauxi + +eosqa +zpqgusowa +okqslrae +qofskay +olaqst + +dbulmwerfxjoiha +jdiwhoumflbxra +rxbdihmofuwalj + +gqzwfumsipboyjnl +forhywgnulpsbmiz + +ql +qml +owq + +dpbxiqjy +bxyqjpdi +yisjxpqdb + +hxcrzpjvmnkgeuo +hryatdbx +rxlhytfwds + +ljdozibqytwnfhvkxp +fqxiwhcyzbptkjlvnod +iptkxndvjzlyqwmhofb +efgvoxydhpjqiztwlbkrnus +vfzqpjblnidytkxaowh + +onewvclt +vhcteos +vecnto + +fpoisndugqmb +fqkgntpwjbmdus +elfqmcnbudgshzp +gnqpdmbfsvu +snrqdupbvgfmj + +euvtmyohfqkscjdn +fydvukotsmpnjhqec +fhqumnvydstkoejc + +zcoupardbfvns +siufbpodcnlva + +dwkfe +nfdz +ibjodf +xdyhvltgpu +dzjnmrcasq + +k +k +k +bk +ckj + +tavfsckigh +hquzcnbdorlwm +ycgh + +qplvetmdc +qdmvetcpl +pqmdcvtel +lpetvmdqc + +lhcq +qcuk + +whmnsqpkjov +wtjgu +tlcjdw + +egicls +cioegs +cesgi + +lxaifjhyrqgsem +mafexiryqdsjghl +xemjlkgfqyraish + +zwrdcmavo +zvrcadfmo +madfozrcv + +slfagzbjwotdni +mdspebtajxfiwknzlc +dqsitfarvljnbzhw +auilefztdjonwbs +tsiebdwjlnfaz + +svgnwpr +nsaiguwl +xmplcdgsn +eotjkyshbqnzgf + +bl +ly +iafxle + +wnckbplriv +ixdbelhpgmqfscvwzj +lpwivbc +byptliwvuac +vbicwoklpyu + +eskwamyvgxzqbtprculijf +eipbrxystfkgucjazwqmvl +wvplyjkrbcguzqsfteimxa +vhtrlousjbpmfzanqkwgcxyei + +p +m + +ntfspeyqrj +pqyernsftj +tnrspejfqy + +gx +x +x +x + +gizducfvmtohe +genmuitdvzkhxf +tbpyaruimeshzgwldqv +kidmjnuovehzgt +mxthzudigve + +kudjgcbhna +lcajungkd +chdankjug +cekjgpanud + +zqlucvfkmnpoighxb +ohcpgetlvzufinkqmbx +cunpqvgkziflbxhom +cgklbnvfxouqmpzih +kjimlchzgxpqvyuofbn + +uwmz +nz +zbofx +zw + +r +or +av +j +j + +tvbqc +qedctbv +tqzvbc + +t +t +ts +t +t + +qhkbwa +awubqtzx +fqbyja +mbaiqhrt + +wzcuyqanpdtsghr +zpocrshdwynaqtxvge + +gpq +qeh +cq + +jfltaouwri +ygbxsqdz +skd + +jmlh +hlmj +hjlm +jmlh +umihknslj + +ute +ltdzqf + +ygkx +mywxcrd +apyx + +xy +y +dy + +mivusqxpzyljehgkotrf +ajlizqnpegckfohdvsxrwb + +pl +lp +pl +lp + +xmnaupwtcvozrfekbdshlq +dlafzmnhvpeskwoqucb +uzydhfovwmapneqlgkbcs +cjapswblfmnzqokeuvhid +dzlaovqnmsuwkhcyfpeb + +wpb +bp +bp +bp +bp + +pusm +umpshr +musp + +xdz +z +f +ecjo +nkxz + +tjmvdf +st +trn + +hkfgarys +rghfasy + +ljyixtumsfngvdwoqzpakecrbh +kfpuvicgrsnoetabmywjzqxlhd + +az +z + +rgkf +khrgn +nrgk +gkrfoc +werzgkpa + +vkg +k +k +ku +ik + +blruxyvehtsn +thdl +mtldh +lht +thil + +rnzqadiplhbegj +qlezpgnabdrji +lnrzaqjpdigeb +rbjlnpiegqazd +jprzlegqdbnia + +kgo +okg + +rjm +kiml +cuxstqpwod +kghb + +yckovthbrigazfxq +atriygxofzkcqh + +vudbtxjpgaqfzhlkmncswyi +lgfjahksybqmncoeuwvixtrd + +dmlyrgkwfjovqasxit +ylawsjxrftdegmkqvi +stqgmxfrjvlkhaydwie +mypcdrjnkgtsxvqawlfzi + +ethrvfnyasdkb +eanwdyfcsbhr +xayerdsbhlf +ejdrshvywbaf + +hqyfnrxjzsd +buly +yukpm +likmy + +zlpditkvsawocunjqyhmrx +rdtjsunpqymlhxkvcwzoai +oaprkqhumtvlcwxdnzsyij +uxmdclkpjqrotahysizvnw +olwhpitmraqdnkxuvjsycz + +srnhuf +hrsxfwynuo +gnzsfbutcrh +krnhusf + +l +lsb +ujqtvol + +cptnhxgdkivyjlsbrwmuf +nkbshfmrxgjdoclwivy +fxibalcmhydvkjnwgsr + +txye +cjvqsulagn +kihdbf +ohpmzwr +rbtw + +tgm +mgt + +nhucrjmq + +rubajlyszwn +nlbsjzwryau +zrwuynsjbla + +flvdypkxabzm +lipzbtrmqof +ljmghurbifpzns + +bsv +wsux +vs +s +sv + +vfqsehx +xseqvhf +svxefqh + +fipwjdl +jpilwfd +whflvdipjx + +oclrqnubyhpmdks +wmkchdsqujbpxlnyo +onulmdsbyhkqp +mlubkpyhnqods +tfmesqblonudihypk + +gcwf +a +v +q +o + +xpqlzcfvtjgr +fxwprjglmasiqev +xljpgbrfqvo +fbvqrcgxpdljt + +nxpktofqglvrsjbi +wvkotsgijlbnrufdxq + +rpfew +iflep + +tdy +teyvdjo +tdy + +ix +gzkwchaqd +oysure + +hxvkjmneycuspbwroqaligf +qkhpisjmxblnwezrgoauycfvt +emcqhiufkjbrlwyngapsovx +aixrbgcfynwelsoqkpmhjuv + +ckxhmridjbfalqo +yzunwpsdlgev + +ls +lzk +sl + +kdpzmau +gzamukp +kpfua +pkau + +usmywivnpgt +biqxymnosaklrehzj + +orwcjpkbiexz +bpzikgwn +winpbkz + +wobslxnhfyjtg +vqdecolzarnm + +rgfloc +yufcor + +tgwnebxyzkchqvoulmprdijasf +zmpdjlekigtswronhubqcvfa + +fyrbd +yfbr +frby +fbkghytr + +stexkgyiqpaodnm +opecuqrdnytkxaig +oxykdtnaegpiq +xtgaydoepqikn +oyktnixegqpbad + +irgbyxhwm +iwgykrbx +yibgrwx + +dxejzvrocb +tbxhmqscrid +cjrodlgbxz +zcbxwpjrd + +l +lg +g +lg +nfi + +ab +aw + +vlbi +zegtwnc + +dgbj +dgjybl +ardgupbsqjv + +xoquygizahnwpkvds +duaoyzvgqxhkiwspn +gpvyukzaiqdnwoxsh +qpwnyzihovukasxgd + +fcepzibvulyxhsjqdanwmtrg +bijrdfxcqhplwnymsezatuv +uxbcwnrmisvqhljpzdaetfy +umwzscitfjhxyrelpvdabnq +usahyzdmtqfibxcjvlepwnr + +tpk +gzetqkypuhj +pknct +mfticpk +akiwtfsp + +qedhju +lvdqtzehyj + +vyfe +vey +yve +yve +yev + +dseopbmfcuk +msfekpuodcb + +jm +jm +mj +jm + +jfgevdqxm +mqftev +fmeqv +etfmqv + +grhalzpfsjweuyt +zteylfsaugpj +jtuzpeyflgsa +zlajntyufgkspe +fjyapletgzsu + +ixhz +n + +mqekbhiu +ikgbhmeq + +xscglkt +ctglkxr +kxlctg + +siygouxkzhetdrqcfp +eiftxuyhpkczrqdsgo +qgfryxepotiucskhdz +pfruziqyxgedkthcso +pezofhisdcxygurqkt + +kp +kqyxp + +hzbtkxlyipegra +lkrgehiyapzxtb +zhliaprgbkexty +axgyhlpekbiztr + +mh +al +hien +zxkprdvo + +xfjokhuyszwt +ujotxwsfkzyh +tfhwozsujykx + +bqudfgvjeiy +djefqvibug +yvxuiedqjgbf +xuefjqgdvib +ibveujdqgnf + +liyqzxwogcdhvjsr +nvcigxswpoedq + +zjdgxfqwhcbm +qxhjgdwmbzcvf +cxgfmzjwbdqh +qjzwphxibcmfdg + +tdflsxicwmpar +iawprsxtmcfdl +rxpafwlihsdtcm +amtwplscxrfdi + +sgjmp +sojg +gsj +sjgu + +pjtayfvqgubsdzh +rxwbhcekljnm + +fhsmgpyblcitz +zmibgvhylwf +vigmfbzylh +iyfvglwhmzb + +bprqyialnmkveohuxs +iykvuxbpshemloarqn +ivnoqlxrpyabheukms +xvqnmyhbkueslipora + +ogdijpwtxuchrv +ovjhdwxptiugcr +jxutokrfwpighcvd + +oizhtyglwbnjfuverqps +syaiuqhzeltbovrwjpgn +eohzgwjbtrqulsivnpy + +uptch +igt + +up +uhy +u +oua +hu + +owtkc +oktwc +wkcto +wcokt + +qosvjmkcixhdb +upaweznmgjt + +pcnabt +bapct +dcbaqzuvyl +jcab + +siw +iws +wsi +siw +zskiw + +b +by + +vdljnuawqg +daluqjvwgn + +vqctdhulbpj +citavlqhjkdpe +glhsjpryofnzwvcqdt + +xo +xo +xo +ox + +l +vkjflgh +ld + +oftdbe +jutioleh +ebcrtgo + +dcwx +zgcxtb +dcqt +opfucrjikea + +kjogaebchpmxzudy +yvxmabpdgznjoe + +dtfrbceshaupizxqwl +wlefqdxbarzitscpuh +lrafisdhktxpzcbwuqe +tleibrqsazhufdpcxw + +mwjahec +wcjme +kjrwcme +cemjw + +jfgonrqkezumxdsbvaci +vgsindtuyzjbomrkqf +osfbklvjiumwznhdgp + +nwmgfludzhoyb +jwmgonfzhdkiuab +huvgwsfrbdcenmotzqp +zdhgxofwbijmnu + +wahstyxvugdmolp +tdalphmxsuoygwv +glpudovmtshawxy +hwstlopuyxmagvd +lgayovuwdnxptshjm + +a +a +a +rca + +szlidbpwxq +slbzpqdwx +qzwxhrpybls + +ewhjlxfcmuidsgnbrkyoq +enmiavrkwzlobjsuyq +pisbwokteznlqjuymr + +brnec +nwcrei +bnecor +ncerb +rnkedc + +pqw +kbct +hviudfjyars +wbe +b + +xtsbynudvwjkfalre +auwkntbfeyvxsrdlj +nyewflsxkjuartdbv +adexltvsbymrwnkujf + +yima +miay +amiy +czimay + +yagqmw +mwqgya +gqwyam + +acqibtfwlnyvjumrdgspoxz +dxzbqownsgylajucitmrpfv +ztpcrulxjomvwbdgyfinas +scbwynpftarmgjduxliovz +mpgtuyzhxwcoibdrsanflvj + +bdftwqgsaimhxvn +stmaqbxhgwvfdni +abmfshgnxvqitdw +thabinfgmvdqsxwy +dtwvbasxnhiqfgm + +siomckdrlhnytjaqpzwu +cqxytvoanbulrekzwfpd +uxadwqkgptrzlycon + +stwohnvrq +kfnpxvcy + +ijlkvrdacmuhotxwbsqpegyn +gopemwhirtcbynxaskvulqj +aweqlciybkguopsjtmxrhvn +pwelrvhicybstoqkujgaxmn + +ckpdbfs +kcdfqv +foecjkqsvbh +muzckif + +zsblxdetgovunfiqwhjpkmracy +wvkxysnjdraclzgemouphbt + +qmtx +xqt + +dmieulgon +jfmyra +fsjma +xmsq +tvcm + +xklcpvzje +lpjrvaez +zpjlev +fvpjlez + +bodrkvzcmhyxulswnijt +ynilmcwzrvohtsubkdx + +tewspzja +wjtsplzfega +atzsewjp + +tu +but +atdnsu + +y +u + +qbtawmldjsy +mjqdsylbatw +tyalbmqjswd +ljsdtwbqyma + +msgytaj +vygscje +qjciogk +nhpflxzrduw + +vcmrtws +srwyc +wursckd +cpwrs +wsrc + +ielm +pilfr +mhxlcaf +gvzosdytl + +ij +avi +ylio +kaim +ijamw + +cgxwjydavlhbpior +adckqejbhysinlo +ajwczfloydthbmvi +cubojhwagryild + +jyqagilxfsk +yfasltokjgqx + +impglqcwn +ngcaydziwp +ipbgnzwcu + +lj +j +jfrb + +xncgrjkpsmwailbdeouzqht +rayuhpxqsezkdlowicfnmjgbt +ijzwpaqtdxcuhegsmlkvborn +upndtklhgeoibmzcxrswaqj + +ohsckdiej +dochisejk +dcsiojkeh + +xcbnwtzqu +oeywhzn +jgfskirml + +dsrvqfctojm +facqi +yflgqcw +cqnlfz +qefkcy + +xvwadfktl +fltkxwa +wptxjalf +mtfaxlw +awtflx + +vzxqjbrwlpysguonctmf +orynmphcqbfuzwtaxjs +mrunfcqjxoytszbpw +podxzyserwjbqutnfcm +sxqdfercbnopmyujtwz + +anzbwplo +ingwuxc +dwrketnsv + +goz +go +goa + +msgopxyt +tsopygmx +gmxyustpko +xpmtsoyg +xptgmosy + +ohj +ojf +jo + +gvm +c +nrhjkwda + +ryqudzpvg +vzugpqr + +wya +wa +bajqno +gxa +da + +eobwrtihcqfp +rhbkdep + +spnlubhavkw +obiqgzyxdfercj + +jtfq +q + +jyx +wuz + +bhqnegu +uehqngo +ehvqgu +edquhg +ucgyqdhe + +cigbdtul +agicltduv +cgytuidl +utgcdilm +ulgejtcwfxdi + +efk +fd + +yekuojwtxp +odky +ngz +tpwyd + +vo +og +o +o +ofj + +wavejohibzrk +wijeafkrvzob +ierabjvkzwoq + +bxtkfhcyigulzdp +ihjfyukgltb +nafkrhwibgyulqvm + +wljfgnvr +aowxfliqpr + +swkxmvhcriylgt +cgitkxhlvmrwy + +ilnzkweohypu +axfcdrtsmjqbv + +xolcuzgfvitedbkyr +gkldfetvpuxyorzi +fxituzlqvokersgjhyd +btkzyxiedrlfvgou +koryuemagtixfdlzv + +hsubfgecvrjna +nctvf + +pyeaxfmr +eyxprfam + +zr +uez +zou +zqdxnsakmvifj +hz + +jhbwgfrpvdx +mcnrpehvufgtb +pvzubqhfgar +ofipybhktlqrvgs + +bsfu +hu + +xk +kx +uk +k +k + +qymaugnc +ajigmczroyxb + +dxjisapbrcqnltwv +anzrjtiqxslbce +qnxgjalrtiscmyb + +rkmxv +hmrkvx + +nha +pqjeh +h +ahv +vah + +ipl +svirqdjpmx +pjimx +whpekfzgtbi + +qlshkevani +eshaknilvq + +xpi +pxio +xpjoi +pnxi +piox + +kxub +dkmxu +nka +cku +quxzmk + +exthvjmbrl +ebsamihlxrvt +utfbrexmkljhvn +hbxmelrvtj +mlerbhxtv + +ykzvcm +vfackzmy +zvmkyc + +cdnqv +vcqdn +dcsqn +dcnzq + +odv +jdokvasx +dqvo +dwplnvo +qsodv + +ud +du +du + +sfoihm +oisf +siohf +sifo +qdjkifalso + +eabz +bpza +bz +ezb +bzuyvg + +d +x +d +d +d + +muf +m + +ohtfclrqkabuvynewidxgjp +lchojyerxwianpbtfkdvqu + +h +h +vh +h + +uthpecmangsirovj +itzrvywgmaushc +cumrhqtasvgnfi +mvgtorachqiebsu + +icrlaxzefw +ceibjhywlvzdrsao +xelqaiczmufwr +ialnczmewr + +v +frwckiy + +qne +zsgn + +ysaxl +xqwlasey +xsyalb + +ntevywd +hxungtl + +snzgpbyhtlamxroec +wczfumyrjhidgsqbkavot + +sapbxcfrthquln +kqafnsuhob + +eaxhmlnuwco +qigzs +gkfjy +jrvdg + +bztomjpxycqnkse +qcotlpesajmfk +oetdksqpcmj + +pwtjdilcyx +liejpwtcdyx +ticlpwyjxd +iwldjcpytx + +aoznvbfrxy +zbfvyxroan +fybavroznx +fbavnyzrox +xobyfvrnza + +ioxynh +xinyho + +io +uyiwon +oxi +ivo +cio + +y +ny + +l +lc +gl +cl +l + +akxs +asxk +akxs + +vglhiwm +hkv +rducpj + +iszjbtaouvcdkgfylxhqnrm +cagdmhlziutfxqrkjynovsb +kmcdrvgxynzoafusjlebqtih + +kqduelpmh +uplhedkmq +dupqelkh +eflyuhwqgdkp +hqplekdu + +gwkfxo +fowxgk +foxkwg +xkfwog +fwkgxo + +xpegdzcsoyjt +zpcsgetjydxo +stoxjgfzecvdpy +typecgxjzosd + +digfewr +psxv + +pntydfukzoecihxv +vtfzihungkcdxoey + +ktaqydchpr +kcalptydhx +ydkprcaht + +qep +pqew +qvpe +qepx + +l +o +o +n + +zubsojhtqep +bujqpsytoieh +upeqthsobyj + +regblhcjn +djgecrtblnh +jhebcnlrg +brehclngj + +lprbihju +jhzoplsnk + +hgnlwjfqczu +cjyuntigwzqeh +qhwlgunfzcajv + +adjmogquh +wpsodnth + +brueif +teiuqrfb +ufrbei +fbieru + +zeaufk +ukfeza + +qk +cqkf +kq +kq +qk + +dfw +ndwft +wfd + +sdevru +fdsr +nbtmord + +vlhxnguq +qvlgun + +nkcoszpaivjqybwt +qjdzgrumbsiopkveaylcx +szypwickvjfoqbha + +xbtzcjeimsnwf +vtkicgmnhbx +xnhabvqicmtdpr + +uxt +utx +utx + +yurfmzncxwbil +vyi +yovi +iya +ksyi + +vbkmdhjzf +vbhkjzmf +mfolkbhjzv + +bcl +blc +clb + +groy +n +mq +wiebc + +bpn +pnb +pbn +bpnw +nbzp + +blgdwivs +gvilsmwbd +bwgdklisnv +busdviwlg +mwlibsgvudc + +stafhuqw +aufhqs +hsqauf +xrkfmepbsnqac + +ajlhmnzqfbiskyxvuoc +svfalqujboincmxzkhy +sxvlznqfajhyboimukc +vljuykzxnsiabqchfmo +fbszjynvolhamucikqx + +tjhcwv +wc + +jobkfqrchsxeilu +jmfiaowhpkulqrx + +janucsmrw +lnjco +qgctnjz +vgjnfc +dcionzxj + +ouhskqaiydtjz +oisamqzehwlyutx +uqytfipahsvzco +uapehtyqziso +yqatsuizefhmow + +klsdvrhmfiqyptuebxwc +usdxgerciwlvnmpyfob +vbwxyedsrmlpiacfu + +mzcf +mwc +chm + +zuipejovcklydarwxqsft +cdevzkwmrjfpoqxtuylsia +frwldqezastuocvixpjyk +xkluzcosjtfvdeapwriqy + +yk +yk +ky +kgy +ykv + +vtrikmwcoju +qtphlzbjwovrg + +pujnbx +nbupjx +ubxpjn + +nikcbsdhge +hibkgcnle +nboehtpigck +likhecnbg + +cuhjlgofs +khsocg +sbfoghzv +ydsngtwop + +swfudijxtklq +xqvnajufkihwtdsl +ixjkwdsqtful + +mvajfubtpgxwocs +pvsbofxmjwaguc +asbgcfmowxujpv +oseuibcgxfvmawjp +pmbcageuojfxswv + +dvwqskngflbpx +ibtgczowdfljmhuaye +svlgnwfrpqbd + +ftxykloisajqwzun +qytozbimwxuafeknj +lazjyixqmotnuwk +voxhyjzknuticqwa + +tfszajmeokvupiy +tmqcvyjsuf +vtyufsmgnj + +kwzrisqu +zuskiqr + +v +h +h +h +w + +g +g +g +g +mg + +wmoigknfuqlerxcpd +xmcrguoeqfnpkwild +egmlufncqdvxropiwk +wagquoxrcfptekdinml +lxgfmeirdquowkcpn From a226768e08de557f40835e87b7fee93fabb6abeb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 6 Dec 2020 07:23:29 +0100 Subject: [PATCH 051/129] 2020: d06: ex2: add solution --- 2020/d06/ex2/ex2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 2020/d06/ex2/ex2.py diff --git a/2020/d06/ex2/ex2.py b/2020/d06/ex2/ex2.py new file mode 100755 index 0000000..c78283d --- /dev/null +++ b/2020/d06/ex2/ex2.py @@ -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() From 7d268d0d4fb2873cc03cc77da7155a9108e1537f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 7 Dec 2020 07:08:52 +0100 Subject: [PATCH 052/129] 2020: d07: ex1: add input --- 2020/d07/ex1/input | 594 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 594 insertions(+) create mode 100644 2020/d07/ex1/input diff --git a/2020/d07/ex1/input b/2020/d07/ex1/input new file mode 100644 index 0000000..ccf5d2e --- /dev/null +++ b/2020/d07/ex1/input @@ -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. From 146b3becf9705fa233e2b47dc997b8fb690014b4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 7 Dec 2020 07:09:03 +0100 Subject: [PATCH 053/129] 2020: d07: ex1: add solution --- 2020/d07/ex1/ex1.py | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100755 2020/d07/ex1/ex1.py diff --git a/2020/d07/ex1/ex1.py b/2020/d07/ex1/ex1.py new file mode 100755 index 0000000..d92977c --- /dev/null +++ b/2020/d07/ex1/ex1.py @@ -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() From acc9ef472c701e7a79754ae230c37c9e8ec85034 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 7 Dec 2020 07:09:18 +0100 Subject: [PATCH 054/129] 2020: d07: ex2: add input --- 2020/d07/ex2/input | 594 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 594 insertions(+) create mode 100644 2020/d07/ex2/input diff --git a/2020/d07/ex2/input b/2020/d07/ex2/input new file mode 100644 index 0000000..ccf5d2e --- /dev/null +++ b/2020/d07/ex2/input @@ -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. From d3a1040f6051869f1cef5cd328f23d7de91dc10c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 7 Dec 2020 07:09:28 +0100 Subject: [PATCH 055/129] 2020: d07: ex2: add solution --- 2020/d07/ex2/ex2.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 2020/d07/ex2/ex2.py diff --git a/2020/d07/ex2/ex2.py b/2020/d07/ex2/ex2.py new file mode 100755 index 0000000..107d737 --- /dev/null +++ b/2020/d07/ex2/ex2.py @@ -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() From 0ed6d5eb435daa83c2cf17438ac80df96f7357f1 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 8 Dec 2020 08:23:25 +0100 Subject: [PATCH 056/129] 2020: d08: ex1: add input --- 2020/d08/ex1/input | 675 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 675 insertions(+) create mode 100644 2020/d08/ex1/input diff --git a/2020/d08/ex1/input b/2020/d08/ex1/input new file mode 100644 index 0000000..296e397 --- /dev/null +++ b/2020/d08/ex1/input @@ -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 From 17138bfc8ff640d322446940331e2aae2f7d61ed Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 8 Dec 2020 08:23:38 +0100 Subject: [PATCH 057/129] 2020: d08: ex1: add solution --- 2020/d08/ex1/ex1.py | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 2020/d08/ex1/ex1.py diff --git a/2020/d08/ex1/ex1.py b/2020/d08/ex1/ex1.py new file mode 100755 index 0000000..a2394fa --- /dev/null +++ b/2020/d08/ex1/ex1.py @@ -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() From 5a39d2babe9ed58eb7fc069e580ec5042f2c2f84 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 8 Dec 2020 08:23:46 +0100 Subject: [PATCH 058/129] 2020: d08: ex2: add input --- 2020/d08/ex2/input | 675 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 675 insertions(+) create mode 100644 2020/d08/ex2/input diff --git a/2020/d08/ex2/input b/2020/d08/ex2/input new file mode 100644 index 0000000..296e397 --- /dev/null +++ b/2020/d08/ex2/input @@ -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 From d7e74e60f17949df5c229bd13f8834da1a7cc03e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 8 Dec 2020 08:24:09 +0100 Subject: [PATCH 059/129] 2020: d08: ex2: add solution --- 2020/d08/ex2/ex2.py | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 2020/d08/ex2/ex2.py diff --git a/2020/d08/ex2/ex2.py b/2020/d08/ex2/ex2.py new file mode 100755 index 0000000..bba650d --- /dev/null +++ b/2020/d08/ex2/ex2.py @@ -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() From 074226098fa76abc963d7dff2c6990b2316d0d77 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 9 Dec 2020 09:10:32 +0100 Subject: [PATCH 060/129] 2020: d09: ex1: add input --- 2020/d09/ex1/input | 1000 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1000 insertions(+) create mode 100644 2020/d09/ex1/input diff --git a/2020/d09/ex1/input b/2020/d09/ex1/input new file mode 100644 index 0000000..ca43231 --- /dev/null +++ b/2020/d09/ex1/input @@ -0,0 +1,1000 @@ +21 +32 +15 +49 +19 +30 +50 +40 +33 +45 +11 +42 +26 +10 +12 +5 +4 +1 +27 +17 +41 +43 +14 +29 +18 +6 +24 +16 +28 +7 +8 +31 +44 +9 +13 +30 +85 +11 +22 +10 +48 +70 +15 +19 +20 +17 +21 +25 +14 +23 +18 +26 +104 +37 +16 +24 +27 +28 +29 +31 +32 +44 +30 +46 +39 +33 +35 +34 +42 +36 +38 +47 +72 +40 +41 +43 +60 +45 +48 +49 +51 +55 +73 +59 +69 +62 +63 +65 +71 +67 +68 +89 +70 +74 +78 +160 +81 +83 +136 +90 +117 +130 +99 +115 +100 +106 +118 +152 +121 +161 +219 +184 +133 +142 +145 +146 +159 +164 +155 +168 +171 +217 +381 +252 +189 +633 +205 +199 +246 +221 +224 +239 +301 +254 +459 +275 +304 +323 +287 +291 +588 +392 +319 +326 +475 +388 +711 +394 +404 +695 +429 +420 +540 +526 +445 +692 +849 +1066 +529 +562 +566 +578 +675 +1007 +970 +718 +723 +645 +865 +814 +792 +798 +823 +824 +1247 +874 +946 +971 +1398 +1597 +1174 +1140 +1241 +1091 +1128 +1211 +1689 +1738 +1363 +1437 +2995 +1368 +1443 +2263 +1770 +1926 +1951 +2145 +1698 +1820 +1845 +1917 +2062 +2219 +2574 +2826 +2911 +2302 +2339 +2491 +4109 +3066 +3175 +3934 +2805 +2811 +3141 +6079 +3468 +3543 +3518 +3665 +4122 +4219 +3737 +3762 +3979 +5967 +4558 +4641 +4793 +8418 +6424 +8328 +5557 +8101 +5616 +11065 +7477 +6279 +5952 +6609 +11250 +11072 +7762 +7859 +10745 +7499 +7716 +7741 +15863 +14138 +10510 +15027 +10593 +10350 +11173 +12231 +11895 +15239 +14041 +11568 +12888 +23068 +12561 +21995 +14108 +25772 +15215 +15240 +15358 +15457 +22581 +18066 +29971 +20860 +24783 +21523 +26922 +33563 +21918 +22741 +30672 +23463 +24129 +24456 +26783 +30455 +26669 +51494 +29323 +29348 +30573 +46129 +68710 +30815 +38926 +43601 +51266 +53434 +44989 +43441 +44264 +60020 +46374 +50132 +49410 +47592 +53452 +48585 +77935 +60163 +55992 +56017 +58671 +59921 +81839 +86518 +96875 +96255 +78407 +82367 +91363 +87705 +89253 +88430 +89815 +94396 +98717 +106537 +143847 +142705 +96177 +102037 +104577 +115938 +114663 +190573 +118592 +186944 +138328 +179068 +160774 +166837 +171620 +176958 +170072 +261297 +176135 +177683 +234505 +184211 +193113 +202714 +411463 +219240 +293621 +198214 +206614 +271414 +285429 +233255 +256920 +302803 +299102 +391327 +382749 +327611 +341692 +380397 +346207 +347755 +353818 +396923 +361894 +631428 +504669 +395827 +400928 +404828 +431469 +491835 +439869 +463534 +490175 +518684 +532357 +556022 +669303 +730504 +903777 +710360 +675366 +1088379 +693962 +701573 +1361932 +715712 +840797 +757721 +796755 +800655 +805756 +1019556 +836297 +995891 +1363265 +1551913 +1179246 +1205887 +1051041 +1257595 +1433087 +1344669 +1606411 +1369328 +1395535 +1376939 +1409674 +1417285 +1502228 +1473433 +1832188 +2302883 +1554476 +1597410 +1636952 +2182695 +2042184 +1887338 +2547804 +2588920 +3209127 +2230287 +2256928 +2446576 +2764863 +4618801 +2713997 +2746267 +4421108 +2974349 +3998594 +3524290 +2890718 +3389566 +4299112 +3939835 +3151886 +4763603 +4144266 +3819647 +4070033 +3929522 +4117625 +6363915 +5021791 +4970925 +4487215 +5160573 +5192843 +5460264 +6971533 +5604715 +5636985 +7377933 +5865067 +7221919 +7453812 +7081408 +6541452 +7091721 +7269511 +7639101 +8951313 +9935100 +10470974 +7999555 +8416737 +8604840 +9458140 +9509006 +12241981 +15638656 +15663817 +17556153 +11097249 +15146292 +14491430 +18886413 +15080963 +23096270 +16476552 +14361232 +24962404 +15269066 +14730822 +32601505 +16416292 +20658718 +16604395 +17021577 +17457695 +26366315 +18062980 +30810109 +38734926 +30932883 +25458481 +29222252 +26243541 +25588679 +28852662 +29092054 +51591601 +29442195 +30837784 +29630298 +39323636 +29999888 +32290643 +38116413 +33020687 +33437869 +33625972 +34062090 +43387892 +43046374 +62462882 +55030874 +51047160 +54680733 +51702022 +54810931 +58074914 +55096203 +71614279 +64275653 +58534249 +59072493 +59442083 +77449982 +98077248 +105858091 +87386846 +65311330 +66458556 +66646659 +67063841 +67688062 +85109250 +98198823 +160661705 +102749182 +118160578 +105727893 +106798225 +106512953 +150420580 +165765310 +212371044 +154450687 +172496096 +117606742 +125531049 +126088742 +131769886 +131957989 +132375171 +333157801 +132999392 +227120261 +133015568 +190837143 +250622310 +183308073 +263964133 +212240846 +208477075 +212526118 +223334635 +213311178 +224119695 +243137791 +329847588 +243695484 +249376628 +259088134 +249564731 +251619791 +339399920 +263727875 +264333160 +436645813 +357135263 +266014960 +442456934 +580469898 +414171778 +391785148 +395548919 +420717921 +425837296 +421788253 +435860753 +644837616 +492702522 +467257486 +486833275 +493072112 +493260215 +498941359 +501184522 +513292606 +515347666 +603733080 +748920411 +530348120 +623150223 +752684182 +657800108 +1070674912 +787334067 +805956926 +812503069 +816266840 +887975407 +847625549 +857649006 +1302681733 +954090761 +966198845 +1801716310 +979905387 +992201574 +1596545960 +1014289025 +1014477128 +1043640726 +1045695786 +2024765673 +1372070634 +1188148228 +1280950331 +1830555865 +1463757034 +1700478476 +1593290993 +1618459995 +1628769909 +1972106961 +1705274555 +1811739767 +1823847851 +1946104232 +1920289606 +2035842300 +2364272208 +3215005955 +2006490599 +2611023088 +2028766153 +3293769469 +2233844014 +2326646117 +2469098559 +2560218862 +2651905262 +2744707365 +4885749276 +3057048027 +3211750988 +3222060902 +3840505920 +3334044464 +5421320235 +5945067552 +5023490755 +3949055759 +3866393838 +7052256908 +8414166111 +4035256752 +4240334613 +9002115579 +4262610167 +12842621499 +4794062876 +11562334441 +4978551379 +5029317421 +10923618931 +5396612627 +5801755392 +6268799015 +9823380297 +6556105366 +7062566822 +12081574329 +7200438302 +8106728451 +9056673043 +7815449597 +7901650590 +9772614255 +8275591365 +8297866919 +9064574173 +8502944780 +9241161546 +9291927588 +10007868800 +19064541843 +10780306771 +12794000976 +10425930048 +13672203992 +11198368019 +15307166753 +13469237317 +19282012631 +13618672188 +14263005124 +16573458284 +15015887899 +28837156098 +15717100187 +21434121785 +16404595370 +16778536145 +19496234938 +35213335125 +27771826303 +17744106326 +34080429742 +21206236819 +24044602236 +21624298067 +32965472255 +30245662276 +23895167365 +31420483269 +24667605336 +28634560087 +27087909505 +29278893023 +29980105311 +48712207572 +30732988086 +31794424044 +32121695557 +37240341264 +51414227096 +33183131515 +48978063122 +51824536068 +38950343145 +39368404393 +45250839055 +49840796906 +103238763164 +45519465432 +127133930529 +56462029380 +48562772701 +50983076870 +69034765308 +64328250769 +71162828437 +56366802528 +77641160989 +76190684409 +67973329350 +82491180319 +63916119601 +78318747538 +70423472779 +95360262338 +87513115846 +88791140051 +84201182200 +109847716201 +140106804010 +140518935178 +96502542302 +113492794782 +94082238133 +139458238087 +177821045551 +99545849571 +107349879398 +120695053297 +120282922129 +124340131878 +126790275307 +189841059717 +131889448951 +148742220317 +134339592380 +185668626936 +154624654979 +157936588625 +171714298046 +172992322251 +326338953025 +191551061598 +190584780435 +326563265868 +347777648342 +193628087704 +201432117531 +214777291430 +453129228332 +206895728969 +219828771700 +227632801527 +240977975426 +541116244455 +258679724258 +339327000752 +266229041331 +334410847253 +283081812697 +288964247359 +312561243604 +397480509404 +329650886671 +344706620297 +363577102686 +382135842033 +476709900401 +426724500669 +395060205235 +546138737828 +400523816673 +553539219030 +455755266856 +541761536955 +434528530496 +636038180661 +468610776953 +499657699684 +524908765589 +547643971617 +555193288690 +549310854028 +572046060056 +709806313366 +723492777855 +642212130275 +874190409805 +798261663624 +708283722983 +745712944719 +907044607622 +856279083529 +980667268324 +1005066120884 +835052347169 +1421834381422 +890283797352 +903139307449 +1047301671301 +934186230180 +1403923055146 +1017921630981 +1024566465273 +1072552737206 +1096954825645 +1104504142718 +2428489520419 +1660133761256 +1418090036349 +1350495853258 +1387925074994 +1453996667702 +1506545386607 +1543336070152 +1601992028248 +1691331430698 +1738191654618 +1725336144521 +1824470027532 +2144256496946 +2278208872346 +1793423104801 +1975692044655 +1958752695453 +2006738967386 +3549806172053 +2042488096254 +2097119202479 +2460477812200 +2201458968363 +2454999995976 +2768585889607 +4185813956721 +2738420928252 +4497488092230 +2841921742696 +2960542054309 +4476612582870 +4479667840709 +7440209895018 +3562661682150 +3752175800254 +3617893132333 +6404583424846 +4635344847497 +4208197935749 +4848660710082 +3965491662839 +4001240791707 +4049227063640 +7803707089054 +6023139494350 +4298578170842 +5162001022672 +4970044857970 +5415542050285 +6807413405535 +5580342670948 +8843542783246 +6843162534403 +5802463797005 +7168739990058 +7180554814483 +8209438727456 +7528153344989 +7314837482404 +7370068932587 +7826091068082 +7966732454546 +14696893335047 +15494885799535 +8014718726479 +11777458263505 +8050467855347 +8347805234482 +9268623028812 +11467318160900 +10101041967847 +10132045880642 +10385586908255 +22338048333938 +17319090884159 +12423505205351 +12971203787063 +12645626331408 +12983018611488 +14349294804541 +14495392296887 +14684906414991 +19092295745909 +15281569936950 +15336801387133 +28319819998621 +15981451181025 +35073746926934 +16065186581826 +20438223931830 +18151509823194 +16398273089829 +18448847202329 +25394708992414 +23356790695318 +20233087848489 +24880979205142 +22809092113606 +25069131536759 +25406523816839 +25628644942896 +25616830118471 +36339809306806 +30560578878713 +28844687101428 +29180298711878 +53936650117092 +34429097133042 +58024985813306 +33785648589462 +32046637762851 +90276459423898 +32463459671655 +50495484965180 +34549782913023 +34847120292158 +36631360938318 +41805637897647 +47878223650365 +50475655353598 +43042179962095 +51989390825484 +59402478707933 +57115769299610 +51023353935310 +54461517219899 +54797128830349 +59740877590591 +59405265980141 From 5da7942d780b94b789ad88afede090e553b74d5d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 9 Dec 2020 09:10:46 +0100 Subject: [PATCH 061/129] 2020: d09: ex1: add solution --- 2020/d09/ex1/ex1.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 2020/d09/ex1/ex1.py diff --git a/2020/d09/ex1/ex1.py b/2020/d09/ex1/ex1.py new file mode 100755 index 0000000..318e38f --- /dev/null +++ b/2020/d09/ex1/ex1.py @@ -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() From e127a77443081b5a2e1e7846dcb6c552081772a6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 9 Dec 2020 09:11:16 +0100 Subject: [PATCH 062/129] 2020: d09: ex2: add input --- 2020/d09/ex2/input | 1000 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1000 insertions(+) create mode 100644 2020/d09/ex2/input diff --git a/2020/d09/ex2/input b/2020/d09/ex2/input new file mode 100644 index 0000000..ca43231 --- /dev/null +++ b/2020/d09/ex2/input @@ -0,0 +1,1000 @@ +21 +32 +15 +49 +19 +30 +50 +40 +33 +45 +11 +42 +26 +10 +12 +5 +4 +1 +27 +17 +41 +43 +14 +29 +18 +6 +24 +16 +28 +7 +8 +31 +44 +9 +13 +30 +85 +11 +22 +10 +48 +70 +15 +19 +20 +17 +21 +25 +14 +23 +18 +26 +104 +37 +16 +24 +27 +28 +29 +31 +32 +44 +30 +46 +39 +33 +35 +34 +42 +36 +38 +47 +72 +40 +41 +43 +60 +45 +48 +49 +51 +55 +73 +59 +69 +62 +63 +65 +71 +67 +68 +89 +70 +74 +78 +160 +81 +83 +136 +90 +117 +130 +99 +115 +100 +106 +118 +152 +121 +161 +219 +184 +133 +142 +145 +146 +159 +164 +155 +168 +171 +217 +381 +252 +189 +633 +205 +199 +246 +221 +224 +239 +301 +254 +459 +275 +304 +323 +287 +291 +588 +392 +319 +326 +475 +388 +711 +394 +404 +695 +429 +420 +540 +526 +445 +692 +849 +1066 +529 +562 +566 +578 +675 +1007 +970 +718 +723 +645 +865 +814 +792 +798 +823 +824 +1247 +874 +946 +971 +1398 +1597 +1174 +1140 +1241 +1091 +1128 +1211 +1689 +1738 +1363 +1437 +2995 +1368 +1443 +2263 +1770 +1926 +1951 +2145 +1698 +1820 +1845 +1917 +2062 +2219 +2574 +2826 +2911 +2302 +2339 +2491 +4109 +3066 +3175 +3934 +2805 +2811 +3141 +6079 +3468 +3543 +3518 +3665 +4122 +4219 +3737 +3762 +3979 +5967 +4558 +4641 +4793 +8418 +6424 +8328 +5557 +8101 +5616 +11065 +7477 +6279 +5952 +6609 +11250 +11072 +7762 +7859 +10745 +7499 +7716 +7741 +15863 +14138 +10510 +15027 +10593 +10350 +11173 +12231 +11895 +15239 +14041 +11568 +12888 +23068 +12561 +21995 +14108 +25772 +15215 +15240 +15358 +15457 +22581 +18066 +29971 +20860 +24783 +21523 +26922 +33563 +21918 +22741 +30672 +23463 +24129 +24456 +26783 +30455 +26669 +51494 +29323 +29348 +30573 +46129 +68710 +30815 +38926 +43601 +51266 +53434 +44989 +43441 +44264 +60020 +46374 +50132 +49410 +47592 +53452 +48585 +77935 +60163 +55992 +56017 +58671 +59921 +81839 +86518 +96875 +96255 +78407 +82367 +91363 +87705 +89253 +88430 +89815 +94396 +98717 +106537 +143847 +142705 +96177 +102037 +104577 +115938 +114663 +190573 +118592 +186944 +138328 +179068 +160774 +166837 +171620 +176958 +170072 +261297 +176135 +177683 +234505 +184211 +193113 +202714 +411463 +219240 +293621 +198214 +206614 +271414 +285429 +233255 +256920 +302803 +299102 +391327 +382749 +327611 +341692 +380397 +346207 +347755 +353818 +396923 +361894 +631428 +504669 +395827 +400928 +404828 +431469 +491835 +439869 +463534 +490175 +518684 +532357 +556022 +669303 +730504 +903777 +710360 +675366 +1088379 +693962 +701573 +1361932 +715712 +840797 +757721 +796755 +800655 +805756 +1019556 +836297 +995891 +1363265 +1551913 +1179246 +1205887 +1051041 +1257595 +1433087 +1344669 +1606411 +1369328 +1395535 +1376939 +1409674 +1417285 +1502228 +1473433 +1832188 +2302883 +1554476 +1597410 +1636952 +2182695 +2042184 +1887338 +2547804 +2588920 +3209127 +2230287 +2256928 +2446576 +2764863 +4618801 +2713997 +2746267 +4421108 +2974349 +3998594 +3524290 +2890718 +3389566 +4299112 +3939835 +3151886 +4763603 +4144266 +3819647 +4070033 +3929522 +4117625 +6363915 +5021791 +4970925 +4487215 +5160573 +5192843 +5460264 +6971533 +5604715 +5636985 +7377933 +5865067 +7221919 +7453812 +7081408 +6541452 +7091721 +7269511 +7639101 +8951313 +9935100 +10470974 +7999555 +8416737 +8604840 +9458140 +9509006 +12241981 +15638656 +15663817 +17556153 +11097249 +15146292 +14491430 +18886413 +15080963 +23096270 +16476552 +14361232 +24962404 +15269066 +14730822 +32601505 +16416292 +20658718 +16604395 +17021577 +17457695 +26366315 +18062980 +30810109 +38734926 +30932883 +25458481 +29222252 +26243541 +25588679 +28852662 +29092054 +51591601 +29442195 +30837784 +29630298 +39323636 +29999888 +32290643 +38116413 +33020687 +33437869 +33625972 +34062090 +43387892 +43046374 +62462882 +55030874 +51047160 +54680733 +51702022 +54810931 +58074914 +55096203 +71614279 +64275653 +58534249 +59072493 +59442083 +77449982 +98077248 +105858091 +87386846 +65311330 +66458556 +66646659 +67063841 +67688062 +85109250 +98198823 +160661705 +102749182 +118160578 +105727893 +106798225 +106512953 +150420580 +165765310 +212371044 +154450687 +172496096 +117606742 +125531049 +126088742 +131769886 +131957989 +132375171 +333157801 +132999392 +227120261 +133015568 +190837143 +250622310 +183308073 +263964133 +212240846 +208477075 +212526118 +223334635 +213311178 +224119695 +243137791 +329847588 +243695484 +249376628 +259088134 +249564731 +251619791 +339399920 +263727875 +264333160 +436645813 +357135263 +266014960 +442456934 +580469898 +414171778 +391785148 +395548919 +420717921 +425837296 +421788253 +435860753 +644837616 +492702522 +467257486 +486833275 +493072112 +493260215 +498941359 +501184522 +513292606 +515347666 +603733080 +748920411 +530348120 +623150223 +752684182 +657800108 +1070674912 +787334067 +805956926 +812503069 +816266840 +887975407 +847625549 +857649006 +1302681733 +954090761 +966198845 +1801716310 +979905387 +992201574 +1596545960 +1014289025 +1014477128 +1043640726 +1045695786 +2024765673 +1372070634 +1188148228 +1280950331 +1830555865 +1463757034 +1700478476 +1593290993 +1618459995 +1628769909 +1972106961 +1705274555 +1811739767 +1823847851 +1946104232 +1920289606 +2035842300 +2364272208 +3215005955 +2006490599 +2611023088 +2028766153 +3293769469 +2233844014 +2326646117 +2469098559 +2560218862 +2651905262 +2744707365 +4885749276 +3057048027 +3211750988 +3222060902 +3840505920 +3334044464 +5421320235 +5945067552 +5023490755 +3949055759 +3866393838 +7052256908 +8414166111 +4035256752 +4240334613 +9002115579 +4262610167 +12842621499 +4794062876 +11562334441 +4978551379 +5029317421 +10923618931 +5396612627 +5801755392 +6268799015 +9823380297 +6556105366 +7062566822 +12081574329 +7200438302 +8106728451 +9056673043 +7815449597 +7901650590 +9772614255 +8275591365 +8297866919 +9064574173 +8502944780 +9241161546 +9291927588 +10007868800 +19064541843 +10780306771 +12794000976 +10425930048 +13672203992 +11198368019 +15307166753 +13469237317 +19282012631 +13618672188 +14263005124 +16573458284 +15015887899 +28837156098 +15717100187 +21434121785 +16404595370 +16778536145 +19496234938 +35213335125 +27771826303 +17744106326 +34080429742 +21206236819 +24044602236 +21624298067 +32965472255 +30245662276 +23895167365 +31420483269 +24667605336 +28634560087 +27087909505 +29278893023 +29980105311 +48712207572 +30732988086 +31794424044 +32121695557 +37240341264 +51414227096 +33183131515 +48978063122 +51824536068 +38950343145 +39368404393 +45250839055 +49840796906 +103238763164 +45519465432 +127133930529 +56462029380 +48562772701 +50983076870 +69034765308 +64328250769 +71162828437 +56366802528 +77641160989 +76190684409 +67973329350 +82491180319 +63916119601 +78318747538 +70423472779 +95360262338 +87513115846 +88791140051 +84201182200 +109847716201 +140106804010 +140518935178 +96502542302 +113492794782 +94082238133 +139458238087 +177821045551 +99545849571 +107349879398 +120695053297 +120282922129 +124340131878 +126790275307 +189841059717 +131889448951 +148742220317 +134339592380 +185668626936 +154624654979 +157936588625 +171714298046 +172992322251 +326338953025 +191551061598 +190584780435 +326563265868 +347777648342 +193628087704 +201432117531 +214777291430 +453129228332 +206895728969 +219828771700 +227632801527 +240977975426 +541116244455 +258679724258 +339327000752 +266229041331 +334410847253 +283081812697 +288964247359 +312561243604 +397480509404 +329650886671 +344706620297 +363577102686 +382135842033 +476709900401 +426724500669 +395060205235 +546138737828 +400523816673 +553539219030 +455755266856 +541761536955 +434528530496 +636038180661 +468610776953 +499657699684 +524908765589 +547643971617 +555193288690 +549310854028 +572046060056 +709806313366 +723492777855 +642212130275 +874190409805 +798261663624 +708283722983 +745712944719 +907044607622 +856279083529 +980667268324 +1005066120884 +835052347169 +1421834381422 +890283797352 +903139307449 +1047301671301 +934186230180 +1403923055146 +1017921630981 +1024566465273 +1072552737206 +1096954825645 +1104504142718 +2428489520419 +1660133761256 +1418090036349 +1350495853258 +1387925074994 +1453996667702 +1506545386607 +1543336070152 +1601992028248 +1691331430698 +1738191654618 +1725336144521 +1824470027532 +2144256496946 +2278208872346 +1793423104801 +1975692044655 +1958752695453 +2006738967386 +3549806172053 +2042488096254 +2097119202479 +2460477812200 +2201458968363 +2454999995976 +2768585889607 +4185813956721 +2738420928252 +4497488092230 +2841921742696 +2960542054309 +4476612582870 +4479667840709 +7440209895018 +3562661682150 +3752175800254 +3617893132333 +6404583424846 +4635344847497 +4208197935749 +4848660710082 +3965491662839 +4001240791707 +4049227063640 +7803707089054 +6023139494350 +4298578170842 +5162001022672 +4970044857970 +5415542050285 +6807413405535 +5580342670948 +8843542783246 +6843162534403 +5802463797005 +7168739990058 +7180554814483 +8209438727456 +7528153344989 +7314837482404 +7370068932587 +7826091068082 +7966732454546 +14696893335047 +15494885799535 +8014718726479 +11777458263505 +8050467855347 +8347805234482 +9268623028812 +11467318160900 +10101041967847 +10132045880642 +10385586908255 +22338048333938 +17319090884159 +12423505205351 +12971203787063 +12645626331408 +12983018611488 +14349294804541 +14495392296887 +14684906414991 +19092295745909 +15281569936950 +15336801387133 +28319819998621 +15981451181025 +35073746926934 +16065186581826 +20438223931830 +18151509823194 +16398273089829 +18448847202329 +25394708992414 +23356790695318 +20233087848489 +24880979205142 +22809092113606 +25069131536759 +25406523816839 +25628644942896 +25616830118471 +36339809306806 +30560578878713 +28844687101428 +29180298711878 +53936650117092 +34429097133042 +58024985813306 +33785648589462 +32046637762851 +90276459423898 +32463459671655 +50495484965180 +34549782913023 +34847120292158 +36631360938318 +41805637897647 +47878223650365 +50475655353598 +43042179962095 +51989390825484 +59402478707933 +57115769299610 +51023353935310 +54461517219899 +54797128830349 +59740877590591 +59405265980141 From f3456d2ca9de2e3ff234f4179b78f1b9db009760 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 9 Dec 2020 09:11:33 +0100 Subject: [PATCH 063/129] 2020: d09: ex2: add solution --- 2020/d09/ex2/ex2.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 2020/d09/ex2/ex2.py diff --git a/2020/d09/ex2/ex2.py b/2020/d09/ex2/ex2.py new file mode 100755 index 0000000..f60e2eb --- /dev/null +++ b/2020/d09/ex2/ex2.py @@ -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() From f67de590ce19fecaef5219ab9966de74554c0400 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 10 Dec 2020 07:29:04 +0100 Subject: [PATCH 064/129] 2020: d10: ex1: add input --- 2020/d10/ex1/input | 101 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 2020/d10/ex1/input diff --git a/2020/d10/ex1/input b/2020/d10/ex1/input new file mode 100644 index 0000000..a97393a --- /dev/null +++ b/2020/d10/ex1/input @@ -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 From 9bc536f6ec2d0bd7c6eea32b80ac1605a4be62ce Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 10 Dec 2020 07:29:12 +0100 Subject: [PATCH 065/129] 2020: d10: ex1: add solution --- 2020/d10/ex1/ex1.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 2020/d10/ex1/ex1.py diff --git a/2020/d10/ex1/ex1.py b/2020/d10/ex1/ex1.py new file mode 100755 index 0000000..e75dd5c --- /dev/null +++ b/2020/d10/ex1/ex1.py @@ -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() From 5fb874f00bcd7e61bd2859319f50793db453dcc3 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 10 Dec 2020 07:29:21 +0100 Subject: [PATCH 066/129] 2020: d10: ex2: add input --- 2020/d10/ex2/input | 101 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 2020/d10/ex2/input diff --git a/2020/d10/ex2/input b/2020/d10/ex2/input new file mode 100644 index 0000000..a97393a --- /dev/null +++ b/2020/d10/ex2/input @@ -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 From d3abeae02a053aa03800f5d3fcdd254a8bd38cea Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 10 Dec 2020 07:29:28 +0100 Subject: [PATCH 067/129] 2020: d10: ex2: add solution --- 2020/d10/ex2/ex2.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 2020/d10/ex2/ex2.py diff --git a/2020/d10/ex2/ex2.py b/2020/d10/ex2/ex2.py new file mode 100755 index 0000000..6af091e --- /dev/null +++ b/2020/d10/ex2/ex2.py @@ -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() From c318b9970c3a1901770634999768d9a567ffc7c5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 11 Dec 2020 08:41:03 +0100 Subject: [PATCH 068/129] 2020: d11: ex1: add input --- 2020/d11/ex1/input | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 2020/d11/ex1/input diff --git a/2020/d11/ex1/input b/2020/d11/ex1/input new file mode 100644 index 0000000..6577da1 --- /dev/null +++ b/2020/d11/ex1/input @@ -0,0 +1,91 @@ +LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL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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 From acc175e4a63480d8bb8dffe084d29d2628da5f54 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 11 Dec 2020 08:41:30 +0100 Subject: [PATCH 069/129] 2020: d11: ex1: add solution --- 2020/d11/ex1/ex1.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 2020/d11/ex1/ex1.py diff --git a/2020/d11/ex1/ex1.py b/2020/d11/ex1/ex1.py new file mode 100755 index 0000000..d0fa0b9 --- /dev/null +++ b/2020/d11/ex1/ex1.py @@ -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() From e9cab0c0bfbc19283883995b67ce8eb27dc20c60 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 11 Dec 2020 08:41:38 +0100 Subject: [PATCH 070/129] 2020: d11: ex2: add input --- 2020/d11/ex2/input | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 2020/d11/ex2/input diff --git a/2020/d11/ex2/input b/2020/d11/ex2/input new file mode 100644 index 0000000..6577da1 --- /dev/null +++ b/2020/d11/ex2/input @@ -0,0 +1,91 @@ +LLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LL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LL.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 From 4b71dee7c440e8bd6192e5b0f72785567da5ab32 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 11 Dec 2020 08:41:47 +0100 Subject: [PATCH 071/129] 2020: d11: ex2: add solution --- 2020/d11/ex2/ex2.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 2020/d11/ex2/ex2.py diff --git a/2020/d11/ex2/ex2.py b/2020/d11/ex2/ex2.py new file mode 100755 index 0000000..ce8bad5 --- /dev/null +++ b/2020/d11/ex2/ex2.py @@ -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() From 060ba385979d45e5149d46626a267a023ef60343 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Dec 2020 10:05:53 +0100 Subject: [PATCH 072/129] 2020: d12: ex1: add input --- 2020/d12/ex1/input | 785 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 785 insertions(+) create mode 100644 2020/d12/ex1/input diff --git a/2020/d12/ex1/input b/2020/d12/ex1/input new file mode 100644 index 0000000..33221b0 --- /dev/null +++ b/2020/d12/ex1/input @@ -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 From 0cd15bb346301f79eedf4a60e81646d4c28f1d6b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Dec 2020 10:06:00 +0100 Subject: [PATCH 073/129] 2020: d12: ex1: add solution --- 2020/d12/ex1/ex1.py | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 2020/d12/ex1/ex1.py diff --git a/2020/d12/ex1/ex1.py b/2020/d12/ex1/ex1.py new file mode 100755 index 0000000..6d74574 --- /dev/null +++ b/2020/d12/ex1/ex1.py @@ -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() From 05670f39c0d1cd2efa614a7cd87739a08515c026 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Dec 2020 10:06:13 +0100 Subject: [PATCH 074/129] 2020: d12: ex2: add input --- 2020/d12/ex2/input | 785 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 785 insertions(+) create mode 100644 2020/d12/ex2/input diff --git a/2020/d12/ex2/input b/2020/d12/ex2/input new file mode 100644 index 0000000..33221b0 --- /dev/null +++ b/2020/d12/ex2/input @@ -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 From 52fba3b92f93f769d1810989582917575fa0d6f6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Dec 2020 10:06:19 +0100 Subject: [PATCH 075/129] 2020: d12: ex2: add solution --- 2020/d12/ex2/ex2.py | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 2020/d12/ex2/ex2.py diff --git a/2020/d12/ex2/ex2.py b/2020/d12/ex2/ex2.py new file mode 100755 index 0000000..90d5f87 --- /dev/null +++ b/2020/d12/ex2/ex2.py @@ -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() From 08ce15d6c06d9f3b6d7400ffaa466fcd5a9ff927 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 13 Dec 2020 07:38:28 +0100 Subject: [PATCH 076/129] 2020: d13: ex1: add input --- 2020/d13/ex1/input | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 2020/d13/ex1/input diff --git a/2020/d13/ex1/input b/2020/d13/ex1/input new file mode 100644 index 0000000..d644142 --- /dev/null +++ b/2020/d13/ex1/input @@ -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 From 617a003a51965cd8d667e6bfdcba61c80237dc46 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 13 Dec 2020 07:38:51 +0100 Subject: [PATCH 077/129] 2020: d13: ex1: add solution --- 2020/d13/ex1/ex1.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 2020/d13/ex1/ex1.py diff --git a/2020/d13/ex1/ex1.py b/2020/d13/ex1/ex1.py new file mode 100755 index 0000000..fadaefb --- /dev/null +++ b/2020/d13/ex1/ex1.py @@ -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() From bf81ef41f84a0cecc9fec767c1618beccac53171 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 13 Dec 2020 07:38:58 +0100 Subject: [PATCH 078/129] 2020: d13: ex2: add input --- 2020/d13/ex2/input | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 2020/d13/ex2/input diff --git a/2020/d13/ex2/input b/2020/d13/ex2/input new file mode 100644 index 0000000..d644142 --- /dev/null +++ b/2020/d13/ex2/input @@ -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 From bf2c65036ffbfa42aa539c2d4b91db358bf75ee5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 13 Dec 2020 07:39:21 +0100 Subject: [PATCH 079/129] 2020: d13: ex2: add solution --- 2020/d13/ex2/ex2.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 2020/d13/ex2/ex2.py diff --git a/2020/d13/ex2/ex2.py b/2020/d13/ex2/ex2.py new file mode 100755 index 0000000..bd76c7d --- /dev/null +++ b/2020/d13/ex2/ex2.py @@ -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() From 78f159598d73a25d441a1c2d576e4bea7be34b33 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 14 Dec 2020 09:53:17 +0100 Subject: [PATCH 080/129] 2020: d14: ex1: add input --- 2020/d14/ex1/input | 575 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 575 insertions(+) create mode 100644 2020/d14/ex1/input diff --git a/2020/d14/ex1/input b/2020/d14/ex1/input new file mode 100644 index 0000000..f1571c4 --- /dev/null +++ b/2020/d14/ex1/input @@ -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 From f97a35248dce4ee74abb937701c73eda1afe4942 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 14 Dec 2020 09:53:24 +0100 Subject: [PATCH 081/129] 2020: d14: ex1: add solution --- 2020/d14/ex1/ex1.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 2020/d14/ex1/ex1.py diff --git a/2020/d14/ex1/ex1.py b/2020/d14/ex1/ex1.py new file mode 100755 index 0000000..a58c8f0 --- /dev/null +++ b/2020/d14/ex1/ex1.py @@ -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() From a1c21232916dbced40ed9f6a29c992bdab00acb8 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 14 Dec 2020 09:53:39 +0100 Subject: [PATCH 082/129] 2020: d15: ex2: add input --- 2020/d14/ex2/input | 575 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 575 insertions(+) create mode 100644 2020/d14/ex2/input diff --git a/2020/d14/ex2/input b/2020/d14/ex2/input new file mode 100644 index 0000000..f1571c4 --- /dev/null +++ b/2020/d14/ex2/input @@ -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 From 2de3573cfdbaa8f06433619410449fc731756683 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 14 Dec 2020 09:53:44 +0100 Subject: [PATCH 083/129] 2020: d15: ex2: add solution --- 2020/d14/ex2/ex2.py | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 2020/d14/ex2/ex2.py diff --git a/2020/d14/ex2/ex2.py b/2020/d14/ex2/ex2.py new file mode 100755 index 0000000..55c254c --- /dev/null +++ b/2020/d14/ex2/ex2.py @@ -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() From c1aaae7946004cb92373c8518bd0804b1981f227 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 15 Dec 2020 11:15:59 +0100 Subject: [PATCH 084/129] 2020: d15: ex1: add input --- 2020/d15/ex1/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2020/d15/ex1/input diff --git a/2020/d15/ex1/input b/2020/d15/ex1/input new file mode 100644 index 0000000..f4a49fb --- /dev/null +++ b/2020/d15/ex1/input @@ -0,0 +1 @@ +0,13,1,16,6,17 From 832159237fb5f45811f0cdaea349a452ef92d6ef Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 15 Dec 2020 11:16:05 +0100 Subject: [PATCH 085/129] 2020: d15: ex1: add solution --- 2020/d15/ex1/ex1.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 2020/d15/ex1/ex1.py diff --git a/2020/d15/ex1/ex1.py b/2020/d15/ex1/ex1.py new file mode 100755 index 0000000..a6cd437 --- /dev/null +++ b/2020/d15/ex1/ex1.py @@ -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() From ef2957970a944670a00457f8f5ec34fe225fbe15 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 15 Dec 2020 11:16:20 +0100 Subject: [PATCH 086/129] 2020: d15: ex2: add input --- 2020/d15/ex2/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2020/d15/ex2/input diff --git a/2020/d15/ex2/input b/2020/d15/ex2/input new file mode 100644 index 0000000..f4a49fb --- /dev/null +++ b/2020/d15/ex2/input @@ -0,0 +1 @@ +0,13,1,16,6,17 From 1831dc4b8f01e9ffdab5f04863a4ff88ee0acc06 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 15 Dec 2020 11:16:26 +0100 Subject: [PATCH 087/129] 2020: d15: ex2: add solution --- 2020/d15/ex2/ex2.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 2020/d15/ex2/ex2.py diff --git a/2020/d15/ex2/ex2.py b/2020/d15/ex2/ex2.py new file mode 100755 index 0000000..4d9077e --- /dev/null +++ b/2020/d15/ex2/ex2.py @@ -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() From 7e162a4e7a9ede2cc3833a26f866461ce3b32275 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Dec 2020 10:10:42 +0100 Subject: [PATCH 088/129] 2020: d16: ex1: add input --- 2020/d16/ex1/input | 264 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 2020/d16/ex1/input diff --git a/2020/d16/ex1/input b/2020/d16/ex1/input new file mode 100644 index 0000000..4123288 --- /dev/null +++ b/2020/d16/ex1/input @@ -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 From 6501cb9cf5a0e0aac16be935ebc4f408a11c8b99 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Dec 2020 10:10:50 +0100 Subject: [PATCH 089/129] 2020: d16: ex1: add solution --- 2020/d16/ex1/ex1.py | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 2020/d16/ex1/ex1.py diff --git a/2020/d16/ex1/ex1.py b/2020/d16/ex1/ex1.py new file mode 100755 index 0000000..91f2665 --- /dev/null +++ b/2020/d16/ex1/ex1.py @@ -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() From a529394eb448e4e65a3b4c02ab3501346c7caeb1 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Dec 2020 10:10:59 +0100 Subject: [PATCH 090/129] 2020: d16: ex2: add input --- 2020/d16/ex2/input | 264 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 2020/d16/ex2/input diff --git a/2020/d16/ex2/input b/2020/d16/ex2/input new file mode 100644 index 0000000..4123288 --- /dev/null +++ b/2020/d16/ex2/input @@ -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 From 80a4297e9331f5f1555c57cf20647990635cc687 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Dec 2020 10:11:06 +0100 Subject: [PATCH 091/129] 2020: d16: ex2: add solution --- 2020/d16/ex2/ex2.py | 106 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 2020/d16/ex2/ex2.py diff --git a/2020/d16/ex2/ex2.py b/2020/d16/ex2/ex2.py new file mode 100755 index 0000000..61423f4 --- /dev/null +++ b/2020/d16/ex2/ex2.py @@ -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() From d36fb3473d65808023a4c69e04ac961a57b7a621 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 17 Dec 2020 08:55:29 +0100 Subject: [PATCH 092/129] 2020: d17: ex1: add input --- 2020/d17/ex1/input | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 2020/d17/ex1/input diff --git a/2020/d17/ex1/input b/2020/d17/ex1/input new file mode 100644 index 0000000..e6c20d5 --- /dev/null +++ b/2020/d17/ex1/input @@ -0,0 +1,8 @@ +######.# +#.###.#. +###..... +#.####.. +##.#.### +.######. +###.#### +######.# From ef6e30cb6c415d23fdc89579bc468da50b1b5a12 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 17 Dec 2020 08:55:37 +0100 Subject: [PATCH 093/129] 2020: d17: ex1: add solution --- 2020/d17/ex1/ex1.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 2020/d17/ex1/ex1.py diff --git a/2020/d17/ex1/ex1.py b/2020/d17/ex1/ex1.py new file mode 100755 index 0000000..dd9efee --- /dev/null +++ b/2020/d17/ex1/ex1.py @@ -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() From 6dcd2bcf69d14e32675fb3b392a198221861c206 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 17 Dec 2020 08:55:44 +0100 Subject: [PATCH 094/129] 2020: d17: ex2: add input --- 2020/d17/ex2/input | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 2020/d17/ex2/input diff --git a/2020/d17/ex2/input b/2020/d17/ex2/input new file mode 100644 index 0000000..e6c20d5 --- /dev/null +++ b/2020/d17/ex2/input @@ -0,0 +1,8 @@ +######.# +#.###.#. +###..... +#.####.. +##.#.### +.######. +###.#### +######.# From 8c2a2ed4382b3236668d0562874538071a6a18ad Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 17 Dec 2020 08:55:51 +0100 Subject: [PATCH 095/129] 2020: d17: ex2: add solution --- 2020/d17/ex2/ex2.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 2020/d17/ex2/ex2.py diff --git a/2020/d17/ex2/ex2.py b/2020/d17/ex2/ex2.py new file mode 100755 index 0000000..8589288 --- /dev/null +++ b/2020/d17/ex2/ex2.py @@ -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() From 932e5a40f7e806c99d9b147371e7399e75ccb1ea Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 18 Dec 2020 10:09:45 +0100 Subject: [PATCH 096/129] 2020: d18: ex1: add input --- 2020/d18/ex1/input | 377 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 377 insertions(+) create mode 100644 2020/d18/ex1/input diff --git a/2020/d18/ex1/input b/2020/d18/ex1/input new file mode 100644 index 0000000..41690ab --- /dev/null +++ b/2020/d18/ex1/input @@ -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 + 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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) From 34d72e9729665f2ed4d1a1d3d90ed7c9946cc1ca Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 18 Dec 2020 10:09:52 +0100 Subject: [PATCH 097/129] 2020: d18: ex1: add solution --- 2020/d18/ex1/ex1.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 2020/d18/ex1/ex1.py diff --git a/2020/d18/ex1/ex1.py b/2020/d18/ex1/ex1.py new file mode 100755 index 0000000..a7bd7bd --- /dev/null +++ b/2020/d18/ex1/ex1.py @@ -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() From 2d4a21dc9a37f403ab95a4daa8f8102057efa5c1 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 18 Dec 2020 10:10:02 +0100 Subject: [PATCH 098/129] 2020: d18: ex2: add input --- 2020/d18/ex2/input | 377 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 377 insertions(+) create mode 100644 2020/d18/ex2/input diff --git a/2020/d18/ex2/input b/2020/d18/ex2/input new file mode 100644 index 0000000..41690ab --- /dev/null +++ b/2020/d18/ex2/input @@ -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 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1d1936f5e72df1330a3cf8d28d8a47cdb6937aa9 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 18 Dec 2020 10:10:08 +0100 Subject: [PATCH 099/129] 2020: d18: ex2: add solution --- 2020/d18/ex2/ex2.py | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 2020/d18/ex2/ex2.py diff --git a/2020/d18/ex2/ex2.py b/2020/d18/ex2/ex2.py new file mode 100755 index 0000000..94f13ed --- /dev/null +++ b/2020/d18/ex2/ex2.py @@ -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() From aee3b2f333b95ead3daa9c12b5c9a76843296eed Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 19 Dec 2020 11:00:25 +0100 Subject: [PATCH 100/129] 2020: d19: ex1: add input --- 2020/d19/ex1/input | 561 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 561 insertions(+) create mode 100644 2020/d19/ex1/input diff --git a/2020/d19/ex1/input b/2020/d19/ex1/input new file mode 100644 index 0000000..6242e89 --- /dev/null +++ b/2020/d19/ex1/input @@ -0,0 +1,561 @@ +102: 100 47 | 76 84 +23: 60 47 | 73 84 +132: 17 47 | 81 84 +108: 55 100 +18: 116 47 | 26 84 +103: 84 115 | 47 81 +65: 84 113 | 47 50 +128: 107 47 | 125 84 +14: 84 100 | 47 107 +118: 47 17 | 84 57 +2: 47 100 | 84 40 +28: 63 84 | 74 47 +22: 102 84 | 123 47 +123: 84 74 +19: 3 47 | 13 84 +24: 74 47 | 81 84 +115: 55 55 +90: 92 47 | 44 84 +48: 84 94 | 47 96 +109: 17 84 | 100 47 +92: 84 75 | 47 108 +66: 38 47 | 125 84 +83: 66 47 | 108 84 +31: 121 84 | 77 47 +29: 47 61 | 84 111 +45: 47 47 | 47 84 +59: 47 49 | 84 43 +37: 47 30 | 84 95 +36: 107 84 | 125 47 +82: 74 84 | 38 47 +61: 84 10 | 47 110 +79: 47 28 | 84 109 +33: 101 47 | 133 84 +12: 45 47 | 63 84 +91: 122 84 | 93 47 +122: 65 47 | 52 84 +21: 57 84 | 115 47 +8: 42 +67: 102 47 | 64 84 +39: 113 84 | 81 47 +41: 84 124 | 47 10 +50: 47 47 | 84 84 +17: 47 84 | 84 84 +120: 98 84 | 78 47 +113: 55 47 | 47 84 +20: 84 128 | 47 104 +7: 84 1 | 47 20 +51: 84 113 | 47 81 +56: 84 83 | 47 69 +131: 84 127 | 47 97 +0: 8 11 +5: 47 63 | 84 125 +94: 15 84 | 127 47 +121: 99 47 | 27 84 +119: 47 115 | 84 57 +129: 47 80 | 84 131 +15: 47 100 | 84 45 +35: 84 50 | 47 76 +95: 47 115 | 84 107 +68: 127 84 | 51 47 +124: 84 107 +75: 50 55 +57: 47 84 | 84 55 +13: 47 33 | 84 129 +53: 106 47 | 59 84 +106: 16 84 | 118 47 +89: 84 125 | 47 45 +104: 45 84 | 76 47 +99: 47 56 | 84 7 +78: 84 74 | 47 81 +64: 17 47 | 115 84 +32: 50 84 | 40 47 +1: 47 24 | 84 72 +47: "a" +80: 114 47 | 109 84 +88: 47 119 | 84 132 +105: 47 125 | 84 100 +6: 68 84 | 67 47 +110: 76 84 | 63 47 +38: 84 84 | 84 47 +49: 47 63 | 84 76 +26: 55 107 +81: 47 84 +74: 84 47 +96: 84 89 | 47 117 +77: 47 86 | 84 71 +135: 32 84 | 2 47 +133: 47 15 | 84 128 +42: 19 84 | 62 47 +30: 47 100 | 84 74 +27: 6 47 | 91 84 +63: 84 55 | 47 47 +62: 84 87 | 47 23 +76: 84 84 +4: 84 135 | 47 54 +60: 41 47 | 37 84 +100: 47 47 | 84 47 +85: 47 112 | 84 18 +116: 125 84 | 63 47 +134: 57 47 | 115 84 +34: 52 47 | 25 84 +40: 47 47 +111: 58 84 | 126 47 +3: 29 47 | 130 84 +114: 17 84 | 107 47 +52: 47 45 | 84 74 +10: 47 100 | 84 81 +98: 47 76 | 84 100 +112: 84 82 | 47 103 +72: 40 47 | 45 84 +126: 50 84 | 113 47 +107: 84 47 | 47 84 +11: 42 31 +55: 84 | 47 +54: 12 84 | 5 47 +130: 34 47 | 70 84 +84: "b" +127: 81 47 | 17 84 +87: 84 53 | 47 9 +101: 105 84 | 14 47 +9: 88 84 | 120 47 +73: 47 79 | 84 22 +97: 74 84 | 50 47 +117: 74 47 +70: 47 134 | 84 46 +58: 47 50 | 84 115 +125: 47 47 | 55 84 +46: 47 81 | 84 17 +86: 84 90 | 47 85 +25: 38 84 | 63 47 +69: 39 47 | 78 84 +43: 47 100 | 84 125 +93: 84 66 | 47 35 +44: 47 21 | 84 36 +16: 57 47 | 107 84 +71: 48 84 | 4 47 + +babaaabbbababababbbbabbaabbaabaa +babaaaabaaaaababbbbaaaaa +abbabaabbaaabababaabbbbabbbbbaabbbbabababaaaabbbbababbbb +bbbabababbabbbabbbabbbbb +babaabbbababbbabaabaaaaa +abbabaabbaababbabababbbababbbabbabbabbbabbaabbbb +aaaaabaabbbbbaabbbbbbbbbbaaabbaaabbaabab +baababbabbbabbaaaaaababbaabbababbbabbbbb +aaabaaaabbabbbabbabaabbbabaabbbbaaaaabaaaabaabaaababaabbabbaaaabbbbaabbabbabaaaaaaaabaab +ababaaabababbbababaaabab +bbbbabbbbbaabaaaaaabbbbbbabbbabaabbaaababbbaaaaababaabaabaabababbabbbabbabaaabbaaabbaaaa +babaabaaababaaabaaaababa +aabaaabbaabbbabbabaabaab +bbbaabaaaabaaabbbaaabbbabbbaaabb +aaaaaaabaaababbbbbbbbbbbbaaabaabbaaabbab +bbabbabbaaaaabababaababa +babbababbbabbaababaababbaaaaabaaabbbabba +bbbbbbbababbaaaaabaaabbaabbaaaab +bbbbbaaabbbbbaaaaaabaaaabbbaaabb +babbababaababbbbbbbaaabb +abaabbaabbababaabbababba +abaaabbaaabaabbbabababba +babaaaabaaaababbabbbbaaa +bbbbbbbabaababbaaaaababbabbaabbabbbaabaababaabbbbbbaabab +aaabbabbbaabababbaabaaba +bbbababbabaabbabbbabaaaa +baabbabababaaaabbbbbbaab +bbabbbbabaababbabbbaabab +abaabbabbbabbabbabbbabba +bbbbbbbaaababaaabbaabbbabbaaabbbbabababb +aabbaaabbabbabaaaabbabaababbbaababaabababaaabbaa +aaabaababbbabbbbaaababbbbaaabbbb +aaaaaaaaaaabaaaababbabbb +bbbabbbbaabaababaabbabab +baaabaabbaaaabbbbaaaaaaa +bbbbbbbaabbabbaabaabaaaa +aaaaabaabbabbaaaaaaaaabb +aabaaabbaabbabaaabbabaabbaababaaabbbaaaaababbaabaaabbaaabbaaabaa +bababbbaaabaababbbababaabbaabaabbaaaabbabbaabababbbabbbababbabbb +abbbaababbaabaaaaababbbaaaabbbaa +aababbbaaaabaabbbbabaaaa +aaaaabbaaabaaabbbababaaa +bbbababaaabaaaabbabbabaabbababababababbbabbaaaaabbababbabbbbabbbabbbaabb +bbbabababbbabababababbbb +bbaaababbbabbbbaabbbbbaa +bbababaabaaaabbaabbbbaaa +bbbbabbababbbbaabbaaaababbababbaabaaabababbabbabbbbbbaababbbbabbbbaaaaabbbaabbba +abbabbabbbbbbaabaaaaabababaaaaabaaabbaaaabababba +bbbabaabaababaaabaabbaaa +bbababbbbaaababaaaabbabbaaabbbaa +aabbbbababaabbaabababbaa +aaabbabbbaabbbabbbbbbbbabaaaabbaaabababaabaaabab +aaaaaaababbabbabbabaaaaa +aababaaaaaababbbabbabbabaaababbbbbabbababababaaaabbabbbb +babaabbbbaaabaaabbbabbab +bbbbabbbbaabbbabbbaabbbaabbbbbaabbbbaaabbbbaabbbbaababbaaaabaaaabbabbabbabbaabbb +aaabbbabbaaabaabbaaaaabaabababab +abbababbabbbbbabbaabbbabaaababbbbbbbabaababbbbbabababbbb +bbaabbbaaaaababaaabaaaabbbbbbaabbaaaabbaabaaabaabaaaabbabbabbbaabbaaaaaa +abbabbaaaabaaaabbbbbbaabbabaababbbbabbba +bbaaaabaabbababbbbaabbaa +aabbaabaabbaaabbaaabaaaaaaababbabababbaa +baaaabbaaaaaabbbbabbababbaabbbbabbabbabbaabbaabb +babbaaaabbaabaaabbbbaaaabbbabbaaaaaaaabb +aaaaababaaabbabbababbabb +abbabaaaaaabaababbabaaab +aaabaababbaabbbaababbabb +babbabaabaababbabbabaabb +abbabbaabbabbbabababaaaa +bbabbbaaaababaaaaaabbbaa +bbbbbbbaaaaaabbabbbaabaaaaabbaaa +bbbaabaababaaabbaababbabaababaabbbababba +bbaaabbaabaabbbbbbbaababbbaabaabaaabaababaaaaabbbaaabaababaaaaabaabbbbaabaabbbaa +baabbababbaaaaababaabbabaabbbaabaabbaabbabbbaaababbaaaab +bbabaaaaaaaabababaabbababbaabbbbabbbaaababbaababaabaaaaaaaabaabb +baaaaaabbaababbaababaaaa +bbbabbbbbbaabaabbaaabbab +babbbabababaaaabaabbaaabbbabaabababbbaaabaababbbbbaababbbabbbabb +aabaaababababababaabbbababbababbbabbaabb +bbaabaaabbaabababbaababaabbabbba +bbbabaaaababaabbaabbabbbbabbaabaabbabaabbaabaabaabbaabbabaaabaaa +abbaaabbbbbbbbbbaaabbaab +baabbbbbaabbaabbaabbababbaabaaba +baaaabaaabbbbaabaabbabbbbaababbb +abbbbbbaabbbbbbbbbbbbaaaaaaabaaa +abbbbbbbbbabbbaabbbaaabaaabababa +aababbbaabbabaabbabaaaba +bbabbaabbabbabaaababbbba +aaabbbabbaabaabbbbbabbbbaaaaabbbbabbbabababbbaaa +aaabaabbaabaababaabababb +bbababaaabbbaabaabbababa +baabbbaaaaababababaabbaababbabbb +babbbaabbaaaabbaababbabb +bbababbbababbbaabbabbbabaabababaaabaaaaa +babbbbbbbbabbbababbbbaab +abaabbbbbabbbbbbaaabbaba +bbabbbaabbbbbaaabbbaaaaa +abbbbbbbbaabbbaaabbbbbbabaaaabaaaaaabbbb +aabaaabababbbbbbaaabbaab +bbbabababbbbbbabbbbbaabaabababbaaabbbbbb +aababbbaaaaaaaaaabbaaaaa +ababaababaababbbabbbbabaaabbabaaabbabbaabbaaaaaababaabba +aabbaaabaabbbaabaabaabbbaaabaaab +aabbaaabaaaaabaaaaabbbabaaabaaaababaaaaaabbbbbaaaababbaa +babbbaabaabaaabababbabaababbbaabbabaabbaabababbababaaaaa +aabbbbabababbbaaaaabaabbbaabbabaaaabababaabaaaabaaaababaabbbabbaabaaabbb +bbbbbbababbbabaababbabaabababababaababbabbbbbbbabbaaabbb +bbabababaaababbabbababba +abbbbbbabbbbbbaaabbbaabbbbabaabaaaaaaabb +aaaaabbbbaaaabbabbbabbab +aabbaaabbbbaaaabbabababbbabbaabbbbababbbbaaabbbababaabbbaabaaaaababbbaaa +ababbbabbbabbbaaababbbbbaabbabbaababbaaa +abbabbababbababbbbbbabbb +aabbaabaabbabbabbaabbaab +baabbbaaabbababbabbaaaba +baaabbbaaabbbabbbaaaaaaa +bbaaababaaaaabaabaaaabba +aabaaabbbbabbaabaaababaabbbbaabb +bbbbabbaaaabbabbaabbabab +aabaaaabbaaaaabababbabba +bababbbabaabaabbaaaabaab +ababaaabbbaabaabbbaabaaababaabbbabaabbaaaabbbaaabbbaabab +aababaaabbbbaaaaaaabbbbb +abaabbaabbbbbaaaaaaabaaa +babbbabababbaaaabaaaabab +abbbbbabbabbaaaababbaabb +bbaaaaabbbbababaaaaabaab +bbaababaaaabaabbabaabaab +bbababbaabbbbabbbaaaaabbabababba +bbabbaabbbbbabbaabababbbaabbbbbabaabbaaabbbabbbabaabbaab +abbabbaabbaaaaabbbabbbaabbbabaaabbaaabbbaaabaaab +aaababbababbabaabaabbbababbabbabbbaababaabbbabbaabaababa +baabbaabbbabbababbaaaaaabaaabbab +aabbabaabbbbbbbbbaabaaababaaaaaa +abbaabbabaaaaabaabbbabaabaaabaabaabaabbbaabaabaaaabaaaaa +baaaabbabaababbababbbababababbbb +bbabbaabbaaabbbabaaabaababbbbbbabbaaabaa +baabbbbaabbbbbbabaabbaab +baaaabbaabbababbaababbababaaaabbbbbbbabababaaaba +baabbbbbaabaabbbbbabbaaaabbaabbaabbbbbabbbbbbaba +babaabbbbbaabaaaabaababbabbbbabbbbbaaaaa +baabbababbaababaabbbaaab +bbaaaabbbaaaaaabbbabababbaabbabbbaaabbaaababaabb +abbbbbbaaababaaababbaaba +baabbabababababaaaaaababbababbbabaabbbaaabaaabab +aaaaababaabaabababbbbbbbabbbaaba +bababaaabbbaabbabaaaaabb +aabbaababbabbbbabbbaaaab +bbbbbbbbaabbbabbbabbbbba +aabaababbaabaabbbbaaaaababaaaaabbaaaaaaa +aaaaaaaaaaaaabababbbbbbabbbaabab +bbbaabaaababbbaaaabaaababbababbbabaaabbaabaaaaaa +ababbabbbbbbaabbaaabbaaabbaaabbaaaabbbba +baabababbbbbabaaababbbaabbaaababbbbaaaababbabbbb +bbaabbbaabaaabaaababaabb +bbabbbaaabbaabbbaaaabbaa +bbbabaabaaaaabaaaababaaaabaaabaaaaaaabbaabbaabbabbbbbaba +baaaabbaabbbaabaabbabbaabbbaaabaaabbbbbaaaaabaab +bbabbabbbbbbbaabbbababbbbbaabaaaaaabbaaa +abbbbbbbabaaabbbabbaaaabaaabababaabaabababbbaaaaabaaaababbababbabbbbabbb +baabbabaababbbaabbababba +bbaabbbaaaabbbbaaabaabaa +baabbabaabbbbbabaaaaabaababbbbaaabaaaaaa +baaabaaabbbababbababaaabaababbaa +aaababbabbaaaaabbaabababbbabaaba +aabbbaabaabbaaababbbaabb +bbbbbbbbbaabababaabaabaa +ababbaaaaabbbbbaaaabbaabbaaabaaabaabbaabbabbbababbbbabbabaaaaaababaaaaba +baaaaabaaaaaababaabbaaaa +aaaaaaaabbabababaaaabbaa +aababaaaababbbaabbbaaaaa +aaaaaaabbbaaabababbbaaab +aaababaaaabbbbababbaaaab +aaababaabaaaabbaabbaabab +bbaabaaaaaabaabbbabaaabbababaaba +ababaaabbaaaabbabbaabaaaabbababbaababaaababaabbbbabbabbb +aaaaaaabaaababbbbbaaaabbbbabaaaabaaabbabbaabbbab +abbabaaaabaaabbabbabbaaaababbbbbbbbaaaaa +abaaaaababbbbbababbbbaba +abaabaaaaabbbbaaaaaabaab +babababaaababaaaabaababa +bbbaaaaabbbbbbaaaabbaabb +aababaaaaaaaabaaabbbbaab +ababaaabababbbaaaaaabbab +baabbbabbbaabbbaabbbaabb +baabbbbaabbbaababbababba +bbbbabaaaaaababbbaababaa +aaaaabbabbbaabbaabaabbbaaabababababbbbba +baabaaabbbaabaabababaabb +aaabaaaaabbabbaabaabaaaa +aaabaabaabbabbabbabaabab +babaabbbbaabbbbbabaaabbabbaabaaabbababbababbbaaaababaabb +baaabaaababbabababbaaabbbaabaaabbaabaaaa +baaabaabbbababbbabbbbbabbabbaaab +abbabaaaaabbbbbababbaaaaaaaaababbabaababaabbbbbb +abbbbbbaabbbbaaababaabaaabbbbabbabbbbababbababbababaaaabbbaaaaba +aaabaabbabbbabaaabbaaaaa +bbbbaaabbbbabaaabaaabbbb +babbbaabbaabbbbbaaaabaaa +aaaaabaabaabaaabaabbaababbaababb +baababbbababbabbbbbbbaabaaaaabbababbbbbabaaaababbbbbbbbbbbaaaaabbabaaaabbababbab +baabaabababaababaaabbaaa +aababbabababaaababbabaaabbababbaabaababa +bbabbbabbabbbaababababba +abbaabbbaababaaaabbbabab +aaababbbabaabbbbbbbbabbb +aabbbbabbaaabaaaabbbaabb +abbbbbaabbbaabababaabaabababbaba +aaababaabbbbaaaababaaabbbaabbabbaaaabbaaababbaaa +bbaaaabaabbabaaaaabbaaabbbbabbab +aaabbababbbbababbbbbaaaababaaaaaababbaababaababbaababbbaaabbaaba +abbaabbbbabaabbbababbaab +baabbbbbbbaaabbbbababbbbbbaaaaaaabbbbbaaabaababa +aabbbbabbbbababbbabaaabbbabbbbbbbaaaabab +baabbbaabbabbbbababbbbaa +babbbbbbabbbbbbbaaabaabbbbbbbbbabbaaabaa +bbbabaaabbbbbaaaaaabbaab +abbbbbababaaabbaaababbbabbaaaaabaaaaabaabaaaaabb +bbabababaabbbaabaaabbbbabaaabbab +aaabbbbabbbbaaabbbbabbbbbbbbabbbaabababb +baaaabbaabbababbbabaaaaa +baababaabbaaaaabbababaabbbababbbababbbbabbabbaabbaaaabbabbaaabbbbbabbabbabbbabab +aaaaaaaaaabbbbababbbbabb +abbaaabbbaaaaaabbababaab +abaabbbbbaabbabaaaabababaabbababaaabbaab +aaaaabaabaababbaabbbbaba +bbbbbaaabbabababbaabbabaabaaaabaaabababb +aaaaabbaabbabaaaabbabbbabbbaaabbbaabaaaabbaaaaaa +aaabaaaaaaaaabbaaabaaabbbaabbbabaaaaabbbbabaaaaa +abaababbaababbbbaaabaaaabbbbbbbaabbaabaa +abaaabaabbbbbbabaabbbabbababaaba +bbabbaaabbaaaaababaaabbaaabbbabbbbbbabbaaabbabba +aaaaaaabbaababababaabbaababbaaaabaaabbab +bbbbbaaaaaababbbbaabbaab +abbaabbbbbaaaabbbbbbaaaabaabbabbaabbbaabbbaabbab +aaaabbbababaababbbbaababaababbaabbbabaababbbaabbbbaabbbaababbbaa +abbabbaaabbbaababbabaaab +aaaaaaababbaaabbbbaababb +baaabbaabaaabbaaabbbabba +babbbaabbbabbaabaabbaabaaabababa +aaaababbabababbbababaaabbbabaababbaababaaaabaabaabbabaaabbbaabaa +aaaaaaabaabbabaaabbabbaaaababbbbabbabaaabaaabaabaaaabbbaaabbbaaa +abbbbbbbbbbbabbabbbbaabb +baaabbbaabaababbaaabbaba +bbbbbbabbabbbabbaabaababbbbaabab +aaaaababbbbbabbbababbaabbbbbbabbaabbbbbbbbaaaaaa +ababaabbbababbbbbbbaaaabaabbbaaa +aaaababbbbbbabbabbaabbaa +aaabaababbbababbbabbabbb +bbababaaabaaabbaaabbaaaa +aaaaababbbaabbaaaaaaaabaabbbababbbbaabab +aabbaabbbabaabaabaaaaaaaabaababbbabbbbbaababbabbababaabaaabbbabbaabaabbaaabbbbba +bbbbaaaabbabababbbaaaaaa +abaaaaabaaaaaaabaabbaaabaaababaaaabaaaaa +babbbaabababaaabababbaab +baaaaaababababbbbaabababbbbbbaabbabaaaabaaaaaabaaababbaa +aabaaabbaababbabbabaabbbaababbabaabbbbaa +ababbbbbabbbaabababbaaba +bbababababbbaaaaabaabbabaaabbabb +bbaabaabaabbbaabbaaaaaabaabbabbbabbbbaab +baabaabbaababbbabbbbbaba +aaaaabababaaaaababababba +abababababbbabbbbababaaa +ababbbaabbabbbbabbbbbbaaabbbbabaabbabbba +babaaaaaaaabbaaabbbaabab +abaaababaaaabaaabaaaaaaabbabbbaaaababababaaaababaaaababbbbabaabbaabbbbba +aaababbbbaaaabbbaaaaaaabbbbabbbaaabbbbaa +babababaaaaababbabaabaab +bbaabbbababbabababaabaababbbbabaabbaaaaababbbbab +abababbbaabbbbababbbaaaaaaabaaab +aabaabaaaaaababaabbaaaabaabaaaaaaaababaa +aabbbaabbbbbabaababbabba +abbbaabaaaaaaaaababbbabbbbaaaababbbbbababbbaaaaa +aaabbbabbbbababbbbaabaabbaaaabab +aabbaababbabbbabbbbbbaba +abbaabbabbbbaaaaabaaaabbbaaababb +aaabababbbbbaaaabbbababb +abbbbbbbaaabaababbababababaabbbaabaabaaa +bbbabababaabbababaabbbbabaababaa +bbbabbabaaaabaaaaabbaaababababababababaaaaaabbbbaaaaabaabbaababb +aabaaabaaaaaaaababbabbbb +aabbabaabaabbabbaaabbbbaaabaabaa +bbaaaabbbbbabaaabababbbaaabaaababababaab +bbbbbbbaaabbbbbaaaaabbab +babaabbbbaaabaaabbbababbbbbaabaaabbbbaba +bbaaaabbbbbbaaaaabababaaaaabbaaabbbaabba +bbabbbababaabbbbaabaaabaaaabbaaa +baabaabbabaababbbbaabaabbaabbabbabbbbababbaaabbb +babbbabaabbbaababababbab +aabaaabbabaaaaabbbaaaabbaaabbaba +aaaaabaaabaabbbbaabbbbbb +aaaabbbabbababaabaabbbaabbbbbababababababbbaaabbaaabbabaaababbba +abaaaabbabbbbbabbbabbbababbaababbbaaabba +abababbbbaabbbbbbabbbbbbabbbbbabaaaababbababaabb +abaaabbabbababbbabaababbbaabbbbababbbaabbbaabbaa +babbbbbbbaabababbbababaaabbabbaabaabbabbaabbbaaa +aaababbababaaaabbbbaaaaa +babaaabbaabbbbbaaaaababa +aaabaaaaaabbaababaabbabababbaaaabbaabbaa +abaabbabbbaababaabbbaabababbabaabbaaaababbababaaabbbabbb +bbbbababbbaabaabbabaaabbaababbaaabaaabbb +baabbbabaaaaaaabbaabbaab +bbbaaabaaaababbbababaabbbbbbbaabbbbababb +babbaaaababbabbaabababbbababbbabaaababaa +aaabababaabbabaabbbabaaababbbbab +bbbbababbbabbbababbababbbaababaababaabba +bbbababababbbbbbabbbaaaaabaabbba +aabaaabbabbbbbaaabaababaabaaabab +bbabbabaabaaaaaababbbbaa +abaabaabaaaaabaabbbbbabababbabbbaabaabaa +bbabbbaababbbabbaabbaaabbabbabaabaaabaaababaabaabbbabbababbbbabbbabbabbabbaabbbb +aaaaabaababbababababbbbbaababbabbbabababbbbbabbb +abaaabbabbabbbaaaabababb +abbbbbababaaaaabbabaaaaa +bbbabbabaaabbaabbaaaabaababbaaab +bbbbbbbbabaabbaaaabbbaaa +baaabbbaaababbbbabbbabbbabaabaabaababaab +aaaababbbbaabbbaaaaababbbabbabba +bbabbbaaababaaabbbbbbbbabbaabaababbabbba +aaabababbabbbabaaabbabaaaaabbaba +aabaabbbbaabbbabaaabbbbabbbbabbb +bbbbbbabababaaababaabbbbaabbaaaabababbbb +abaaaabbaaabaabbbbaaababaaabbaabaabbbbbb +baabbababbbaaabaababbbba +baaabbbabababbbaabbaabab +babababaaaabaaaabbbbabbb +babbababaaabbbbabbbaabaabaabbbbbaaabbbab +baabbaabbababbababbaaaaa +bbababbbaaaaaaaabaabbbbaaaaabaaa +abbbaabbbbbbbbaabbabbbabbbbbabaaababaaab +bbaabbbababaabbbbabaaaba +baaababababaabbbbbabbaba +abababbbaababbbbabbabaabbaabbbaaabbbaabaabbbbaaa +bbaaaaaaaaabababbaabababaababbbbbbbbabaaaaabbabbbbbbbbaabaaaaabbbababbaaaaababaa +baaaaabaaaaaaaaaabbabbba +baabbbbaabaabbabbaaabbbb +abbabbabaabbabaaaabbabab +abaabbbbbaaaaababbabaaba +bbbbbaaabbaabbbaabaaabbaabaaaaabbaabababaabbabbbbabbaabb +babbbabaabaaabbaabbbbbaa +bbabbaabbabbabaabbaaaabaaaabbaab +aaaababaaabaaaaabbabbabaababaabaaabbabbb +abbaaabbbbababaabaaaabaa +baabbbbabaabaabbbaabbaab +baababbabbbabaabaaabaabbbaaabaaabbbbbaba +bbbababbaabbbabbbbbbbbaa +bbbbbbabbbabbabbabbaabbbaaabaaab +bbbababbababaaababaaabbabaababbb +baabaabbaabbabaabbbaaaab +bbaaaababbabababaaabaaaaaaabaabaabbbbaba +bbabbaaabbbbbaaabbbaabab +ababaaababbabababbaababb +aabaaaababbabbabbabbbbaa +aaaabaaabbaabbabababaaaaabbbabbb +abbbabaabbabbbaaaabaaababbabbabbbbaabaababaaabbb +bbaaaabbaabbaaabaaaaaaabaaabbbbaaabbaabaaababaaabbaaabaa +babbbabbaaabababbbabaaab +abbabbabbaabbababbabbbbaaaaabbbabbababba +abbaababbbaabbababbbabbaaabbbbbaaaabababaabababbbbaabbbaabbabaabbbbbabbaabaaaaab +babbbabaababbbabbbbabbba +baaabaabaaaaaaabbabaabba +baabaabbbaabaaabbbabbaaabaaaaaabbbbbaabb +bbababbbabaaaabbbababaaa +baababbaaaabbbbaabbababbaabbaabaabaabbbabbabaaab +bbbbbbaaabbbababbaababbbbaaabbaabbaababb +bbabbaaabaabbbaababbaabb +ababbbababbbbbbbababbabb +babababababaaaaaaaaababababbaaabbabaabab +abaaabaaabbaabbbbabbaaba +aaaababbbabbbbbbbbbaabba +babbbabaaababaaabaaababb +ababbbabbbabbabbbbababaaaaabbbaa +aaaaabbbaabbaababbbbbbbbbaaaabbbaaaaabaabbbbaabaaababbaabababbabbabbabbb +abbabaabbbabbbaaaaabaaaabbbbbaaa +bbbbabbaaabaabbbaabababb +bbbabbaabbbaabaaabaaabaabaaaaaabaabbbbaa +bbbababbbabaaaabaaabbaba +abbababbabaababbbaabbabaaaabaabbaaaabaaabbabbbbbababababbbbaabba +aaabaaaaaababbbaabbaabab +abaabbaabaaabababaaabbbababbbbab +aaaaabbbbbababbbbabaaaaa +aabaaabaaababaaaabaabaaa +aabaabababbbaaaabaabbaaa +babaabaababaabbbbbababbbaaababbaabbabaabbabbbbabbaabaaba +aabaaabaaaabaaaabbaabbbb +bbbbaabaabaaabaaaababbbabaabbaab +bbabababbbabbbbaabbbbaab +baabababbaabbbbbbaaabbbabbbabbbbbabaabbababbaaabaabababa +abbbabbbabbabbabbaaaabaabbbbbaaaabaabababaababaaaaabababaababbba +baabbabbbaabbbbaabaabbabaababbaa +abaababbaaaaabbbaabbbaabaaababbbbbaaababaaaaababbabbaabb +bbbabbbbababababaaabaaabbaabbabaabbabbbbaababaaaabbbabbbbbbabbbbaaaaababbaaaaaaa +aababbabaabababaaababbabbaaaaaaabbbbbbaabbaaabbbbbbaabbb +ababbbabaaabaababbbaaabb +abbbbbbaabbbbbbbbbababba +bbabbbbabbabbbaaabbabaababbbaaaaaabbaaaa +bbaabaababbbbbbbabaabaab +aaaaabbabbbbabbabaabbbbbbabbabaaababbabbaabbaaaa +abbaabbabbbbbbbbabababba +abababbbabbababbabbabbaabbbbaabb +baaabaaaaaaaabbabaaababb +abaabbbbbabaaaabbaaaabaa +bbaabaaabbaabaaaabbbbbaa +baabaaabbbbbbbbabbababaaabbaaaab +bbaaabababbaaabbaabaaabbaabaabbabaaaabaa +aababbbbbbabbabbbbabbbbaaabababb +abbbabaabbaaaaabaaabbaaa +abbbaaaabaaabaaaaaaaaaaabbaabbab +aaabaaaabbbbbbbaabbababbbabbbabaabbabbaabbbbaaaabbbaabbb +aabbaaabbbabbabbbbbaabaaaaaaaabaabbbaabb +babbbbbbaabbabaabaaaabab +aaaaabbbaaaaabbaaababbbaabababab +baabaabbbbbbbbbabbaabaaababaabab +aababbbbaaaabbaababaaaaabaabbbabbbababaaaabaaabbaaaabaabababbbabbabaabbabaabaaaa +aababaaaabbbababbbaabaabbbbababbbbaaabababababba +bbbbbbabbabbababaaaaabaabaabbbaabbaaabababbaaaab +abbaabbbaabbbbabbbabbaba +bbaababaabaabbbbbabababb +aabaabbbbbbbbbbababbababbbbbababbabbaaab +bbabbaabaabbaabababaaaabbabbaaaaabaaabab +babbaaaabbabbabbabbaabab +bbbababbabbababbbabbaabb +aaababbabaaaaaababbbabba +babaabaabaaababaaabaaabaaaabbabb From 22e59128fb2b728554792efae4135e624591ba2a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 19 Dec 2020 11:00:31 +0100 Subject: [PATCH 101/129] 2020: d19: ex1: add solution --- 2020/d19/ex1/ex1.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 2020/d19/ex1/ex1.py diff --git a/2020/d19/ex1/ex1.py b/2020/d19/ex1/ex1.py new file mode 100755 index 0000000..2741dfd --- /dev/null +++ b/2020/d19/ex1/ex1.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +import itertools +import re +import sys +from typing import Dict, List + + +def parse_rule(raw_rules: List[str]) -> str: + parsed: Dict[int, str] = {} + rules = {int(num): rule.strip() for num, rule in (i.split(":") for i in raw_rules)} + + for n, r in rules.items(): + if '"' not in r: + continue + parsed[n] = r.replace('"', "") + + while 0 not in parsed: + for num in parsed: + if num not in rules: + continue + rules.pop(num) + + for num, r in rules.items(): + nums = list(reversed(sorted(map(int, re.findall("(\\d+)", r))))) + if all(n in parsed for n in nums): + for n in nums: + r = re.sub(str(n), parsed[n], r) # Bigger numbers replaced first + r = r.replace(" ", "") + parsed[num] = "(" + r + ")" + return parsed[0] + + +def solve(raw: List[str]) -> int: + pattern = re.compile(parse_rule(list(itertools.takewhile(len, raw)))) + + return sum( + pattern.fullmatch(line) is not None for line in itertools.dropwhile(len, raw) + ) + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main() From ab15ce121f0de469b8503fb48c7561644f12574d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 19 Dec 2020 11:00:51 +0100 Subject: [PATCH 102/129] 2020: d19: ex2: add input --- 2020/d19/ex2/input | 561 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 561 insertions(+) create mode 100644 2020/d19/ex2/input diff --git a/2020/d19/ex2/input b/2020/d19/ex2/input new file mode 100644 index 0000000..6242e89 --- /dev/null +++ b/2020/d19/ex2/input @@ -0,0 +1,561 @@ +102: 100 47 | 76 84 +23: 60 47 | 73 84 +132: 17 47 | 81 84 +108: 55 100 +18: 116 47 | 26 84 +103: 84 115 | 47 81 +65: 84 113 | 47 50 +128: 107 47 | 125 84 +14: 84 100 | 47 107 +118: 47 17 | 84 57 +2: 47 100 | 84 40 +28: 63 84 | 74 47 +22: 102 84 | 123 47 +123: 84 74 +19: 3 47 | 13 84 +24: 74 47 | 81 84 +115: 55 55 +90: 92 47 | 44 84 +48: 84 94 | 47 96 +109: 17 84 | 100 47 +92: 84 75 | 47 108 +66: 38 47 | 125 84 +83: 66 47 | 108 84 +31: 121 84 | 77 47 +29: 47 61 | 84 111 +45: 47 47 | 47 84 +59: 47 49 | 84 43 +37: 47 30 | 84 95 +36: 107 84 | 125 47 +82: 74 84 | 38 47 +61: 84 10 | 47 110 +79: 47 28 | 84 109 +33: 101 47 | 133 84 +12: 45 47 | 63 84 +91: 122 84 | 93 47 +122: 65 47 | 52 84 +21: 57 84 | 115 47 +8: 42 +67: 102 47 | 64 84 +39: 113 84 | 81 47 +41: 84 124 | 47 10 +50: 47 47 | 84 84 +17: 47 84 | 84 84 +120: 98 84 | 78 47 +113: 55 47 | 47 84 +20: 84 128 | 47 104 +7: 84 1 | 47 20 +51: 84 113 | 47 81 +56: 84 83 | 47 69 +131: 84 127 | 47 97 +0: 8 11 +5: 47 63 | 84 125 +94: 15 84 | 127 47 +121: 99 47 | 27 84 +119: 47 115 | 84 57 +129: 47 80 | 84 131 +15: 47 100 | 84 45 +35: 84 50 | 47 76 +95: 47 115 | 84 107 +68: 127 84 | 51 47 +124: 84 107 +75: 50 55 +57: 47 84 | 84 55 +13: 47 33 | 84 129 +53: 106 47 | 59 84 +106: 16 84 | 118 47 +89: 84 125 | 47 45 +104: 45 84 | 76 47 +99: 47 56 | 84 7 +78: 84 74 | 47 81 +64: 17 47 | 115 84 +32: 50 84 | 40 47 +1: 47 24 | 84 72 +47: "a" +80: 114 47 | 109 84 +88: 47 119 | 84 132 +105: 47 125 | 84 100 +6: 68 84 | 67 47 +110: 76 84 | 63 47 +38: 84 84 | 84 47 +49: 47 63 | 84 76 +26: 55 107 +81: 47 84 +74: 84 47 +96: 84 89 | 47 117 +77: 47 86 | 84 71 +135: 32 84 | 2 47 +133: 47 15 | 84 128 +42: 19 84 | 62 47 +30: 47 100 | 84 74 +27: 6 47 | 91 84 +63: 84 55 | 47 47 +62: 84 87 | 47 23 +76: 84 84 +4: 84 135 | 47 54 +60: 41 47 | 37 84 +100: 47 47 | 84 47 +85: 47 112 | 84 18 +116: 125 84 | 63 47 +134: 57 47 | 115 84 +34: 52 47 | 25 84 +40: 47 47 +111: 58 84 | 126 47 +3: 29 47 | 130 84 +114: 17 84 | 107 47 +52: 47 45 | 84 74 +10: 47 100 | 84 81 +98: 47 76 | 84 100 +112: 84 82 | 47 103 +72: 40 47 | 45 84 +126: 50 84 | 113 47 +107: 84 47 | 47 84 +11: 42 31 +55: 84 | 47 +54: 12 84 | 5 47 +130: 34 47 | 70 84 +84: "b" +127: 81 47 | 17 84 +87: 84 53 | 47 9 +101: 105 84 | 14 47 +9: 88 84 | 120 47 +73: 47 79 | 84 22 +97: 74 84 | 50 47 +117: 74 47 +70: 47 134 | 84 46 +58: 47 50 | 84 115 +125: 47 47 | 55 84 +46: 47 81 | 84 17 +86: 84 90 | 47 85 +25: 38 84 | 63 47 +69: 39 47 | 78 84 +43: 47 100 | 84 125 +93: 84 66 | 47 35 +44: 47 21 | 84 36 +16: 57 47 | 107 84 +71: 48 84 | 4 47 + +babaaabbbababababbbbabbaabbaabaa +babaaaabaaaaababbbbaaaaa +abbabaabbaaabababaabbbbabbbbbaabbbbabababaaaabbbbababbbb +bbbabababbabbbabbbabbbbb +babaabbbababbbabaabaaaaa +abbabaabbaababbabababbbababbbabbabbabbbabbaabbbb +aaaaabaabbbbbaabbbbbbbbbbaaabbaaabbaabab +baababbabbbabbaaaaaababbaabbababbbabbbbb +aaabaaaabbabbbabbabaabbbabaabbbbaaaaabaaaabaabaaababaabbabbaaaabbbbaabbabbabaaaaaaaabaab +ababaaabababbbababaaabab +bbbbabbbbbaabaaaaaabbbbbbabbbabaabbaaababbbaaaaababaabaabaabababbabbbabbabaaabbaaabbaaaa +babaabaaababaaabaaaababa +aabaaabbaabbbabbabaabaab +bbbaabaaaabaaabbbaaabbbabbbaaabb +aaaaaaabaaababbbbbbbbbbbbaaabaabbaaabbab +bbabbabbaaaaabababaababa +babbababbbabbaababaababbaaaaabaaabbbabba +bbbbbbbababbaaaaabaaabbaabbaaaab +bbbbbaaabbbbbaaaaaabaaaabbbaaabb +babbababaababbbbbbbaaabb +abaabbaabbababaabbababba +abaaabbaaabaabbbabababba +babaaaabaaaababbabbbbaaa +bbbbbbbabaababbaaaaababbabbaabbabbbaabaababaabbbbbbaabab +aaabbabbbaabababbaabaaba +bbbababbabaabbabbbabaaaa +baabbabababaaaabbbbbbaab +bbabbbbabaababbabbbaabab +abaabbabbbabbabbabbbabba +bbbbbbbaaababaaabbaabbbabbaaabbbbabababb +aabbaaabbabbabaaaabbabaababbbaababaabababaaabbaa +aaabaababbbabbbbaaababbbbaaabbbb +aaaaaaaaaaabaaaababbabbb +bbbabbbbaabaababaabbabab +baaabaabbaaaabbbbaaaaaaa +bbbbbbbaabbabbaabaabaaaa +aaaaabaabbabbaaaaaaaaabb +aabaaabbaabbabaaabbabaabbaababaaabbbaaaaababbaabaaabbaaabbaaabaa +bababbbaaabaababbbababaabbaabaabbaaaabbabbaabababbbabbbababbabbb +abbbaababbaabaaaaababbbaaaabbbaa +aababbbaaaabaabbbbabaaaa +aaaaabbaaabaaabbbababaaa +bbbababaaabaaaabbabbabaabbababababababbbabbaaaaabbababbabbbbabbbabbbaabb +bbbabababbbabababababbbb +bbaaababbbabbbbaabbbbbaa +bbababaabaaaabbaabbbbaaa +bbbbabbababbbbaabbaaaababbababbaabaaabababbabbabbbbbbaababbbbabbbbaaaaabbbaabbba +abbabbabbbbbbaabaaaaabababaaaaabaaabbaaaabababba +bbbabaabaababaaabaabbaaa +bbababbbbaaababaaaabbabbaaabbbaa +aabbbbababaabbaabababbaa +aaabbabbbaabbbabbbbbbbbabaaaabbaaabababaabaaabab +aaaaaaababbabbabbabaaaaa +aababaaaaaababbbabbabbabaaababbbbbabbababababaaaabbabbbb +babaabbbbaaabaaabbbabbab +bbbbabbbbaabbbabbbaabbbaabbbbbaabbbbaaabbbbaabbbbaababbaaaabaaaabbabbabbabbaabbb +aaabbbabbaaabaabbaaaaabaabababab +abbababbabbbbbabbaabbbabaaababbbbbbbabaababbbbbabababbbb +bbaabbbaaaaababaaabaaaabbbbbbaabbaaaabbaabaaabaabaaaabbabbabbbaabbaaaaaa +abbabbaaaabaaaabbbbbbaabbabaababbbbabbba +bbaaaabaabbababbbbaabbaa +aabbaabaabbaaabbaaabaaaaaaababbabababbaa +baaaabbaaaaaabbbbabbababbaabbbbabbabbabbaabbaabb +babbaaaabbaabaaabbbbaaaabbbabbaaaaaaaabb +aaaaababaaabbabbababbabb +abbabaaaaaabaababbabaaab +aaabaababbaabbbaababbabb +babbabaabaababbabbabaabb +abbabbaabbabbbabababaaaa +bbabbbaaaababaaaaaabbbaa +bbbbbbbaaaaaabbabbbaabaaaaabbaaa +bbbaabaababaaabbaababbabaababaabbbababba +bbaaabbaabaabbbbbbbaababbbaabaabaaabaababaaaaabbbaaabaababaaaaabaabbbbaabaabbbaa +baabbababbaaaaababaabbabaabbbaabaabbaabbabbbaaababbaaaab +bbabaaaaaaaabababaabbababbaabbbbabbbaaababbaababaabaaaaaaaabaabb +baaaaaabbaababbaababaaaa +bbbabbbbbbaabaabbaaabbab +babbbabababaaaabaabbaaabbbabaabababbbaaabaababbbbbaababbbabbbabb +aabaaababababababaabbbababbababbbabbaabb +bbaabaaabbaabababbaababaabbabbba +bbbabaaaababaabbaabbabbbbabbaabaabbabaabbaabaabaabbaabbabaaabaaa +abbaaabbbbbbbbbbaaabbaab +baabbbbbaabbaabbaabbababbaabaaba +baaaabaaabbbbaabaabbabbbbaababbb +abbbbbbaabbbbbbbbbbbbaaaaaaabaaa +abbbbbbbbbabbbaabbbaaabaaabababa +aababbbaabbabaabbabaaaba +bbabbaabbabbabaaababbbba +aaabbbabbaabaabbbbbabbbbaaaaabbbbabbbabababbbaaa +aaabaabbaabaababaabababb +bbababaaabbbaabaabbababa +baabbbaaaaababababaabbaababbabbb +babbbaabbaaaabbaababbabb +bbababbbababbbaabbabbbabaabababaaabaaaaa +babbbbbbbbabbbababbbbaab +abaabbbbbabbbbbbaaabbaba +bbabbbaabbbbbaaabbbaaaaa +abbbbbbbbaabbbaaabbbbbbabaaaabaaaaaabbbb +aabaaabababbbbbbaaabbaab +bbbabababbbbbbabbbbbaabaabababbaaabbbbbb +aababbbaaaaaaaaaabbaaaaa +ababaababaababbbabbbbabaaabbabaaabbabbaabbaaaaaababaabba +aabbaaabaabbbaabaabaabbbaaabaaab +aabbaaabaaaaabaaaaabbbabaaabaaaababaaaaaabbbbbaaaababbaa +babbbaabaabaaabababbabaababbbaabbabaabbaabababbababaaaaa +aabbbbabababbbaaaaabaabbbaabbabaaaabababaabaaaabaaaababaabbbabbaabaaabbb +bbbbbbababbbabaababbabaabababababaababbabbbbbbbabbaaabbb +bbabababaaababbabbababba +abbbbbbabbbbbbaaabbbaabbbbabaabaaaaaaabb +aaaaabbbbaaaabbabbbabbab +aabbaaabbbbaaaabbabababbbabbaabbbbababbbbaaabbbababaabbbaabaaaaababbbaaa +ababbbabbbabbbaaababbbbbaabbabbaababbaaa +abbabbababbababbbbbbabbb +aabbaabaabbabbabbaabbaab +baabbbaaabbababbabbaaaba +baaabbbaaabbbabbbaaaaaaa +bbaaababaaaaabaabaaaabba +aabaaabbbbabbaabaaababaabbbbaabb +bbbbabbaaaabbabbaabbabab +aabaaaabbaaaaabababbabba +bababbbabaabaabbaaaabaab +ababaaabbbaabaabbbaabaaababaabbbabaabbaaaabbbaaabbbaabab +aababaaabbbbaaaaaaabbbbb +abaabbaabbbbbaaaaaaabaaa +babbbabababbaaaabaaaabab +abbbbbabbabbaaaababbaabb +bbaaaaabbbbababaaaaabaab +bbaababaaaabaabbabaabaab +bbababbaabbbbabbbaaaaabbabababba +bbabbaabbbbbabbaabababbbaabbbbbabaabbaaabbbabbbabaabbaab +abbabbaabbaaaaabbbabbbaabbbabaaabbaaabbbaaabaaab +aaababbababbabaabaabbbababbabbabbbaababaabbbabbaabaababa +baabbaabbbabbababbaaaaaabaaabbab +aabbabaabbbbbbbbbaabaaababaaaaaa +abbaabbabaaaaabaabbbabaabaaabaabaabaabbbaabaabaaaabaaaaa +baaaabbabaababbababbbababababbbb +bbabbaabbaaabbbabaaabaababbbbbbabbaaabaa +baabbbbaabbbbbbabaabbaab +baaaabbaabbababbaababbababaaaabbbbbbbabababaaaba +baabbbbbaabaabbbbbabbaaaabbaabbaabbbbbabbbbbbaba +babaabbbbbaabaaaabaababbabbbbabbbbbaaaaa +baabbababbaababaabbbaaab +bbaaaabbbaaaaaabbbabababbaabbabbbaaabbaaababaabb +abbbbbbaaababaaababbaaba +baabbabababababaaaaaababbababbbabaabbbaaabaaabab +aaaaababaabaabababbbbbbbabbbaaba +bababaaabbbaabbabaaaaabb +aabbaababbabbbbabbbaaaab +bbbbbbbbaabbbabbbabbbbba +aabaababbaabaabbbbaaaaababaaaaabbaaaaaaa +aaaaaaaaaaaaabababbbbbbabbbaabab +bbbaabaaababbbaaaabaaababbababbbabaaabbaabaaaaaa +ababbabbbbbbaabbaaabbaaabbaaabbaaaabbbba +baabababbbbbabaaababbbaabbaaababbbbaaaababbabbbb +bbaabbbaabaaabaaababaabb +bbabbbaaabbaabbbaaaabbaa +bbbabaabaaaaabaaaababaaaabaaabaaaaaaabbaabbaabbabbbbbaba +baaaabbaabbbaabaabbabbaabbbaaabaaabbbbbaaaaabaab +bbabbabbbbbbbaabbbababbbbbaabaaaaaabbaaa +abbbbbbbabaaabbbabbaaaabaaabababaabaabababbbaaaaabaaaababbababbabbbbabbb +baabbabaababbbaabbababba +bbaabbbaaaabbbbaaabaabaa +baabbabaabbbbbabaaaaabaababbbbaaabaaaaaa +baaabaaabbbababbababaaabaababbaa +aaababbabbaaaaabbaabababbbabaaba +aabbbaabaabbaaababbbaabb +bbbbbbbbbaabababaabaabaa +ababbaaaaabbbbbaaaabbaabbaaabaaabaabbaabbabbbababbbbabbabaaaaaababaaaaba +baaaaabaaaaaababaabbaaaa +aaaaaaaabbabababaaaabbaa +aababaaaababbbaabbbaaaaa +aaaaaaabbbaaabababbbaaab +aaababaaaabbbbababbaaaab +aaababaabaaaabbaabbaabab +bbaabaaaaaabaabbbabaaabbababaaba +ababaaabbaaaabbabbaabaaaabbababbaababaaababaabbbbabbabbb +aaaaaaabaaababbbbbaaaabbbbabaaaabaaabbabbaabbbab +abbabaaaabaaabbabbabbaaaababbbbbbbbaaaaa +abaaaaababbbbbababbbbaba +abaabaaaaabbbbaaaaaabaab +babababaaababaaaabaababa +bbbaaaaabbbbbbaaaabbaabb +aababaaaaaaaabaaabbbbaab +ababaaabababbbaaaaaabbab +baabbbabbbaabbbaabbbaabb +baabbbbaabbbaababbababba +bbbbabaaaaaababbbaababaa +aaaaabbabbbaabbaabaabbbaaabababababbbbba +baabaaabbbaabaabababaabb +aaabaaaaabbabbaabaabaaaa +aaabaabaabbabbabbabaabab +babaabbbbaabbbbbabaaabbabbaabaaabbababbababbbaaaababaabb +baaabaaababbabababbaaabbbaabaaabbaabaaaa +baaabaabbbababbbabbbbbabbabbaaab +abbabaaaaabbbbbababbaaaaaaaaababbabaababaabbbbbb +abbbbbbaabbbbaaababaabaaabbbbabbabbbbababbababbababaaaabbbaaaaba +aaabaabbabbbabaaabbaaaaa +bbbbaaabbbbabaaabaaabbbb +babbbaabbaabbbbbaaaabaaa +aaaaabaabaabaaabaabbaababbaababb +baababbbababbabbbbbbbaabaaaaabbababbbbbabaaaababbbbbbbbbbbaaaaabbabaaaabbababbab +baabaabababaababaaabbaaa +aababbabababaaababbabaaabbababbaabaababa +bbabbbabbabbbaababababba +abbaabbbaababaaaabbbabab +aaababbbabaabbbbbbbbabbb +aabbbbabbaaabaaaabbbaabb +abbbbbaabbbaabababaabaabababbaba +aaababaabbbbaaaababaaabbbaabbabbaaaabbaaababbaaa +bbaaaabaabbabaaaaabbaaabbbbabbab +aaabbababbbbababbbbbaaaababaaaaaababbaababaababbaababbbaaabbaaba +abbaabbbbabaabbbababbaab +baabbbbbbbaaabbbbababbbbbbaaaaaaabbbbbaaabaababa +aabbbbabbbbababbbabaaabbbabbbbbbbaaaabab +baabbbaabbabbbbababbbbaa +babbbbbbabbbbbbbaaabaabbbbbbbbbabbaaabaa +bbbabaaabbbbbaaaaaabbaab +abbbbbababaaabbaaababbbabbaaaaabaaaaabaabaaaaabb +bbabababaabbbaabaaabbbbabaaabbab +aaabbbbabbbbaaabbbbabbbbbbbbabbbaabababb +baaaabbaabbababbbabaaaaa +baababaabbaaaaabbababaabbbababbbababbbbabbabbaabbaaaabbabbaaabbbbbabbabbabbbabab +aaaaaaaaaabbbbababbbbabb +abbaaabbbaaaaaabbababaab +abaabbbbbaabbabaaaabababaabbababaaabbaab +aaaaabaabaababbaabbbbaba +bbbbbaaabbabababbaabbabaabaaaabaaabababb +aaaaabbaabbabaaaabbabbbabbbaaabbbaabaaaabbaaaaaa +aaabaaaaaaaaabbaaabaaabbbaabbbabaaaaabbbbabaaaaa +abaababbaababbbbaaabaaaabbbbbbbaabbaabaa +abaaabaabbbbbbabaabbbabbababaaba +bbabbaaabbaaaaababaaabbaaabbbabbbbbbabbaaabbabba +aaaaaaabbaababababaabbaababbaaaabaaabbab +bbbbbaaaaaababbbbaabbaab +abbaabbbbbaaaabbbbbbaaaabaabbabbaabbbaabbbaabbab +aaaabbbababaababbbbaababaababbaabbbabaababbbaabbbbaabbbaababbbaa +abbabbaaabbbaababbabaaab +aaaaaaababbaaabbbbaababb +baaabbaabaaabbaaabbbabba +babbbaabbbabbaabaabbaabaaabababa +aaaababbabababbbababaaabbbabaababbaababaaaabaabaabbabaaabbbaabaa +aaaaaaabaabbabaaabbabbaaaababbbbabbabaaabaaabaabaaaabbbaaabbbaaa +abbbbbbbbbbbabbabbbbaabb +baaabbbaabaababbaaabbaba +bbbbbbabbabbbabbaabaababbbbaabab +aaaaababbbbbabbbababbaabbbbbbabbaabbbbbbbbaaaaaa +ababaabbbababbbbbbbaaaabaabbbaaa +aaaababbbbbbabbabbaabbaa +aaabaababbbababbbabbabbb +bbababaaabaaabbaaabbaaaa +aaaaababbbaabbaaaaaaaabaabbbababbbbaabab +aabbaabbbabaabaabaaaaaaaabaababbbabbbbbaababbabbababaabaaabbbabbaabaabbaaabbbbba +bbbbaaaabbabababbbaaaaaa +abaaaaabaaaaaaabaabbaaabaaababaaaabaaaaa +babbbaabababaaabababbaab +baaaaaababababbbbaabababbbbbbaabbabaaaabaaaaaabaaababbaa +aabaaabbaababbabbabaabbbaababbabaabbbbaa +ababbbbbabbbaabababbaaba +bbababababbbaaaaabaabbabaaabbabb +bbaabaabaabbbaabbaaaaaabaabbabbbabbbbaab +baabaabbaababbbabbbbbaba +aaaaabababaaaaababababba +abababababbbabbbbababaaa +ababbbaabbabbbbabbbbbbaaabbbbabaabbabbba +babaaaaaaaabbaaabbbaabab +abaaababaaaabaaabaaaaaaabbabbbaaaababababaaaababaaaababbbbabaabbaabbbbba +aaababbbbaaaabbbaaaaaaabbbbabbbaaabbbbaa +babababaaaaababbabaabaab +bbaabbbababbabababaabaababbbbabaabbaaaaababbbbab +abababbbaabbbbababbbaaaaaaabaaab +aabaabaaaaaababaabbaaaabaabaaaaaaaababaa +aabbbaabbbbbabaababbabba +abbbaabaaaaaaaaababbbabbbbaaaababbbbbababbbaaaaa +aaabbbabbbbababbbbaabaabbaaaabab +aabbaababbabbbabbbbbbaba +abbaabbabbbbaaaaabaaaabbbaaababb +aaabababbbbbaaaabbbababb +abbbbbbbaaabaababbababababaabbbaabaabaaa +bbbabababaabbababaabbbbabaababaa +bbbabbabaaaabaaaaabbaaababababababababaaaaaabbbbaaaaabaabbaababb +aabaaabaaaaaaaababbabbbb +aabbabaabaabbabbaaabbbbaaabaabaa +bbaaaabbbbbabaaabababbbaaabaaababababaab +bbbbbbbaaabbbbbaaaaabbab +babaabbbbaaabaaabbbababbbbbaabaaabbbbaba +bbaaaabbbbbbaaaaabababaaaaabbaaabbbaabba +bbabbbababaabbbbaabaaabaaaabbaaa +baabaabbabaababbbbaabaabbaabbabbabbbbababbaaabbb +babbbabaabbbaababababbab +aabaaabbabaaaaabbbaaaabbaaabbaba +aaaaabaaabaabbbbaabbbbbb +aaaabbbabbababaabaabbbaabbbbbababababababbbaaabbaaabbabaaababbba +abaaaabbabbbbbabbbabbbababbaababbbaaabba +abababbbbaabbbbbbabbbbbbabbbbbabaaaababbababaabb +abaaabbabbababbbabaababbbaabbbbababbbaabbbaabbaa +babbbbbbbaabababbbababaaabbabbaabaabbabbaabbbaaa +aaababbababaaaabbbbaaaaa +babaaabbaabbbbbaaaaababa +aaabaaaaaabbaababaabbabababbaaaabbaabbaa +abaabbabbbaababaabbbaabababbabaabbaaaababbababaaabbbabbb +bbbbababbbaabaabbabaaabbaababbaaabaaabbb +baabbbabaaaaaaabbaabbaab +bbbaaabaaaababbbababaabbbbbbbaabbbbababb +babbaaaababbabbaabababbbababbbabaaababaa +aaabababaabbabaabbbabaaababbbbab +bbbbababbbabbbababbababbbaababaababaabba +bbbababababbbbbbabbbaaaaabaabbba +aabaaabbabbbbbaaabaababaabaaabab +bbabbabaabaaaaaababbbbaa +abaabaabaaaaabaabbbbbabababbabbbaabaabaa +bbabbbaababbbabbaabbaaabbabbabaabaaabaaababaabaabbbabbababbbbabbbabbabbabbaabbbb +aaaaabaababbababababbbbbaababbabbbabababbbbbabbb +abaaabbabbabbbaaaabababb +abbbbbababaaaaabbabaaaaa +bbbabbabaaabbaabbaaaabaababbaaab +bbbbbbbbabaabbaaaabbbaaa +baaabbbaaababbbbabbbabbbabaabaabaababaab +aaaababbbbaabbbaaaaababbbabbabba +bbabbbaaababaaabbbbbbbbabbaabaababbabbba +aaabababbabbbabaaabbabaaaaabbaba +aabaabbbbaabbbabaaabbbbabbbbabbb +bbbbbbabababaaababaabbbbaabbaaaabababbbb +abaaaabbaaabaabbbbaaababaaabbaabaabbbbbb +baabbababbbaaabaababbbba +baaabbbabababbbaabbaabab +babababaaaabaaaabbbbabbb +babbababaaabbbbabbbaabaabaabbbbbaaabbbab +baabbaabbababbababbaaaaa +bbababbbaaaaaaaabaabbbbaaaaabaaa +abbbaabbbbbbbbaabbabbbabbbbbabaaababaaab +bbaabbbababaabbbbabaaaba +baaababababaabbbbbabbaba +abababbbaababbbbabbabaabbaabbbaaabbbaabaabbbbaaa +bbaaaaaaaaabababbaabababaababbbbbbbbabaaaaabbabbbbbbbbaabaaaaabbbababbaaaaababaa +baaaaabaaaaaaaaaabbabbba +baabbbbaabaabbabbaaabbbb +abbabbabaabbabaaaabbabab +abaabbbbbaaaaababbabaaba +bbbbbaaabbaabbbaabaaabbaabaaaaabbaabababaabbabbbbabbaabb +babbbabaabaaabbaabbbbbaa +bbabbaabbabbabaabbaaaabaaaabbaab +aaaababaaabaaaaabbabbabaababaabaaabbabbb +abbaaabbbbababaabaaaabaa +baabbbbabaabaabbbaabbaab +baababbabbbabaabaaabaabbbaaabaaabbbbbaba +bbbababbaabbbabbbbbbbbaa +bbbbbbabbbabbabbabbaabbbaaabaaab +bbbababbababaaababaaabbabaababbb +baabaabbaabbabaabbbaaaab +bbaaaababbabababaaabaaaaaaabaabaabbbbaba +bbabbaaabbbbbaaabbbaabab +ababaaababbabababbaababb +aabaaaababbabbabbabbbbaa +aaaabaaabbaabbabababaaaaabbbabbb +abbbabaabbabbbaaaabaaababbabbabbbbaabaababaaabbb +bbaaaabbaabbaaabaaaaaaabaaabbbbaaabbaabaaababaaabbaaabaa +babbbabbaaabababbbabaaab +abbabbabbaabbababbabbbbaaaaabbbabbababba +abbaababbbaabbababbbabbaaabbbbbaaaabababaabababbbbaabbbaabbabaabbbbbabbaabaaaaab +babbbabaababbbabbbbabbba +baaabaabaaaaaaabbabaabba +baabaabbbaabaaabbbabbaaabaaaaaabbbbbaabb +bbababbbabaaaabbbababaaa +baababbaaaabbbbaabbababbaabbaabaabaabbbabbabaaab +bbbbbbaaabbbababbaababbbbaaabbaabbaababb +bbabbaaabaabbbaababbaabb +ababbbababbbbbbbababbabb +babababababaaaaaaaaababababbaaabbabaabab +abaaabaaabbaabbbbabbaaba +aaaababbbabbbbbbbbbaabba +babbbabaaababaaabaaababb +ababbbabbbabbabbbbababaaaaabbbaa +aaaaabbbaabbaababbbbbbbbbaaaabbbaaaaabaabbbbaabaaababbaabababbabbabbabbb +abbabaabbbabbbaaaaabaaaabbbbbaaa +bbbbabbaaabaabbbaabababb +bbbabbaabbbaabaaabaaabaabaaaaaabaabbbbaa +bbbababbbabaaaabaaabbaba +abbababbabaababbbaabbabaaaabaabbaaaabaaabbabbbbbababababbbbaabba +aaabaaaaaababbbaabbaabab +abaabbaabaaabababaaabbbababbbbab +aaaaabbbbbababbbbabaaaaa +aabaaabaaababaaaabaabaaa +aabaabababbbaaaabaabbaaa +babaabaababaabbbbbababbbaaababbaabbabaabbabbbbabbaabaaba +aabaaabaaaabaaaabbaabbbb +bbbbaabaabaaabaaaababbbabaabbaab +bbabababbbabbbbaabbbbaab +baabababbaabbbbbbaaabbbabbbabbbbbabaabbababbaaabaabababa +abbbabbbabbabbabbaaaabaabbbbbaaaabaabababaababaaaaabababaababbba +baabbabbbaabbbbaabaabbabaababbaa +abaababbaaaaabbbaabbbaabaaababbbbbaaababaaaaababbabbaabb +bbbabbbbababababaaabaaabbaabbabaabbabbbbaababaaaabbbabbbbbbabbbbaaaaababbaaaaaaa +aababbabaabababaaababbabbaaaaaaabbbbbbaabbaaabbbbbbaabbb +ababbbabaaabaababbbaaabb +abbbbbbaabbbbbbbbbababba +bbabbbbabbabbbaaabbabaababbbaaaaaabbaaaa +bbaabaababbbbbbbabaabaab +aaaaabbabbbbabbabaabbbbbbabbabaaababbabbaabbaaaa +abbaabbabbbbbbbbabababba +abababbbabbababbabbabbaabbbbaabb +baaabaaaaaaaabbabaaababb +abaabbbbbabaaaabbaaaabaa +bbaabaaabbaabaaaabbbbbaa +baabaaabbbbbbbbabbababaaabbaaaab +bbaaabababbaaabbaabaaabbaabaabbabaaaabaa +aababbbbbbabbabbbbabbbbaaabababb +abbbabaabbaaaaabaaabbaaa +abbbaaaabaaabaaaaaaaaaaabbaabbab +aaabaaaabbbbbbbaabbababbbabbbabaabbabbaabbbbaaaabbbaabbb +aabbaaabbbabbabbbbbaabaaaaaaaabaabbbaabb +babbbbbbaabbabaabaaaabab +aaaaabbbaaaaabbaaababbbaabababab +baabaabbbbbbbbbabbaabaaababaabab +aababbbbaaaabbaababaaaaabaabbbabbbababaaaabaaabbaaaabaabababbbabbabaabbabaabaaaa +aababaaaabbbababbbaabaabbbbababbbbaaabababababba +bbbbbbabbabbababaaaaabaabaabbbaabbaaabababbaaaab +abbaabbbaabbbbabbbabbaba +bbaababaabaabbbbbabababb +aabaabbbbbbbbbbababbababbbbbababbabbaaab +bbabbaabaabbaabababaaaabbabbaaaaabaaabab +babbaaaabbabbabbabbaabab +bbbababbabbababbbabbaabb +aaababbabaaaaaababbbabba +babaabaabaaababaaabaaabaaaabbabb From df664d9fca79149ca8d5d9c66cff10290a353040 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 19 Dec 2020 11:00:56 +0100 Subject: [PATCH 103/129] 2020: d19: ex2: add solution --- 2020/d19/ex2/ex2.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 2020/d19/ex2/ex2.py diff --git a/2020/d19/ex2/ex2.py b/2020/d19/ex2/ex2.py new file mode 100755 index 0000000..b036fa8 --- /dev/null +++ b/2020/d19/ex2/ex2.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import itertools +import re +import sys +from typing import Dict, List + + +def parse_rule(raw_rules: List[str]) -> str: + parsed: Dict[int, str] = {} + rules = {int(num): rule.strip() for num, rule in (i.split(":") for i in raw_rules)} + + for n, r in rules.items(): + if '"' not in r: + continue + parsed[n] = r.replace('"', "") + + while 0 not in parsed: + for num in parsed: + if num not in rules: + continue + rules.pop(num) + + for num, r in rules.items(): + nums = list(reversed(sorted(map(int, re.findall("(\\d+)", r))))) + if all(n in parsed for n in nums): + for n in nums: + r = re.sub(str(n), parsed[n], r) # Bigger numbers replaced first + r = r.replace(" ", "{x}" if num == 11 else "") + if num == 11: + r = "(" + r + "{x})" + r = "(" + r + ")" + if num == 8: + r = "(" + r + "+)" + parsed[num] = r + return parsed[0] + + +def solve(raw: List[str]) -> int: + pattern = parse_rule(list(itertools.takewhile(len, raw))) + + def matches(repeats: int) -> int: + pat = re.compile(pattern.replace("x", str(repeats))) + return sum( + pat.fullmatch(line) is not None for line in itertools.dropwhile(len, raw) + ) + + return sum(itertools.takewhile(bool, map(matches, itertools.count(1)))) + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main() From 96980ecb19a1ea9182a988cf119c4f2616e2636f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 20 Dec 2020 14:26:25 +0100 Subject: [PATCH 104/129] 2020: d20: ex1: add input --- 2020/d20/ex1/input | 1728 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1728 insertions(+) create mode 100644 2020/d20/ex1/input diff --git a/2020/d20/ex1/input b/2020/d20/ex1/input new file mode 100644 index 0000000..3d3540f --- /dev/null +++ b/2020/d20/ex1/input @@ -0,0 +1,1728 @@ +Tile 1913: +##..#....# +.#.#.#.### +#...##.##. +.....#.#.# +.#......## +.........# +#...###..# +.#..#..... +.##...#..# +#.#...#... + +Tile 2579: +##...####. +##..#....# +...#...#.# +#.....###. +##..#...## +#....#..#. +.#.....### +.##...#... +#......... +...##..... + +Tile 1531: +.......### +.#....#### +.#.#.#...# +....#..#.# +.#.#.##..# +.#.#.#...# +#.##...### +##..#..... +#...#..... +##.##.#..# + +Tile 1493: +#.##.#.#.. +#.#..#.##. +..#.....#. +#.#.#....# +....#....# +...#####.. +#####.#.#. +#.##..##.. +..#.....## +.##..#.### + +Tile 3109: +########.# +......#.## +#....#...# +##.#.##... +....#.#... +#####...## +....#....# +..##...### +.......#.# +#.##.#.... + +Tile 3343: +###......# +#..#.#..## +...#....#. +#......... +..#.....## +.....##### +.....####. +##.......# +..#....... +#.......## + +Tile 2609: +####..#.## +#.#..#.... +....###..# +###..#..#. +#.#......# +##..#..#.. +#....#..#. +#......### +#..#....## +.#..#.###. + +Tile 1823: +###..#.... +..###...#. +..#.###... +...#.....# +#....#.#.# +.#..#.#..# +#..##.#..# +...##..... +....#.#.#. +###.##...# + +Tile 3391: +....#...#. +.#.#....#. +#......#.. +#..#....#. +#.##...#.# +...##.#### +....##..#. +##.#.#..## +.....#..## +#.#.#..#.# + +Tile 2753: +....###..# +.#..##.#.# +...#...... +..#.###.## +...#..##.. +....#..... +#......#.. +#........# +......#..# +#..#.#...# + +Tile 3989: +.#.###.#.. +#......##. +.##......# +.......### +###....### +##........ +##....#.#. +...#.#..#. +........#. +###..#..#. + +Tile 1877: +...###...# +#.#..##... +.##.###.#. +#.#....#.. +#..#.#.##. +#.......## +####..#.#. +##.#....## +.##....... +.#..##..## + +Tile 2729: +#...####.# +...#.....# +.###...... +...#..#..# +...#.#.#.# +.#.....##. +..#.....## +........#. +###....... +#..##...## + +Tile 1031: +##.#..#### +#.##.#.... +..#....... +#......### +.##.###.## +#...#...#. +#..##..... +#..#.#.#.. +....###... +....#.###. + +Tile 3803: +#..#..##.. +...##..#.. +...#.#.... +#.....#..# +#........# +.#..#.#.## +..#..#.#.. +#..#.#.#.. +..##..#.#. +#####.###. + +Tile 3541: +.##.#..#.. +.##..#...# +.#.#..#... +...#..##.# +..#.....#. +..##...... +.##......# +##.......# +.#..#.##.# +###.#.##.# + +Tile 3821: +.#.#.#.... +..#..##... +#.##...... +..#...#.## +#.####..#. +##.##.#... +..#..#.... +....#....# +...###.#.# +.#..#.#.## + +Tile 3853: +#####..#.# +.....#..## +#...#.##.# +.##....#.# +#.#......# +###...#.#. +##....#.## +#.#.#.#..# +....###... +##.#.#.... + +Tile 1249: +###...#### +..#....#.. +##.##....# +.........# +#......... +.##.#.##.. +...#...##. +.......... +##...#.#.. +##.####..# + +Tile 3673: +...##..#.# +.#..#..#.# +###......# +#.....###. +..#.#..... +#.#..#.### +.#.##.##.. +.##....#.. +.#...##..# +#.###..#.# + +Tile 3163: +##.#.##### +.##....#.. +####...... +#..#.#..## +.#.#..##.# +##.....#.# +.......#.. +#...#..... +..#..#.... +###.#...#. + +Tile 1759: +###.#...## +...#..#... +###..###.. +.#.#...#.# +.##...#... +..###....# +#.#.....#. +......###. +..#.####.# +##..##..#. + +Tile 1831: +.#...#...# +...#.#..## +#...#.#... +#...##.#.. +.#.#.#..#. +......##.# +.........# +#....##.#. +......#..# +#..#...##. + +Tile 2179: +.###.....# +..######.# +....#....# +...#....#. +#.##..#... +#..#....## +.#..#.#..# +..#.#....# +#.#.#..... +###.##...# + +Tile 2713: +..###.#..# +#.#.....#. +#....#.#.. +#...##.... +##...#.#.# +###..###.# +.##..#..## +.#...##.#. +#.#....... +#...#..... + +Tile 1889: +....#....# +......#.#. +##.###...# +.#..##...# +##.##.#..# +...#...##. +#....#...# +.......#.. +.#...#..## +.#.####.## + +Tile 1999: +##....##.# +#..#.##.## +..#...#... +#.....#... +......#... +#.....#..# +.#.##..#.# +..#..##..# +#...#..#.. +###..##..# + +Tile 2039: +.#....#### +.##..#.... +.#.......# +#........# +#.......#. +.#..#..... +#.##...... +##....#..# +.........# +#.#......# + +Tile 2969: +...#####.. +..#.#...## +##.....#.. +##.....### +#...#..### +#..#....## +#..##...## +.........# +#...##...# +.#......## + +Tile 2153: +.##..###.. +#.#..#..## +.#####.... +#.#..#.### +#.....#.## +####..#.#. +.......... +.#......#. +...##...#. +.#....#### + +Tile 2837: +..###..... +###.#.###. +.#....#... +##.....### +##.##..### +..#..##.## +.#....##.. +#..##.##.. +#..#...... +#..##...#. + +Tile 1619: +##..###.## +##....#### +.#..##.#.. +##.#...#.. +#..##.##.. +...#.#.#.# +.....#.##. +..##..#..# +#..#..#..# +......#.#. + +Tile 3943: +.#.##.#.#. +.......#.# +.........# +...#..#..# +...#....## +#.#.##.... +##.......# +.#..#.##.# +...##.#..# +#.##....#. + +Tile 3389: +#...#.##.. +#.##..#... +#.#.#..... +##...#...# +##.....#.. +.#..###..# +..###..... +#.##..#.## +####....## +##.#.##### + +Tile 3631: +##.###.### +#...#..... +..#....... +#....#.### +#......... +#.#....... +....##...# +........#. +#....#.... +.....#.#.. + +Tile 2081: +##..##.#.. +.##......# +........## +#.......## +......##.# +#....#.... +.#.#...##. +....##..#. +#.#..##### +...#####.. + +Tile 1579: +##........ +.....#...# +#......#.. +#..#.#...# +...#..#... +#.##....## +...#...... +.#...#..#. +..#....#.# +.##...#... + +Tile 3019: +.##..####. +...#....## +...##.#.#. +#....#.... +.........# +##..#..#.# +...#.#...# +.#.##.#.## +##..#..... +#..#..###. + +Tile 2089: +##.##.#... +..#.##...# +##...#.... +#........# +#..#.....# +..######.# +.......#.. +...#..##.. +#.#....#.. +...#.##### + +Tile 2297: +#.#.###... +#.##...... +#..#..#... +......#..# +#....#...# +###.#..##. +#....##.## +.......#.# +.........# +.###.#.#.. + +Tile 1373: +#..#.####. +........#. +....#....# +.##..#...# +.#.....#.# +#.....#... +#..#..#..# +.##...##.# +##.......# +.##..#.#.. + +Tile 1259: +...#..##.# +....#.#..# +#..#.##.## +##..##.... +#..#.#..## +#.#...#... +..#......# +...###.#.# +.......... +.###..##.. + +Tile 2411: +.###..#.#. +.#..#..#.. +#.....#..# +.#.....#.. +##..#...#. +.#........ +#...##.... +#.#..##... +.....#.#.# +....#.##.. + +Tile 3359: +.##..##.## +..#.#..#.# +#.......#. +.#..###..# +.#.....#.. +#......... +...#.....# +.##....#.. +.........# +.#.##..#.. + +Tile 2437: +.#.....#.. +#.#....... +....##.#.. +##.###.##. +##.#....#. +#...#....# +##..##..## +...#..#..# +....##.#.# +.##.#.#... + +Tile 1367: +....#####. +..#.#....# +##......#. +..##...##. +..##..##.# +..##.##..# +#.#......# +##...#...# +.....#.#.. +##.###.### + +Tile 3533: +##..####.. +##..#....# +...#.....# +#.##..#### +###..##... +....###..# +..#.....## +.##.#..#.. +....#.##.. +##.#.##.## + +Tile 1451: +.####.#... +..##.#.#.. +...#.#.... +.........# +....#...## +##...##... +..#...#... +#...#.#### +...#.#.### +#######... + +Tile 3457: +#.##.###.# +#..#.#.... +###.#....# +.#....#.## +.......##. +#...####.# +#.#####..# +#.#..#..#. +#.#....... +.#.##..... + +Tile 2657: +..#####..# +......###. +#.....#..# +.#..###..# +...#.##... +#.....#..# +#....##### +....#..#.. +#.#.###..# +.#..##.#.. + +Tile 2347: +#.##.#.### +#...#....# +.......... +#.#.#..... +#....#.... +#..#...### +#.##...#.. +#.....#..# +#.#.###.#. +#...###.## + +Tile 3923: +#.####...# +###...#.## +......#..# +..#..#..## +#....#.#.# +.........# +.....#.#.# +#..####..# +....##.#.. +#..#...#.. + +Tile 2593: +####...#.. +#...####.# +#......##. +..#..#.... +#..#.....# +...#...... +....#..... +#.#...##.# +.......#.# +#.#####.#. + +Tile 1103: +..##...#.# +..#.....#. +#....#...# +...##....# +#.#.....## +.#.#.#.#.. +#....##### +.#.#.##### +.........# +.##...#.#. + +Tile 2671: +.##.##.#.# +...#.#.... +##....#... +#......#.. +.#....#.## +........## +..#...###. +###...#... +....#.#..# +.#######.# + +Tile 3907: +###....#.. +..##.....# +.......... +##...#..## +##..#..##. +##..##..#. +#.#.....## +..###..#.# +#..#..#..# +#.#....... + +Tile 1327: +.#..#..#.# +.###.###.. +..#..#.... +.#...#.#.. +#.##.....# +#..#.#..#. +###...#... +##..#..#.# +......#... +#.#...###. + +Tile 1163: +..#.#...#. +####.#.#.. +.##.....## +#...#..... +.....####. +#...#..### +...#.##.#. +##..#..#.. +.....#.#.# +.###...#.# + +Tile 2683: +.......#.. +.#.#.##..# +##..#...## +...#...... +##.##...#. +...#.#.### +.#.##..... +#..#....#. +.###..#... +.#.#.....# + +Tile 3881: +#.#.#..##. +##.#...### +##......## +#......... +#..#...... +...#.#...# +.#..##.... +.....##.#. +##...#.... +###.....#. + +Tile 2711: +#...#.#.## +#..##..... +...#...... +#.#.#....# +#...#.#... +...#...... +.#.#...... +..#....#.# +#.##..#... +#.#.#..... + +Tile 3491: +.###..#.## +.....#.... +.##..#..## +##.##..#.# +.###....## +..##..#..# +..#......# +..#..#...# +#...#.#..# +.......##. + +Tile 2339: +###.#####. +.#....#... +##.#.....# +#......... +#......... +..##..##.# +.###...... +#...##.... +##........ +#.....#..# + +Tile 1543: +..##...#.. +.....#..## +....##.... +.........# +.#..#.#..# +.......... +.........# +#.#.#..... +##.#.#.... +#.#.###..# + +Tile 2371: +#..#.##### +##.#..###. +#.#...##.. +#...###.## +#...#..#.# +##.....### +.#.......# +.....#.#.. +..#.#.#### +.###..##.. + +Tile 2971: +..###.#... +#......... +##.#...### +....###... +###......# +..###....# +##.#.....# +.#.....#.. +#.....#### +..##.##.#. + +Tile 2203: +#.###.#.## +.#...##.#. +#.#.....#. +..#.#....# +##..#....# +##..#..... +#..#..#... +##........ +..#..#.#.. +##....#..# + +Tile 2113: +###...##.# +......#... +.....##.#. +....####.# +##..#..#.. +#...#...## +.......#.# +......#..# +#.##.#..## +....##.#.. + +Tile 1321: +.#..#..#.. +##...#...# +.......... +.####..#.# +##.#.#.#.# +#..#.#.... +#..#.....# +.#.......# +....###.#. +##.#.##.## + +Tile 1667: +.#####...# +##....#..# +#..#.#.... +..##..#... +#..##...## +...#...... +..#..#...# +.....#...# +#..#...#.# +##..#.##.. + +Tile 3001: +.#.####### +...#.#...# +..##...#.# +#......... +....#..... +#.....##.# +.....####. +#......... +...#.##.## +##.##..### + +Tile 1789: +..###.#..# +...##...#. +........#. +####...#.# +#..#..#... +##.##..##. +....#..... +#.#.#..... +#.#..#...# +######.#.. + +Tile 3677: +.#...#.### +#..##...## +#..#...#.# +##........ +..#....### +.......... +##..#.##.# +.#........ +......##.. +.##.##...# + +Tile 2693: +#.#.###.#. +#.#..#..#. +.#....#... +#..#...#.# +.#.##..##. +.##......# +...#.....# +##...#.### +.#.#.....# +########.. + +Tile 2141: +#####..... +#......... +#...#....# +....#..... +.......#.. +##..#.#..# +#....#..#. +..#....#.. +.....##.#. +##..#.#.#. + +Tile 3847: +#...###### +#..#.##..# +..#...##.# +##..#.#..# +##..#..#.# +##.##....# +#........# +#....#.#.. +#......... +#......#.. + +Tile 2333: +#.#..##.#. +####.....# +###..#...# +.........# +...##.#..# +###....... +..##...#.# +...###...# +.###.#...# +##..#.##.. + +Tile 2129: +#..###.### +....#....# +#.#.#..#.# +....#....# +#...#.#..# +..##.##... +#.##....#. +#...#.#... +.#..##...# +...###.##. + +Tile 1283: +.#..#.###. +###.#.##.# +#..#..#.#. +.....#...# +.#.#.#.... +#...#..#.# +.#.#..#.## +.#..##..#. +#....##.#. +.#..#...#. + +Tile 2851: +.##.#..... +###......# +.#........ +....#.#..# +.#..#..#.. +.##....#.. +.##...#.## +#.###.##.# +##........ +.#.#.#.#.# + +Tile 2311: +#..##....# +.#......#. +....#...## +....#...#. +.#...#...# +#...#....# +.....#.#.# +.....##..# +##..##.### +##..###.#. + +Tile 3217: +#.##....## +#.......#. +#.#....#.# +..##.###.. +....##...# +#......... +...#.#...# +..##....## +..#......# +##.###..## + +Tile 2833: +####..#..# +#...##.#.# +........## +..##..#... +.......#.. +......#... +###..#..#. +.##..#...# +##.#....#. +.####..... + +Tile 3593: +#..#####.. +.##.#....# +...#..#..# +##.#...##. +#######... +...#..#... +#.##..#.#. +#........# +#...##..## +........## + +Tile 3299: +...#.#..#. +#.#......# +##......## +.#..#..#.. +#.#####... +#...#....# +#.#....... +..#....#.# +.#........ +#.#.#.##.. + +Tile 2719: +...#..#.#. +#..#.###.. +......#.## +....#.#..# +#.#......# +....#..... +##..#.#... +...##..... +###.#....# +..####..## + +Tile 2161: +..#.##..## +#........# +...#.#...# +...###.... +......#..# +..##.##.#. +.#....#.## +#...#####. +#....#...# +.#....#... + +Tile 3643: +...#...##. +##......## +....#.###. +.#.#..#### +..#.#...## +.##.#.#.#. +#.#..#..#. +#..#.#..#. +.#........ +.#.###.... + +Tile 3767: +.##.#....# +#...#...## +.#...##..# +.#.#...... +..#..#..## +#..#.#.##. +#.....#.## +....##...# +.....#.##. +..#..###.. + +Tile 2377: +.#####.#.# +..#.....## +#...#...#. +##....##.. +....#..#.. +#.##..#..# +.#...#.##. +...##...#. +#....#.... +..#.#..### + +Tile 2441: +....#.###. +.#..#....# +.#.###.... +#...#..... +#.#.##.... +....##.... +....##...# +...#..##.. +#...###.## +.##.#.#.#. + +Tile 2273: +...#..#.#. +#..#...### +..#....#.. +...###.#.. +.........# +..##.#..## +###.#....# +#..#.....# +....#...#. +.##..##### + +Tile 1231: +....#####. +#.....#.#. +..#....#.# +.###..##.# +#..#....## +#..#.#.#.. +..#.###... +##........ +..#.....## +##.##..#.# + +Tile 2879: +#####.###. +#..#..#..# +...#..#..# +#......... +.#.#.#...# +...#..#..# +#.#..#.### +#.....#### +.......#.# +..##.##### + +Tile 2473: +.##.###..# +....##.#.# +#..#..#..# +..#.#.#... +#..##..... +.##....#.. +....##..## +...#.....# +....#..... +.#####.#.. + +Tile 3329: +#.#..###.. +......###. +.###..##.. +...#.##... +#..#.#.### +#.###..##. +##..##...# +..#####..# +.#...#.... +#.##.#..#. + +Tile 1489: +....#....# +#.##.....# +..#......# +..#...#..# +.#....#..# +#..##...#. +..####.##. +.#..##..## +..#.....#. +##.#.##..# + +Tile 3259: +..####.### +##.##..#.# +.#..#..### +#.#....... +.....#.#.. +##...#.#.. +.....#...# +.#....#... +..#.#....# +######.... + +Tile 1123: +....#.#.#. +...##..... +...##....# +#.##....## +..#...#..# +.#..#..... +.#......## +.........# +.....#...# +.##.###... + +Tile 1381: +.###..#.## +#..##..#.. +#.....#..# +#..#..#..# +#....#.#.# +.......#.# +#...#.#..# +##..###..# +..#..##... +..##.#..#. + +Tile 2903: +#.###.###. +#..###..#. +##.......# +.#....#... +#..#..##.# +...#...#.# +#.#...##.# +......#..# +##.#..#..# +##.#..##.# + +Tile 1049: +#....#.### +####.....# +#.##....#. +.#....##.. +.##..#..## +#.#.#..#.# +.##...#..# +...#..#.## +.....#..## +..#.#.###. + +Tile 3137: +...#.#.#.# +#.#....#.. +..###...#. +..#..##..# +.#.#.##.#. +#.#..##..# +#.....#... +##...##.## +#.#...#... +.##.#..... + +Tile 2131: +.#......## +...#...##. +.#.#.#.#.# +.......... +...#....#. +#.#.#..#.# +..#.#....# +....##.... +....##..#. +##.##..#.. + +Tile 3733: +.#.#....## +.#..#....# +..###.#..# +.....#...# +...#.....# +###..#.... +#...#.#### +......#... +..#..#.... +.#####.#.. + +Tile 1973: +.#.#.##... +#.....#..# +#......#.. +...#...#.# +..#..#...# +####.#.... +....#..#.# +.#.....#.# +....#..#.# +..#..#.#.. + +Tile 3889: +#.##.#...# +#....##..# +.###..#.## +..#...###. +#....##... +#.##...... +#.#..#..#. +...#.#...# +........## +##.#..#.#. + +Tile 1129: +#...###### +#...#.##.# +###.....#. +#.#..#..#. +.#....#... +..#...#..# +#....#.### +......#.#. +#.#..##.## +.###..#..# + +Tile 1549: +.#..##.#.. +#.#....### +...#..#... +##....#... +..##...#.# +#.#....### +..#.##.##. +.....#...# +#.##.....# +#..#.##... + +Tile 2213: +#...#.#.## +#........# +...##...## +.#..##.#.# +#..##....# +...##...## +##........ +....#....# +...#.#.#.# +..#.###..# + +Tile 1597: +..###..#.. +#......#.. +.......#.# +#.#....### +#.###..#.# +##.#.##... +#.##.#..## +.#.#..##.. +.##..#...# +##...##### + +Tile 1777: +#..#....#. +.........# +..#.....#. +..#......# +.##....#.. +#...#...#. +.#..#..... +#.....#..# +.#..##...# +#.#...#... + +Tile 2503: +#..###.#.. +.#..##.#.. +....##.... +..#..#.... +#....#.#.. +#.#....#.# +...#.#.... +..##.#.... +#.#.#....# +#.######.. + +Tile 3499: +.####...## +.#.##..#.. +#........# +..#......# +##..#...#. +#...##.... +#......#.. +.#.#....## +...#..#... +.##.#...#. + +Tile 1811: +#.###...## +..##...#.. +..#.#..### +##.#....#. +.#...#.... +##.......# +#....#...# +...##.##.. +...#.....# +.####..#.. + +Tile 3793: +###.####.. +##...###.# +...#.###.. +#....#.... +.....#.... +...#.....# +###.####.. +#.##.##.## +......#... +#.#.###... + +Tile 2341: +.##..#.### +.#........ +..####..#. +.#..####.# +#....#...# +......##.# +#.....#... +.......... +#..###.... +####.##### + +Tile 3613: +..#.#.#.#. +#....###.. +#......#.. +#.#...#.## +#..#.....# +##.#.#.#.. +...####..# +##...###.# +#.#.#....# +#..####... + +Tile 3701: +..##.####. +#.##...### +.###.#.... +#..#.....# +##........ +###..#.### +..#...#.#. +.##...#..# +##.......# +###.#...## + +Tile 1483: +#####..##. +....#..#.# +...#####.# +#.##...#.. +........#. +........## +##..##.### +.###....## +...###..#. +...#.#..#. + +Tile 3571: +#.#.##.##. +#......##. +#...#.#... +.#.#....#. +#.#....#.. +#.#...#... +##.....#.# +##.#.#...# +#....#...# +#.#..#..## + +Tile 2521: +##.##..#.# +......#..# +.#.#.#.##. +#........# +.#.##....# +.#....#.#. +##......#. +#....#.... +.#..#...#. +.#..#..### + +Tile 3413: +.##.##..#. +#...#..#.. +##....#..# +.......... +#..#...#.. +##..#....# +....#.#... +#.....#... +......#.## +..##.##.#. + +Tile 1933: +#..#....## +#...#..### +.#......## +......#..# +.......... +##.##..### +.......### +...#...### +.#....#..# +#.#..#.#.# + +Tile 1021: +.#..##.#.# +##....#... +.#........ +.#.#....## +.#......## +##........ +.....#..#. +#....#.#.# +#......... +..#.#.##.# + +Tile 3323: +...###.#.. +.#..####.. +....#..... +#.....##.# +###......# +..######## +.#....##.# +....##.##. +#..##....# +#.##.#..#. + +Tile 1607: +....####.. +##.#...#.# +.......#.# +#......... +..#..####. +..#..#.##. +.###.#...# +##...#.... +#.######.. +##.#.#.### + +Tile 1481: +.###...#.. +.#......## +.....#...# +...#...##. +#.###.##.. +#......### +#......... +###...###. +.#....##.. +#....###.# + +Tile 1879: +###.##.... +#.#.....## +#.#..#.#.# +.#...#..## +......#### +#.###..... +......###. +#..#.#..## +..#......# +.#..#..... + +Tile 2927: +###..##.#. +#..#....#. +##..#..... +#.#...#### +#......... +..###...## +#.####...# +#.##.##..# +...#...... +#....#.##. + +Tile 1867: +..#..####. +##.##..#.# +.##......# +###..#.... +..#......# +#..##..#.# +#......... +...#..#..# +#......#.. +.#....#.#. + +Tile 2647: +#####.##.# +...#...#.. +#.......## +...#..#..# +..#.###... +...##..... +..#......# +.##....... +#...#..... +##...##.#. + +Tile 2207: +#.#####.#. +#..#.#..## +...##....# +..#..#.#.# +#...###..# +.##.#...## +#..##..### +#......... +###.#..#.# +.#....##.# + +Tile 1223: +###.....#. +#.....#.## +##.##.#... +#...##...# +#....#.... +..#.##.... +##....##.. +..#..#.... +.#.##..#.. +###.#.#### + +Tile 1931: +##.#...### +#...##.... +#..#....#. +..##..#... +#...#..... +.........# +###.##.... +...##.#..# +.#.#.....# +..#..##.## + +Tile 3917: +.##.#..#.. +.......##. +#.##....## +...#....## +###....#.# +.##.#...## +###....... +##.....#.. +....###.## +....#...#. + +Tile 1663: +#.#.....## +.#.##.#..# +....#...#. +#...##...# +#..#...... +.#..#.#..# +..#..#..## +...#...... +#...##.... +.##.###### + +Tile 3373: +#..###.### +##...#.#.. +#..#..#..# +.#....##.# +..###..##. +...#.#...# +#.....#..# +##..#..... +.#..#.#... +.#...###.# + +Tile 1319: +.#.#.#.#.# +.....#..## +..#.#.#.#. +.#.##...#. +..##...... +...#...... +.#........ +#..#.....# +#..##....# +.#.##.#..# + +Tile 2687: +#...###.#. +##.#...##. +#...#...## +#..##....# +......#.#. +.###.#.#.. +##...#..## +......#..# +.......... +#.....##.# + +Tile 2003: +.######... +.##...###. +....#..... +#.###.#.#. +......#..# +..##.#.#.# +#.##..#.#. +####.#.... +#...#.#.## +......##.# + +Tile 1453: +###.#.#### +...###..#. +.#..#..### +..#......# +#.#..#..## +..#..#.#.. +#.#...#.#. +..##..#.#. +#..###.... +..#..#..## + +Tile 1871: +..#..##### +##..#....# +##.......# +#..#..#..# +#.....#.#. +#..###.... +.......... +.#........ +.#.##.##.# +#.#..#.### + +Tile 3709: +.##.#.##.. +.#..##...# +.##....... +..##.#.... +.........# +....#..... +###.#.##.. +.#####.... +#####.#... +..#..##### + From cd747e69e65a6fe1d2f77c1b4e97c5c442e74dfb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 20 Dec 2020 14:26:48 +0100 Subject: [PATCH 105/129] 2020: d20: ex1: add solution --- 2020/d20/ex1/ex1.py | 128 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100755 2020/d20/ex1/ex1.py diff --git a/2020/d20/ex1/ex1.py b/2020/d20/ex1/ex1.py new file mode 100755 index 0000000..f8171f8 --- /dev/null +++ b/2020/d20/ex1/ex1.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python + +import functools +import itertools +import math +import sys +from collections import defaultdict +from copy import deepcopy +from typing import Dict, Iterator, List, Set, Tuple + +Tile = List[List[str]] +Tiles = Dict[int, Tile] + + +def parse(raw: str) -> Tiles: + def parse_tile(raw: List[str]) -> Tile: + return [[line[i] for i in range(len(line))] for line in raw] + + res = {} + for lines in map(lambda s: s.splitlines(), raw.split("\n\n")): + if len(lines) == 0: + continue + nums = int(lines[0][5:-1]) + res[nums] = parse_tile(lines[1:]) + return res + + +def rotations(tile: Tile) -> Iterator[Tile]: + yield tile + for __ in range(3): + prev = deepcopy(tile) + for i in range(len(tile)): + for j in range(len(tile[i])): + prev[i][j] = tile[len(tile) - j - 1][i] + tile = prev + yield tile + + +def flips(tile: Tile) -> Iterator[Tile]: + yield tile + yield tile[::-1] + yield [line[::-1] for line in tile] + yield [line[::-1] for line in tile[::-1]] + + +def transforms(tile: Tile) -> List[Tile]: + # Can't use a set with lists... + res: List[Tile] = functools.reduce( + lambda l, it: l + [it] if not any(it == other for other in l) else l, + itertools.chain.from_iterable(map(rotations, flips(tile))), + [], + ) + return res + + +def borders(tile: Tile) -> Iterator[str]: + # They should match on same axis (i.e: go clockwise and counter-clockwise) + return map( + lambda s: "".join(s), + [ + tile[0], + [line[-1] for line in tile], + tile[-1], + [line[0] for line in tile], + ], + ) + + +Transforms = Dict[int, List[Tile]] +Tiling = List[List[Tuple[int, int]]] # Which tile, and which transform + + +def build_tiling(tiles: Tiles) -> Tuple[Transforms, Tiling]: + transform_mapping = {num: transforms(tile) for num, tile in tiles.items()} + trans_borders: Dict[int, Dict[int, List[str]]] = defaultdict(dict) + for num, trans in transform_mapping.items(): + for i, t in enumerate(trans): + trans_borders[num][i] = list(borders(t)) + length = math.isqrt(len(tiles)) + tiling = [[(-1, -1)] * length for __ in range(length)] + + def rec(x: int = 0, y: int = 0, used: Set[int] = set()) -> bool: + if x == length: + return True + for num, borders in trans_borders.items(): + if num in used: + continue + used |= {num} + + for trans, border in borders.items(): + top, __, __, left = border + if y > 0: + nid, ntrans = tiling[x][y - 1] + __, right, __, __ = trans_borders[nid][ntrans] + if left != right: + continue + if x > 0: + nid, ntrans = tiling[x - 1][y] + __, __, bottom, __ = trans_borders[nid][ntrans] + if top != bottom: + continue + tiling[x][y] = num, trans + + next_x, next_y = (x, y + 1) if y < (length - 1) else (x + 1, 0) + if rec(next_x, next_y, used): + return True + + used -= {num} + + tiling[x][y] = (-1, -1) + return False + + assert rec() + return transform_mapping, tiling + + +def solve(tiles: Tiles) -> int: + transforms, tiling = build_tiling(tiles) + return tiling[0][0][0] * tiling[0][-1][0] * tiling[-1][0][0] * tiling[-1][-1][0] + + +def main() -> None: + input = parse(sys.stdin.read()) + print(solve(input)) + + +if __name__ == "__main__": + main() From 150bebc4923fc5bdb308f5c7629953fc78e88073 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 20 Dec 2020 14:26:57 +0100 Subject: [PATCH 106/129] 2020: d20: ex2: add input --- 2020/d20/ex2/input | 1728 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1728 insertions(+) create mode 100644 2020/d20/ex2/input diff --git a/2020/d20/ex2/input b/2020/d20/ex2/input new file mode 100644 index 0000000..3d3540f --- /dev/null +++ b/2020/d20/ex2/input @@ -0,0 +1,1728 @@ +Tile 1913: +##..#....# +.#.#.#.### +#...##.##. +.....#.#.# +.#......## +.........# +#...###..# +.#..#..... +.##...#..# +#.#...#... + +Tile 2579: +##...####. +##..#....# +...#...#.# +#.....###. +##..#...## +#....#..#. +.#.....### +.##...#... +#......... +...##..... + +Tile 1531: +.......### +.#....#### +.#.#.#...# +....#..#.# +.#.#.##..# +.#.#.#...# +#.##...### +##..#..... +#...#..... +##.##.#..# + +Tile 1493: +#.##.#.#.. +#.#..#.##. +..#.....#. +#.#.#....# +....#....# +...#####.. +#####.#.#. +#.##..##.. +..#.....## +.##..#.### + +Tile 3109: +########.# +......#.## +#....#...# +##.#.##... +....#.#... +#####...## +....#....# +..##...### +.......#.# +#.##.#.... + +Tile 3343: +###......# +#..#.#..## +...#....#. +#......... +..#.....## +.....##### +.....####. +##.......# +..#....... +#.......## + +Tile 2609: +####..#.## +#.#..#.... +....###..# +###..#..#. +#.#......# +##..#..#.. +#....#..#. +#......### +#..#....## +.#..#.###. + +Tile 1823: +###..#.... +..###...#. +..#.###... +...#.....# +#....#.#.# +.#..#.#..# +#..##.#..# +...##..... +....#.#.#. +###.##...# + +Tile 3391: +....#...#. +.#.#....#. +#......#.. +#..#....#. +#.##...#.# +...##.#### +....##..#. +##.#.#..## +.....#..## +#.#.#..#.# + +Tile 2753: +....###..# +.#..##.#.# +...#...... +..#.###.## +...#..##.. +....#..... +#......#.. +#........# +......#..# +#..#.#...# + +Tile 3989: +.#.###.#.. +#......##. +.##......# +.......### +###....### +##........ +##....#.#. +...#.#..#. +........#. +###..#..#. + +Tile 1877: +...###...# +#.#..##... +.##.###.#. +#.#....#.. +#..#.#.##. +#.......## +####..#.#. +##.#....## +.##....... +.#..##..## + +Tile 2729: +#...####.# +...#.....# +.###...... +...#..#..# +...#.#.#.# +.#.....##. +..#.....## +........#. +###....... +#..##...## + +Tile 1031: +##.#..#### +#.##.#.... +..#....... +#......### +.##.###.## +#...#...#. +#..##..... +#..#.#.#.. +....###... +....#.###. + +Tile 3803: +#..#..##.. +...##..#.. +...#.#.... +#.....#..# +#........# +.#..#.#.## +..#..#.#.. +#..#.#.#.. +..##..#.#. +#####.###. + +Tile 3541: +.##.#..#.. +.##..#...# +.#.#..#... +...#..##.# +..#.....#. +..##...... +.##......# +##.......# +.#..#.##.# +###.#.##.# + +Tile 3821: +.#.#.#.... +..#..##... +#.##...... +..#...#.## +#.####..#. +##.##.#... +..#..#.... +....#....# +...###.#.# +.#..#.#.## + +Tile 3853: +#####..#.# +.....#..## +#...#.##.# +.##....#.# +#.#......# +###...#.#. +##....#.## +#.#.#.#..# +....###... +##.#.#.... + +Tile 1249: +###...#### +..#....#.. +##.##....# +.........# +#......... +.##.#.##.. +...#...##. +.......... +##...#.#.. +##.####..# + +Tile 3673: +...##..#.# +.#..#..#.# +###......# +#.....###. +..#.#..... +#.#..#.### +.#.##.##.. +.##....#.. +.#...##..# +#.###..#.# + +Tile 3163: +##.#.##### +.##....#.. +####...... +#..#.#..## +.#.#..##.# +##.....#.# +.......#.. +#...#..... +..#..#.... +###.#...#. + +Tile 1759: +###.#...## +...#..#... +###..###.. +.#.#...#.# +.##...#... +..###....# +#.#.....#. +......###. +..#.####.# +##..##..#. + +Tile 1831: +.#...#...# +...#.#..## +#...#.#... +#...##.#.. +.#.#.#..#. +......##.# +.........# +#....##.#. +......#..# +#..#...##. + +Tile 2179: +.###.....# +..######.# +....#....# +...#....#. +#.##..#... +#..#....## +.#..#.#..# +..#.#....# +#.#.#..... +###.##...# + +Tile 2713: +..###.#..# +#.#.....#. +#....#.#.. +#...##.... +##...#.#.# +###..###.# +.##..#..## +.#...##.#. +#.#....... +#...#..... + +Tile 1889: +....#....# +......#.#. +##.###...# +.#..##...# +##.##.#..# +...#...##. +#....#...# +.......#.. +.#...#..## +.#.####.## + +Tile 1999: +##....##.# +#..#.##.## +..#...#... +#.....#... +......#... +#.....#..# +.#.##..#.# +..#..##..# +#...#..#.. +###..##..# + +Tile 2039: +.#....#### +.##..#.... +.#.......# +#........# +#.......#. +.#..#..... +#.##...... +##....#..# +.........# +#.#......# + +Tile 2969: +...#####.. +..#.#...## +##.....#.. +##.....### +#...#..### +#..#....## +#..##...## +.........# +#...##...# +.#......## + +Tile 2153: +.##..###.. +#.#..#..## +.#####.... +#.#..#.### +#.....#.## +####..#.#. +.......... +.#......#. +...##...#. +.#....#### + +Tile 2837: +..###..... +###.#.###. +.#....#... +##.....### +##.##..### +..#..##.## +.#....##.. +#..##.##.. +#..#...... +#..##...#. + +Tile 1619: +##..###.## +##....#### +.#..##.#.. +##.#...#.. +#..##.##.. +...#.#.#.# +.....#.##. +..##..#..# +#..#..#..# +......#.#. + +Tile 3943: +.#.##.#.#. +.......#.# +.........# +...#..#..# +...#....## +#.#.##.... +##.......# +.#..#.##.# +...##.#..# +#.##....#. + +Tile 3389: +#...#.##.. +#.##..#... +#.#.#..... +##...#...# +##.....#.. +.#..###..# +..###..... +#.##..#.## +####....## +##.#.##### + +Tile 3631: +##.###.### +#...#..... +..#....... +#....#.### +#......... +#.#....... +....##...# +........#. +#....#.... +.....#.#.. + +Tile 2081: +##..##.#.. +.##......# +........## +#.......## +......##.# +#....#.... +.#.#...##. +....##..#. +#.#..##### +...#####.. + +Tile 1579: +##........ +.....#...# +#......#.. +#..#.#...# +...#..#... +#.##....## +...#...... +.#...#..#. +..#....#.# +.##...#... + +Tile 3019: +.##..####. +...#....## +...##.#.#. +#....#.... +.........# +##..#..#.# +...#.#...# +.#.##.#.## +##..#..... +#..#..###. + +Tile 2089: +##.##.#... +..#.##...# +##...#.... +#........# +#..#.....# +..######.# +.......#.. +...#..##.. +#.#....#.. +...#.##### + +Tile 2297: +#.#.###... +#.##...... +#..#..#... +......#..# +#....#...# +###.#..##. +#....##.## +.......#.# +.........# +.###.#.#.. + +Tile 1373: +#..#.####. +........#. +....#....# +.##..#...# +.#.....#.# +#.....#... +#..#..#..# +.##...##.# +##.......# +.##..#.#.. + +Tile 1259: +...#..##.# +....#.#..# +#..#.##.## +##..##.... +#..#.#..## +#.#...#... +..#......# +...###.#.# +.......... +.###..##.. + +Tile 2411: +.###..#.#. +.#..#..#.. +#.....#..# +.#.....#.. +##..#...#. +.#........ +#...##.... +#.#..##... +.....#.#.# +....#.##.. + +Tile 3359: +.##..##.## +..#.#..#.# +#.......#. +.#..###..# +.#.....#.. +#......... +...#.....# +.##....#.. +.........# +.#.##..#.. + +Tile 2437: +.#.....#.. +#.#....... +....##.#.. +##.###.##. +##.#....#. +#...#....# +##..##..## +...#..#..# +....##.#.# +.##.#.#... + +Tile 1367: +....#####. +..#.#....# +##......#. +..##...##. +..##..##.# +..##.##..# +#.#......# +##...#...# +.....#.#.. +##.###.### + +Tile 3533: +##..####.. +##..#....# +...#.....# +#.##..#### +###..##... +....###..# +..#.....## +.##.#..#.. +....#.##.. +##.#.##.## + +Tile 1451: +.####.#... +..##.#.#.. +...#.#.... +.........# +....#...## +##...##... +..#...#... +#...#.#### +...#.#.### +#######... + +Tile 3457: +#.##.###.# +#..#.#.... +###.#....# +.#....#.## +.......##. +#...####.# +#.#####..# +#.#..#..#. +#.#....... +.#.##..... + +Tile 2657: +..#####..# +......###. +#.....#..# +.#..###..# +...#.##... +#.....#..# +#....##### +....#..#.. +#.#.###..# +.#..##.#.. + +Tile 2347: +#.##.#.### +#...#....# +.......... +#.#.#..... +#....#.... +#..#...### +#.##...#.. +#.....#..# +#.#.###.#. +#...###.## + +Tile 3923: +#.####...# +###...#.## +......#..# +..#..#..## +#....#.#.# +.........# +.....#.#.# +#..####..# +....##.#.. +#..#...#.. + +Tile 2593: +####...#.. +#...####.# +#......##. +..#..#.... +#..#.....# +...#...... +....#..... +#.#...##.# +.......#.# +#.#####.#. + +Tile 1103: +..##...#.# +..#.....#. +#....#...# +...##....# +#.#.....## +.#.#.#.#.. +#....##### +.#.#.##### +.........# +.##...#.#. + +Tile 2671: +.##.##.#.# +...#.#.... +##....#... +#......#.. +.#....#.## +........## +..#...###. +###...#... +....#.#..# +.#######.# + +Tile 3907: +###....#.. +..##.....# +.......... +##...#..## +##..#..##. +##..##..#. +#.#.....## +..###..#.# +#..#..#..# +#.#....... + +Tile 1327: +.#..#..#.# +.###.###.. +..#..#.... +.#...#.#.. +#.##.....# +#..#.#..#. +###...#... +##..#..#.# +......#... +#.#...###. + +Tile 1163: +..#.#...#. +####.#.#.. +.##.....## +#...#..... +.....####. +#...#..### +...#.##.#. +##..#..#.. +.....#.#.# +.###...#.# + +Tile 2683: +.......#.. +.#.#.##..# +##..#...## +...#...... +##.##...#. +...#.#.### +.#.##..... +#..#....#. +.###..#... +.#.#.....# + +Tile 3881: +#.#.#..##. +##.#...### +##......## +#......... +#..#...... +...#.#...# +.#..##.... +.....##.#. +##...#.... +###.....#. + +Tile 2711: +#...#.#.## +#..##..... +...#...... +#.#.#....# +#...#.#... +...#...... +.#.#...... +..#....#.# +#.##..#... +#.#.#..... + +Tile 3491: +.###..#.## +.....#.... +.##..#..## +##.##..#.# +.###....## +..##..#..# +..#......# +..#..#...# +#...#.#..# +.......##. + +Tile 2339: +###.#####. +.#....#... +##.#.....# +#......... +#......... +..##..##.# +.###...... +#...##.... +##........ +#.....#..# + +Tile 1543: +..##...#.. +.....#..## +....##.... +.........# +.#..#.#..# +.......... +.........# +#.#.#..... +##.#.#.... +#.#.###..# + +Tile 2371: +#..#.##### +##.#..###. +#.#...##.. +#...###.## +#...#..#.# +##.....### +.#.......# +.....#.#.. +..#.#.#### +.###..##.. + +Tile 2971: +..###.#... +#......... +##.#...### +....###... +###......# +..###....# +##.#.....# +.#.....#.. +#.....#### +..##.##.#. + +Tile 2203: +#.###.#.## +.#...##.#. +#.#.....#. +..#.#....# +##..#....# +##..#..... +#..#..#... +##........ +..#..#.#.. +##....#..# + +Tile 2113: +###...##.# +......#... +.....##.#. +....####.# +##..#..#.. +#...#...## +.......#.# +......#..# +#.##.#..## +....##.#.. + +Tile 1321: +.#..#..#.. +##...#...# +.......... +.####..#.# +##.#.#.#.# +#..#.#.... +#..#.....# +.#.......# +....###.#. +##.#.##.## + +Tile 1667: +.#####...# +##....#..# +#..#.#.... +..##..#... +#..##...## +...#...... +..#..#...# +.....#...# +#..#...#.# +##..#.##.. + +Tile 3001: +.#.####### +...#.#...# +..##...#.# +#......... +....#..... +#.....##.# +.....####. +#......... +...#.##.## +##.##..### + +Tile 1789: +..###.#..# +...##...#. +........#. +####...#.# +#..#..#... +##.##..##. +....#..... +#.#.#..... +#.#..#...# +######.#.. + +Tile 3677: +.#...#.### +#..##...## +#..#...#.# +##........ +..#....### +.......... +##..#.##.# +.#........ +......##.. +.##.##...# + +Tile 2693: +#.#.###.#. +#.#..#..#. +.#....#... +#..#...#.# +.#.##..##. +.##......# +...#.....# +##...#.### +.#.#.....# +########.. + +Tile 2141: +#####..... +#......... +#...#....# +....#..... +.......#.. +##..#.#..# +#....#..#. +..#....#.. +.....##.#. +##..#.#.#. + +Tile 3847: +#...###### +#..#.##..# +..#...##.# +##..#.#..# +##..#..#.# +##.##....# +#........# +#....#.#.. +#......... +#......#.. + +Tile 2333: +#.#..##.#. +####.....# +###..#...# +.........# +...##.#..# +###....... +..##...#.# +...###...# +.###.#...# +##..#.##.. + +Tile 2129: +#..###.### +....#....# +#.#.#..#.# +....#....# +#...#.#..# +..##.##... +#.##....#. +#...#.#... +.#..##...# +...###.##. + +Tile 1283: +.#..#.###. +###.#.##.# +#..#..#.#. +.....#...# +.#.#.#.... +#...#..#.# +.#.#..#.## +.#..##..#. +#....##.#. +.#..#...#. + +Tile 2851: +.##.#..... +###......# +.#........ +....#.#..# +.#..#..#.. +.##....#.. +.##...#.## +#.###.##.# +##........ +.#.#.#.#.# + +Tile 2311: +#..##....# +.#......#. +....#...## +....#...#. +.#...#...# +#...#....# +.....#.#.# +.....##..# +##..##.### +##..###.#. + +Tile 3217: +#.##....## +#.......#. +#.#....#.# +..##.###.. +....##...# +#......... +...#.#...# +..##....## +..#......# +##.###..## + +Tile 2833: +####..#..# +#...##.#.# +........## +..##..#... +.......#.. +......#... +###..#..#. +.##..#...# +##.#....#. +.####..... + +Tile 3593: +#..#####.. +.##.#....# +...#..#..# +##.#...##. +#######... +...#..#... +#.##..#.#. +#........# +#...##..## +........## + +Tile 3299: +...#.#..#. +#.#......# +##......## +.#..#..#.. +#.#####... +#...#....# +#.#....... +..#....#.# +.#........ +#.#.#.##.. + +Tile 2719: +...#..#.#. +#..#.###.. +......#.## +....#.#..# +#.#......# +....#..... +##..#.#... +...##..... +###.#....# +..####..## + +Tile 2161: +..#.##..## +#........# +...#.#...# +...###.... +......#..# +..##.##.#. +.#....#.## +#...#####. +#....#...# +.#....#... + +Tile 3643: +...#...##. +##......## +....#.###. +.#.#..#### +..#.#...## +.##.#.#.#. +#.#..#..#. +#..#.#..#. +.#........ +.#.###.... + +Tile 3767: +.##.#....# +#...#...## +.#...##..# +.#.#...... +..#..#..## +#..#.#.##. +#.....#.## +....##...# +.....#.##. +..#..###.. + +Tile 2377: +.#####.#.# +..#.....## +#...#...#. +##....##.. +....#..#.. +#.##..#..# +.#...#.##. +...##...#. +#....#.... +..#.#..### + +Tile 2441: +....#.###. +.#..#....# +.#.###.... +#...#..... +#.#.##.... +....##.... +....##...# +...#..##.. +#...###.## +.##.#.#.#. + +Tile 2273: +...#..#.#. +#..#...### +..#....#.. +...###.#.. +.........# +..##.#..## +###.#....# +#..#.....# +....#...#. +.##..##### + +Tile 1231: +....#####. +#.....#.#. +..#....#.# +.###..##.# +#..#....## +#..#.#.#.. +..#.###... +##........ +..#.....## +##.##..#.# + +Tile 2879: +#####.###. +#..#..#..# +...#..#..# +#......... +.#.#.#...# +...#..#..# +#.#..#.### +#.....#### +.......#.# +..##.##### + +Tile 2473: +.##.###..# +....##.#.# +#..#..#..# +..#.#.#... +#..##..... +.##....#.. +....##..## +...#.....# +....#..... +.#####.#.. + +Tile 3329: +#.#..###.. +......###. +.###..##.. +...#.##... +#..#.#.### +#.###..##. +##..##...# +..#####..# +.#...#.... +#.##.#..#. + +Tile 1489: +....#....# +#.##.....# +..#......# +..#...#..# +.#....#..# +#..##...#. +..####.##. +.#..##..## +..#.....#. +##.#.##..# + +Tile 3259: +..####.### +##.##..#.# +.#..#..### +#.#....... +.....#.#.. +##...#.#.. +.....#...# +.#....#... +..#.#....# +######.... + +Tile 1123: +....#.#.#. +...##..... +...##....# +#.##....## +..#...#..# +.#..#..... +.#......## +.........# +.....#...# +.##.###... + +Tile 1381: +.###..#.## +#..##..#.. +#.....#..# +#..#..#..# +#....#.#.# +.......#.# +#...#.#..# +##..###..# +..#..##... +..##.#..#. + +Tile 2903: +#.###.###. +#..###..#. +##.......# +.#....#... +#..#..##.# +...#...#.# +#.#...##.# +......#..# +##.#..#..# +##.#..##.# + +Tile 1049: +#....#.### +####.....# +#.##....#. +.#....##.. +.##..#..## +#.#.#..#.# +.##...#..# +...#..#.## +.....#..## +..#.#.###. + +Tile 3137: +...#.#.#.# +#.#....#.. +..###...#. +..#..##..# +.#.#.##.#. +#.#..##..# +#.....#... +##...##.## +#.#...#... +.##.#..... + +Tile 2131: +.#......## +...#...##. +.#.#.#.#.# +.......... +...#....#. +#.#.#..#.# +..#.#....# +....##.... +....##..#. +##.##..#.. + +Tile 3733: +.#.#....## +.#..#....# +..###.#..# +.....#...# +...#.....# +###..#.... +#...#.#### +......#... +..#..#.... +.#####.#.. + +Tile 1973: +.#.#.##... +#.....#..# +#......#.. +...#...#.# +..#..#...# +####.#.... +....#..#.# +.#.....#.# +....#..#.# +..#..#.#.. + +Tile 3889: +#.##.#...# +#....##..# +.###..#.## +..#...###. +#....##... +#.##...... +#.#..#..#. +...#.#...# +........## +##.#..#.#. + +Tile 1129: +#...###### +#...#.##.# +###.....#. +#.#..#..#. +.#....#... +..#...#..# +#....#.### +......#.#. +#.#..##.## +.###..#..# + +Tile 1549: +.#..##.#.. +#.#....### +...#..#... +##....#... +..##...#.# +#.#....### +..#.##.##. +.....#...# +#.##.....# +#..#.##... + +Tile 2213: +#...#.#.## +#........# +...##...## +.#..##.#.# +#..##....# +...##...## +##........ +....#....# +...#.#.#.# +..#.###..# + +Tile 1597: +..###..#.. +#......#.. +.......#.# +#.#....### +#.###..#.# +##.#.##... +#.##.#..## +.#.#..##.. +.##..#...# +##...##### + +Tile 1777: +#..#....#. +.........# +..#.....#. +..#......# +.##....#.. +#...#...#. +.#..#..... +#.....#..# +.#..##...# +#.#...#... + +Tile 2503: +#..###.#.. +.#..##.#.. +....##.... +..#..#.... +#....#.#.. +#.#....#.# +...#.#.... +..##.#.... +#.#.#....# +#.######.. + +Tile 3499: +.####...## +.#.##..#.. +#........# +..#......# +##..#...#. +#...##.... +#......#.. +.#.#....## +...#..#... +.##.#...#. + +Tile 1811: +#.###...## +..##...#.. +..#.#..### +##.#....#. +.#...#.... +##.......# +#....#...# +...##.##.. +...#.....# +.####..#.. + +Tile 3793: +###.####.. +##...###.# +...#.###.. +#....#.... +.....#.... +...#.....# +###.####.. +#.##.##.## +......#... +#.#.###... + +Tile 2341: +.##..#.### +.#........ +..####..#. +.#..####.# +#....#...# +......##.# +#.....#... +.......... +#..###.... +####.##### + +Tile 3613: +..#.#.#.#. +#....###.. +#......#.. +#.#...#.## +#..#.....# +##.#.#.#.. +...####..# +##...###.# +#.#.#....# +#..####... + +Tile 3701: +..##.####. +#.##...### +.###.#.... +#..#.....# +##........ +###..#.### +..#...#.#. +.##...#..# +##.......# +###.#...## + +Tile 1483: +#####..##. +....#..#.# +...#####.# +#.##...#.. +........#. +........## +##..##.### +.###....## +...###..#. +...#.#..#. + +Tile 3571: +#.#.##.##. +#......##. +#...#.#... +.#.#....#. +#.#....#.. +#.#...#... +##.....#.# +##.#.#...# +#....#...# +#.#..#..## + +Tile 2521: +##.##..#.# +......#..# +.#.#.#.##. +#........# +.#.##....# +.#....#.#. +##......#. +#....#.... +.#..#...#. +.#..#..### + +Tile 3413: +.##.##..#. +#...#..#.. +##....#..# +.......... +#..#...#.. +##..#....# +....#.#... +#.....#... +......#.## +..##.##.#. + +Tile 1933: +#..#....## +#...#..### +.#......## +......#..# +.......... +##.##..### +.......### +...#...### +.#....#..# +#.#..#.#.# + +Tile 1021: +.#..##.#.# +##....#... +.#........ +.#.#....## +.#......## +##........ +.....#..#. +#....#.#.# +#......... +..#.#.##.# + +Tile 3323: +...###.#.. +.#..####.. +....#..... +#.....##.# +###......# +..######## +.#....##.# +....##.##. +#..##....# +#.##.#..#. + +Tile 1607: +....####.. +##.#...#.# +.......#.# +#......... +..#..####. +..#..#.##. +.###.#...# +##...#.... +#.######.. +##.#.#.### + +Tile 1481: +.###...#.. +.#......## +.....#...# +...#...##. +#.###.##.. +#......### +#......... +###...###. +.#....##.. +#....###.# + +Tile 1879: +###.##.... +#.#.....## +#.#..#.#.# +.#...#..## +......#### +#.###..... +......###. +#..#.#..## +..#......# +.#..#..... + +Tile 2927: +###..##.#. +#..#....#. +##..#..... +#.#...#### +#......... +..###...## +#.####...# +#.##.##..# +...#...... +#....#.##. + +Tile 1867: +..#..####. +##.##..#.# +.##......# +###..#.... +..#......# +#..##..#.# +#......... +...#..#..# +#......#.. +.#....#.#. + +Tile 2647: +#####.##.# +...#...#.. +#.......## +...#..#..# +..#.###... +...##..... +..#......# +.##....... +#...#..... +##...##.#. + +Tile 2207: +#.#####.#. +#..#.#..## +...##....# +..#..#.#.# +#...###..# +.##.#...## +#..##..### +#......... +###.#..#.# +.#....##.# + +Tile 1223: +###.....#. +#.....#.## +##.##.#... +#...##...# +#....#.... +..#.##.... +##....##.. +..#..#.... +.#.##..#.. +###.#.#### + +Tile 1931: +##.#...### +#...##.... +#..#....#. +..##..#... +#...#..... +.........# +###.##.... +...##.#..# +.#.#.....# +..#..##.## + +Tile 3917: +.##.#..#.. +.......##. +#.##....## +...#....## +###....#.# +.##.#...## +###....... +##.....#.. +....###.## +....#...#. + +Tile 1663: +#.#.....## +.#.##.#..# +....#...#. +#...##...# +#..#...... +.#..#.#..# +..#..#..## +...#...... +#...##.... +.##.###### + +Tile 3373: +#..###.### +##...#.#.. +#..#..#..# +.#....##.# +..###..##. +...#.#...# +#.....#..# +##..#..... +.#..#.#... +.#...###.# + +Tile 1319: +.#.#.#.#.# +.....#..## +..#.#.#.#. +.#.##...#. +..##...... +...#...... +.#........ +#..#.....# +#..##....# +.#.##.#..# + +Tile 2687: +#...###.#. +##.#...##. +#...#...## +#..##....# +......#.#. +.###.#.#.. +##...#..## +......#..# +.......... +#.....##.# + +Tile 2003: +.######... +.##...###. +....#..... +#.###.#.#. +......#..# +..##.#.#.# +#.##..#.#. +####.#.... +#...#.#.## +......##.# + +Tile 1453: +###.#.#### +...###..#. +.#..#..### +..#......# +#.#..#..## +..#..#.#.. +#.#...#.#. +..##..#.#. +#..###.... +..#..#..## + +Tile 1871: +..#..##### +##..#....# +##.......# +#..#..#..# +#.....#.#. +#..###.... +.......... +.#........ +.#.##.##.# +#.#..#.### + +Tile 3709: +.##.#.##.. +.#..##...# +.##....... +..##.#.... +.........# +....#..... +###.#.##.. +.#####.... +#####.#... +..#..##### + From 20784cb2ca050e3fe2ecb32c674f083274b3b0a7 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 20 Dec 2020 14:27:02 +0100 Subject: [PATCH 107/129] 2020: d20: ex2: add solution --- 2020/d20/ex2/ex2.py | 185 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100755 2020/d20/ex2/ex2.py diff --git a/2020/d20/ex2/ex2.py b/2020/d20/ex2/ex2.py new file mode 100755 index 0000000..e923806 --- /dev/null +++ b/2020/d20/ex2/ex2.py @@ -0,0 +1,185 @@ +#!/usr/bin/env python + +import functools +import itertools +import math +import sys +from collections import defaultdict +from copy import deepcopy +from typing import Dict, Iterator, List, Set, Tuple + +Tile = List[List[str]] +Tiles = Dict[int, Tile] + + +def parse(raw: str) -> Tiles: + def parse_tile(raw: List[str]) -> Tile: + return [[line[i] for i in range(len(line))] for line in raw] + + res = {} + for lines in map(lambda s: s.splitlines(), raw.split("\n\n")): + if len(lines) == 0: + continue + nums = int(lines[0][5:-1]) + res[nums] = parse_tile(lines[1:]) + return res + + +def rotations(tile: Tile) -> Iterator[Tile]: + yield tile + for __ in range(3): + tile = [ + [tile[j][i] for j in range(len(tile))] + for i in range(len(tile[0]) - 1, -1, -1) + ] + yield tile + + +def flips(tile: Tile) -> Iterator[Tile]: + yield tile + yield tile[::-1] + yield [line[::-1] for line in tile] + yield [line[::-1] for line in tile[::-1]] + + +def transforms(tile: Tile) -> List[Tile]: + # Can't use a set with lists... + res: List[Tile] = functools.reduce( + lambda l, it: l + [it] if not any(it == other for other in l) else l, + itertools.chain.from_iterable(map(rotations, flips(tile))), + [], + ) + return res + + +def borders(tile: Tile) -> Iterator[str]: + # They should match on same axis (i.e: go clockwise and counter-clockwise) + return map( + lambda s: "".join(s), + [ + tile[0], + [line[-1] for line in tile], + tile[-1], + [line[0] for line in tile], + ], + ) + + +Transforms = Dict[int, List[Tile]] +Tiling = List[List[Tuple[int, int]]] # Which tile, and which transform + + +def build_tiling(tiles: Tiles) -> Tuple[Transforms, Tiling]: + transform_mapping = {num: transforms(tile) for num, tile in tiles.items()} + trans_borders: Dict[int, Dict[int, List[str]]] = defaultdict(dict) + for num, trans in transform_mapping.items(): + for i, t in enumerate(trans): + trans_borders[num][i] = list(borders(t)) + length = math.isqrt(len(tiles)) + tiling = [[(-1, -1)] * length for __ in range(length)] + + def rec(x: int = 0, y: int = 0, used: Set[int] = set()) -> bool: + if x == length: + return True + for num, borders in trans_borders.items(): + if num in used: + continue + used |= {num} + + for trans, border in borders.items(): + top, __, __, left = border + if y > 0: + nid, ntrans = tiling[x][y - 1] + __, right, __, __ = trans_borders[nid][ntrans] + if left != right: + continue + if x > 0: + nid, ntrans = tiling[x - 1][y] + __, __, bottom, __ = trans_borders[nid][ntrans] + if top != bottom: + continue + tiling[x][y] = num, trans + + next_x, next_y = (x, y + 1) if y < (length - 1) else (x + 1, 0) + if rec(next_x, next_y, used): + return True + + used -= {num} + + tiling[x][y] = (-1, -1) + return False + + assert rec() + return transform_mapping, tiling + + +def trim(trans: Transforms, tiling: Tiling) -> Tile: + def trim_tile(tile: Tile) -> Tile: + return [line[1:-1] for line in tile[1:-1]] + + def tiling_to_tile(tiling: List[List[Tile]]) -> Tile: + res: Tile = [] + for i in range(len(tiling) * len(tiling[0][0])): + res.append([]) + tile_line_idx = i % len(tiling[0][0]) + for j in range(len(tiling[0]) * len(tiling[0][0][0])): + tile = tiling[i // len(tiling[0][0])][j // len(tiling[0][0][0])] + tile_row_idx = j % len(tiling[0][0][0]) + res[-1].append(tile[tile_line_idx][tile_row_idx]) + return res + + tiles = [[trim_tile(trans[num][id]) for num, id in line] for line in tiling] + return tiling_to_tile(tiles) + + +def find_monster(image: Tile, monster: Tile) -> Iterator[Tuple[int, int]]: + def monster_at(x: int, y: int) -> bool: + for i in range(len(monster)): + for j in range(len(monster[0])): + if monster[i][j] == " ": + continue + if image[x + i][y + j] != "#": + return False + return True + + # Returns upper left corner if found + for i in range(len(image) - len(monster)): + for j in range(len(image[0]) - len(monster[0])): + if monster_at(i, j): + yield i, j + + +def remove_monster(image: Tile, monster: Tile, x: int, y: int) -> None: + for i in range(len(monster)): + for j in range(len(monster[0])): + if monster[i][j] == " ": + continue + image[x + i][y + j] = " " + + +def solve(tiles: Tiles) -> int: + image = trim(*build_tiling(tiles)) + monster = [ + [char for char in line] + for line in ( + " # ", + "# ## ## ###", + " # # # # # # ", + ) + ] + monsters = transforms(monster) + + for monster in monsters: + for coords in find_monster(image, monster): + remove_monster(image, monster, *coords) + + return sum(sum(char == "#" for char in line) for line in image) + + +def main() -> None: + input = parse(sys.stdin.read()) + print(solve(input)) + + +if __name__ == "__main__": + main() From ed189664139e3f83591d52c84f312c6b09783b85 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 21 Dec 2020 12:04:10 +0100 Subject: [PATCH 108/129] 2020: d21: ex1: add input --- 2020/d21/ex1/input | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 2020/d21/ex1/input diff --git a/2020/d21/ex1/input b/2020/d21/ex1/input new file mode 100644 index 0000000..3860abd --- /dev/null +++ b/2020/d21/ex1/input @@ -0,0 +1,40 @@ +zdmhtpg mlcvjc kgdvd htxvfq lxgxp kqxz pfhfb fnkdvt ccn vhbjp hqhnh xcljh ndnlm shc ncrn nrdtprm skrxt qrdpc dcvtrq gdmv nxcrg hhxch mv dscm qzln zjlz qkbm dmjzc fjqv jqlp zcxthb sdclrlb bbtn jrspd lqbcg gdljd mvtkk zbhp hcc ntbqk lvft glj fsr hnh nvnx dvjrrkv fdqp lctltv hjn mknsj gtsslgk (contains sesame, shellfish, dairy) +gtdb nxcrg fzl gtsslgk sgdlhb fzckq mknsj kscd dgdn svzfl mlcvjc ntbqk ctkjrt gdmv tkvddn rzhktt zgcf jfm gzhlbn kphbtmkx mgbv pkrdz fsr drj lqgn tgkgj ndnlm zczht tlv qkbm ccn hhxch lgjsd dvjrrkv qfgbx rqxfdd hrtd ktsnt jmt kgfld mxm knfx kshg nhlxntg zdmhtpg qpp mv ssk tgxvz brjcp skrxt xjksh fsxf tpdc crjddsgj hcrsbr bgc jqlp dmjzc hxgdp xcljh xjqkbq hnh bsgnsc gqkf bzlnnv jjmmn gbmv zdqd zbhp (contains dairy) +hxgdp nkgzzg tgxvz tgkgj hqhnh fdjrml gnnzj fsxj zbhp rqxfdd ndnlm fsr nrgn hhxch gnq sgqrvd sm qjktms jjmmn xcljh qzln jqlp nxcrg bsgnsc jxftql lxgxp kgfld jmt ntbqk kvqq fnkdvt gppfld flg kscd jjdgtt nvnx vhbjp nhlxntg zkhpc bgjcg tpdc jkgf tnvtm rnln mgbv nrdtprm cntfq brhmkh rnsqjkq mv dvjrrkv crjddsgj mxm nqbjlf pkrdz xvzlpx dmjzc brjcp hcrsbr nkcl skrxt zfqhnt rglsgs pfhfb nsnzxsc ncrn fzckq rzhktt dcvtrq zgcf qgl (contains soy, wheat, sesame) +sgqrvd dvjrrkv qszr brhmkh znzx tkvddn mgbv kgpbh gtdb gdmv zjkt zdqd mhqxk cntfq hrtd sgdlhb lxgxp zbhp bgjs hxgdp rfcl lvft qgl ndvnj glj ptcnh xjqkbq zkhpc bgc rnln xntpsg xvzlpx zfqhnt xxbnf ntbqk tgkxxjm ncksb flg nrgn kqxz hkdls gqkf fjqv qpp krhmfb fdjrml tmlm tpdc rpqss qzln ckzg xcljh jdcbc kgfld ndnlm kvhbj svzfl jfm nrlbfc tkxxdnh fsr qjn lqbcg sdclrlb nxcrg gnq vchxzh rzhktt tvgcv (contains shellfish) +pfhfb rpqss bzlnnv vchxzh ctkjrt hjn ckzg hpsrqbl nzxs zcxthb jmt lqbcg ndvnj qbvxrbs dvjrrkv jvgbct zjkt ndnlm nrgn mxm xcljh rzhktt fnkdvt hcc knfx tgkxxjm hqhnh bhghks kgfld tkqp qgl tkvddn gzhlbn rglsgs jjdgtt kvqq gfq zmnflgt fsr qjktms ssk jdcbc kshg dgdn jfm gzthtlg mkmcq tpdc nxcrg mgbv xjqkbq qkbm qpp rnln zbhp chjqncr sm jxftql xjksh tnvtm gbmv tgxvz zczht tkxxdnh kssncfd ptcnh bdfmncs mvtkk rfcl zkhpc qjn xxbnf gdmv fzl lxgxp mhqxk (contains soy, dairy) +xjqkbq xvzlpx nqbjlf qbvxrbs gtsslgk bqjqf sdclrlb ccn qpp nsnzxsc zmnflgt pkrdz ndnlm bsgnsc zgcf zbhp tgkgj jfm lvft nrgn xcljh shc bpvmb ltjt jjdgtt dvjrrkv ckzg mgbv sm hxgdp fsxf nhlxntg kqxz kvqq gzthtlg pfhfb htxvfq nvnx jxftql lgjsd sgqrvd skrxt cntfq glj bgjs mxm bbxsn rpgrk tmlm fsr rqxfdd bgjcg qkbm fdqp hpsrqbl gppfld vchxzh svjp qjktms rnsqjkq nxcrg mv tgxvz krhmfb nxcsxc zcxthb hcrsbr qjn tnvtm qrdpc lvtj qfgbx fjqv rpqss nkgzzg (contains fish, wheat, sesame) +jdcbc prgj rnln zdqd zbhp cntfq mgbv gfq dgdn sm gdmv hkdls hnvhqczc ltjt ckzg skkt tkvddn lsll ndnlm flg nxcrg kgpbh zjlz dvjrrkv zgcf mhqxk gnq qgl ccn hcc hvrrhc bgc rpqss gqkf hqhnh nxbn bsgnsc lqgn gzthtlg xcljh jxftql nrdtprm bdfmncs bhghks kgfld zczht hrtd lqbcg rqxfdd bbtn dmjzc fsr mkmcq zkhpc (contains sesame) +nqbjlf dcvtrq cntfq sdclrlb kvhbj skkt jvgbct xjqkbq knfx lsll zdmhtpg hnh fnkdvt gtdb tgxvz xjksh gzthtlg bhghks qpp zgcf ptcnh mvtkk pfhfb jjmmn ktsnt kpzbxfp tgkgj glj rfcl fsr fsxf lqgn gppfld ssk mlcvjc mhqxk kqxz kshg jjdgtt tvgcv xcljh qszr prgj gfzjc jmt qrdpc hhxch bgc mgbv zbhp kssncfd nhlxntg hkdls bgjs gfq nxcrg hcc fdqp lpm jrspd bsdc nrgn dscm bzlnnv bpvmb qjn nkgzzg rglsgs fjqv xvzlpx xxbnf qjktms xcsxh lqbcg bdfmncs qbvxrbs nkcl skrxt hxgdp ndnlm vhbjp nxcsxc flg nxbn kgpbh (contains soy, wheat, peanuts) +zjlz jdcbc nkcl rpqss gqkf lsll flg zbhp ltjt jmt fzckq rnln mknsj ccn qkbm chjqncr lfgh bsdc bzlnnv bbtn fsr skrxt kvhbj hpsrqbl kgdvd lpm dvjrrkv ptcnh tnvtm sgdlhb rfcl gtdb tvgcv rpgrk mkmcq hvrrhc qjktms bsgnsc zsggkm pvnr shc zcxthb lhcm bqjqf fzl rnsqjkq lqgn brhmkh jkgf mv xntpsg mgbv fdjrml dgdn mhqxk ktsnt xcljh qfgbx tkvddn xjksh lqbcg pkrdz brjcp bbxsn (contains fish, peanuts) +xjcvt kgfld gbmv fsxj bqjqf qgl rnln hcrsbr nxbn zcxthb zfqhnt skrxt tgkxxjm dscm hkdls dvjrrkv lvtj gdljd zmnflgt pkrdz xcljh bsgnsc zjkt zkhpc xxbnf tpdc znzx tgkgj qszr bbxsn qfgbx rzhktt rfcl xcsxh ctkjrt bgjs mhqxk mgbv qrdpc ktsnt jjmmn fmcnhq tkxxdnh jrspd qkbm qpp qbvxrbs kshg prgjph skkt mvtkk ncksb hpsrqbl kphbtmkx dgdn ncrn fnkdvt dcvtrq mv nrdtprm kvqq zdqd gzhlbn drj vchxzh fsr nrlbfc zsggkm tlv bgc sgqrvd lctltv mlcvjc lsll hnnmrxh lfgh bgjcg ntbqk htxvfq rnsqjkq hrtd bhghks gtsslgk dftg lqbcg jqlp zbhp qjn bdfmncs (contains peanuts, sesame) +zkhpc lpm fdqp kpzbxfp hkdls mlcvjc bgjs qckqc ndnlm skrxt zdmhtpg dgdn nkgzzg qjn tvgcv brjcp bsdc kshg kgdvd xcljh crjddsgj jvgbct glj xjksh xvzlpx shc mxm gzhlbn ctkjrt ckzg fsr rnsqjkq mgbv rpgrk zdqd rnln gdljd dcvtrq fjqv fmcnhq svzfl fdjrml hrtd dmjzc nxcsxc sgdlhb mhqxk jdcbc qzln dscm zbhp bbxsn fnkdvt kgpbh zjkt tgkxxjm lhcm ptcnh skkt jqlp mv nrdtprm gtdb htxvfq cntfq tnvtm lqbcg (contains soy, nuts) +ntbqk ccn pkrdz krhmfb hkdls kgpbh bhghks bqjqf hpsrqbl bpvmb fzckq nhlxntg pfhfb xcljh bzlnnv nkgzzg cntfq zbhp jqlp ndnlm tlv qbvxrbs nrdtprm gdmv ssk mgbv gdljd dvjrrkv bsgnsc tpdc rnsqjkq znzx flg fsr zlfm zjkt nvnx glj knfx lqbcg hjn (contains wheat, sesame) +qjn sgdlhb rnsqjkq gdljd dvjrrkv nkcl jxftql kssncfd jvgbct kgfld bgc nxcsxc ndnlm nrdtprm kpzbxfp fsxf gnq vhbjp nvnx hvrrhc tgxvz nsnzxsc tvgcv xvzlpx prgjph kqxz fsr hnnmrxh lqbcg hkdls glj ctkjrt zdmhtpg qszr nhlxntg gqkf tlv hxgdp nrgn ndvnj qckqc xntpsg ltjt rnln zbhp gdmv xxbnf hhxch fnkdvt knfx xcljh kgdvd bdfmncs gfq lpm mkmcq skrxt hnvhqczc krhmfb dftg gtsslgk gzthtlg flg zgcf zkhpc brhmkh pvpfn ssk dgdn bsdc jdcbc (contains fish, sesame, dairy) +bpvmb jvgbct nrgn zbhp dvjrrkv bqjqf mkmcq xcljh fsxf mknsj kssncfd lqbcg skrxt tvgcv xbdhth tkvddn nrdtprm mhqxk chjqncr ndnlm lctltv hnnmrxh rpgrk ccn rnln jdcbc gdljd dmjzc svjp lsll bdfmncs rnsqjkq qgl prgjph hqhnh xjqkbq jjmmn hcrsbr xcsxh drj cntfq fsr bsgnsc rfcl pvnr flg tgkxxjm zczht shc (contains soy, shellfish, sesame) +mlcvjc prgj xntpsg pfhfb gtsslgk nrgn kvqq lhcm fmcnhq qgl nrdtprm hcrsbr tgkxxjm lctltv fnkdvt hjn tvgcv prgjph zjlz rpqss bzlnnv zbhp dftg mkmcq tnvtm rqxfdd mknsj fsr xjqkbq pkrdz dscm gdljd nxcrg sm svjp ndnlm zlfm bgjcg rglsgs lvft mhqxk kpzbxfp lpm rnsqjkq ccn skrxt gqkf mxm gzthtlg dmjzc flg tkqp bgjs qpp bsgnsc cntfq skkt gtdb lqbcg xcljh gnnzj hqhnh jjdgtt gfzjc zgcf brhmkh sgqrvd dvjrrkv (contains shellfish, sesame) +dvjrrkv ccn lqbcg lctltv jvgbct tkqp hxgdp lhcm zsggkm bgc qjktms zjkt nvnx nxcsxc kqxz skrxt bhghks gzthtlg chjqncr htxvfq mv rnsqjkq sgdlhb crjddsgj rglsgs nrgn ndvnj ltjt hhxch xcljh hrtd fmcnhq nkgzzg dscm ncrn zbhp mgbv prgj pfhfb tgkgj hpsrqbl kscd lxgxp bbxsn gdmv tgkxxjm glj nzxs tpdc fsr tmlm lgjsd bsgnsc qjn rqxfdd hqhnh cntfq (contains fish) +hpsrqbl brjcp qpp shc tgkxxjm bbtn xcljh gbmv znzx jkgf zcxthb jjmmn zczht bgc lvtj drj rzhktt tkxxdnh tlv dcvtrq nsnzxsc hkdls tvgcv dvjrrkv qkbm knfx zjkt mhqxk bpvmb ckzg bgjs gfzjc bhghks gtdb nzxs gnnzj sm jjdgtt zjlz rnln xjqkbq ctkjrt xvzlpx xntpsg htxvfq tmlm zdqd lqbcg fsr ndnlm rfcl kgdvd skrxt mgbv hhxch mknsj hxgdp fjqv ssk qszr hqhnh xcsxh chjqncr dmjzc crjddsgj prgjph dscm sgdlhb hjn cntfq bsgnsc qjn nvnx sdclrlb jqlp ncksb (contains sesame) +fnkdvt nxcrg sgdlhb kshg glj jvgbct tlv lgjsd qbvxrbs tgkxxjm xcsxh jfm fdjrml mgbv kvqq xbdhth fsr rpgrk qkbm hjn rfcl dftg tkxxdnh mhqxk nsnzxsc zgcf dvjrrkv fzckq prgjph lqbcg skrxt bgc hpsrqbl lsll tmlm bgjcg gtdb nvnx qszr lxgxp zbhp hcc tgxvz xjqkbq nxbn fdqp zdqd xxbnf fsxf ltjt ptcnh xcljh tkqp tkvddn nrlbfc jqlp jrspd (contains fish, peanuts) +nzxs ckzg nrlbfc nsnzxsc xbdhth pvpfn tvgcv tmlm mvtkk ncksb mhqxk ltjt zbhp fjqv rfcl tkqp lpm gzthtlg hkdls hcrsbr qckqc bhghks qgl kvhbj nkcl jmt lhcm bgjcg flg nqbjlf kvqq kqxz xcljh nrgn pvnr bzlnnv lqgn gnnzj bdfmncs ccn lvtj xjcvt dvjrrkv jjmmn qrdpc ntbqk sgqrvd kscd hcc cntfq gnq tgkgj jxftql jrspd fzl fsr lqbcg qkbm mgbv brjcp bgjs gtdb drj qjktms bqjqf hxgdp skkt prgj kssncfd xntpsg hhxch fsxf hqhnh qpp nxcsxc jvgbct qjn lfgh ndnlm mknsj zjkt mlcvjc lgjsd (contains shellfish) +qgl rnsqjkq hnnmrxh lsll nkcl fsr qjktms ndnlm krhmfb rpgrk xcljh jfm lfgh xntpsg skkt gdmv dvjrrkv zbhp kphbtmkx lhcm vhbjp mgbv zsggkm fsxf ccn nrgn nrdtprm bpvmb znzx bbtn dgdn bhghks zjkt svzfl jjmmn tlv bsgnsc bgc qkbm skrxt bgjcg fdqp ltjt rfcl bgjs rnln gtsslgk zjlz (contains wheat) +nhlxntg hqhnh qfgbx kssncfd zkhpc bdfmncs zcxthb drj sgqrvd lqgn rqxfdd hvrrhc prgj tgkgj nrdtprm skrxt jxftql fsr xcljh qpp shc zbhp qjktms zsggkm ccn chjqncr znzx pkrdz prgjph ntbqk ndnlm nrgn kgdvd tkxxdnh tpdc dvjrrkv qzln knfx nkgzzg rnsqjkq kpzbxfp bbtn tkqp mgbv rzhktt lhcm rglsgs fdqp fmcnhq gzthtlg nvnx ssk bhghks kvhbj hhxch tlv fnkdvt htxvfq zfqhnt xvzlpx lpm qszr hnnmrxh hcrsbr jqlp nsnzxsc (contains dairy, peanuts, wheat) +gfzjc hhxch rzhktt gtdb ssk zbhp zfqhnt jkgf tkqp dvjrrkv kgpbh mknsj bsdc lgjsd mgbv zcxthb hrtd nqbjlf mlcvjc hxgdp tgxvz gqkf fmcnhq tpdc lxgxp hcrsbr znzx zlfm fjqv kvqq nhlxntg zjlz brjcp zkhpc skrxt nrlbfc jdcbc qfgbx svzfl fzckq kgfld prgj gzhlbn lhcm qkbm fsxj hqhnh kscd vhbjp fsr lsll qbvxrbs gfq tnvtm lqbcg nkcl ndnlm sgqrvd xjqkbq (contains wheat, shellfish, fish) +gdmv bbxsn kvqq hnvhqczc lqbcg xjqkbq jvgbct mlcvjc gfq jrspd lxgxp jkgf tkvddn bsgnsc lqgn xcljh fsxf qjktms dscm mgbv fsr ndvnj nrdtprm jjmmn xvzlpx nkgzzg rnln nxcsxc zjkt sdclrlb nhlxntg kphbtmkx gnq zbhp fzckq zlfm hvrrhc zsggkm xcsxh ntbqk skkt jdcbc bgc bsdc prgj shc nzxs bpvmb hcc ncrn xjcvt nrlbfc jqlp ktsnt nvnx gnnzj tkqp nxbn ndnlm sgdlhb bqjqf kqxz qzln zjlz tkxxdnh bdfmncs kpzbxfp hrtd fzl skrxt sgqrvd zdmhtpg dftg fnkdvt lgjsd mv (contains nuts, fish) +nxcrg jqlp xcljh nkcl qjn rpgrk xbdhth vhbjp kqxz zfqhnt nrdtprm ltjt tkxxdnh rqxfdd fdqp bsdc gzhlbn bpvmb ndnlm bbtn skrxt jdcbc fmcnhq pkrdz zsggkm rzhktt ccn gbmv ncrn rglsgs dmjzc sgdlhb prgjph lpm zcxthb dftg qjktms pvnr hnnmrxh kssncfd bdfmncs bhghks lhcm lgjsd ssk bgc fsr gfzjc rnsqjkq zbhp lqbcg krhmfb mkmcq zlfm brhmkh xntpsg hnh bsgnsc dvjrrkv tvgcv sm fdjrml prgj hhxch tpdc fsxf nkgzzg nzxs gnq tmlm (contains dairy) +nrlbfc nxcsxc jvgbct dvjrrkv prgjph gqkf ndnlm lhcm mvtkk xcsxh gtsslgk mgbv kgpbh zbhp qbvxrbs kshg gfq ktsnt bbxsn hjn jfm jxftql jmt xbdhth xcljh zmnflgt kgfld nrgn fnkdvt fdqp skrxt svzfl bgjcg sgqrvd ssk svjp sgdlhb vchxzh kgdvd dgdn xntpsg tpdc zjlz zgcf rnsqjkq zlfm chjqncr tmlm dftg tgxvz jkgf lpm hcc qjn tkxxdnh lqbcg kscd lctltv pvnr ntbqk lsll qszr mv hvrrhc fjqv (contains wheat) +vhbjp fsxj jxftql tkxxdnh nzxs fnkdvt fmcnhq lgjsd chjqncr xcljh brjcp hrtd kssncfd ssk mgbv xvzlpx bgjs rpgrk kgfld gbmv ndvnj ccn rnsqjkq xjksh ncrn brhmkh lxgxp qzln zdmhtpg tkvddn lsll nrgn pvpfn lqgn nxbn lvtj dvjrrkv dscm bsdc hqhnh mxm fsr nrdtprm skrxt nhlxntg tpdc mkmcq bqjqf lhcm hxgdp jkgf hkdls fsxf jmt fzl kshg xjcvt lqbcg jdcbc flg rnln ktsnt zbhp gqkf kphbtmkx rglsgs (contains wheat, sesame, dairy) +fmcnhq prgjph jdcbc gtsslgk xcljh fsr zdqd hnh bzlnnv krhmfb mknsj nrdtprm kgpbh lpm tnvtm zbhp fzckq xcsxh lvft hqhnh hcrsbr jfm bsgnsc qfgbx mgbv lsll qjn hrtd tkvddn sdclrlb dscm lxgxp jjdgtt kqxz zjlz tlv xjksh fdqp ptcnh rglsgs dvjrrkv flg ntbqk bsdc xjqkbq gdljd jmt zjkt gdmv fjqv nxcrg zczht bbxsn nkgzzg zmnflgt skrxt ndnlm brhmkh glj zfqhnt tkxxdnh gqkf (contains peanuts, shellfish) +svzfl bdfmncs mlcvjc xjksh fsr shc ssk mknsj tkqp znzx hqhnh zdqd jjmmn svjp ndnlm lctltv tkvddn bzlnnv jrspd kssncfd zjlz pvpfn fdjrml tgkgj nrgn nvnx bqjqf hpsrqbl hnh rnln zjkt fdqp zlfm xjcvt gbmv tkxxdnh kgdvd mgbv dftg jdcbc fnkdvt tvgcv pkrdz zkhpc lqbcg jmt kvhbj nxcrg nsnzxsc gzhlbn zbhp gdljd skrxt skkt mv qjktms dvjrrkv (contains shellfish) +zjlz gzthtlg vchxzh zfqhnt dftg bdfmncs ndnlm dvjrrkv vhbjp shc znzx fdqp fsr svjp nrdtprm tgkxxjm zbhp nxcsxc ndvnj jjdgtt qjktms mhqxk skrxt rglsgs pvpfn xvzlpx jfm prgjph mlcvjc fmcnhq gppfld tvgcv qszr pvnr bsdc bqjqf jxftql hpsrqbl qjn zkhpc qzln crjddsgj lsll bgjcg fdjrml tgxvz ssk lpm brhmkh zczht zcxthb jrspd ltjt lxgxp lqbcg xcljh dgdn gdljd rfcl rqxfdd tpdc (contains nuts, sesame, dairy) +qjn nrgn pvpfn bsgnsc xxbnf jvgbct pfhfb lqbcg zsggkm xbdhth lvtj xcljh tlv lsll lqgn nrlbfc qckqc hrtd shc sgdlhb zcxthb ssk bdfmncs hkdls tnvtm nxbn jfm hnnmrxh dvjrrkv skrxt jdcbc ndvnj jjdgtt jjmmn gtdb hjn tmlm gdljd ndnlm nhlxntg hnh kpzbxfp bgjs fsr jqlp qjktms zczht rnsqjkq zbhp vhbjp brjcp (contains wheat) +hqhnh fsr zbhp nrgn zlfm ndvnj nkgzzg kgdvd ssk qckqc sdclrlb ptcnh bpvmb brhmkh dvjrrkv rpqss fnkdvt lfgh gdljd tvgcv nxcsxc dmjzc fmcnhq qzln sgdlhb qjn zmnflgt vchxzh tkvddn xcljh dgdn bgjs hhxch pfhfb lqbcg kscd lhcm nrlbfc pkrdz htxvfq skrxt znzx ntbqk hkdls ktsnt bzlnnv rnsqjkq ndnlm sgqrvd tlv hcc zjlz gzthtlg jkgf svzfl tkxxdnh pvpfn nxbn ccn gzhlbn rqxfdd qfgbx rnln bqjqf qrdpc kgfld hnvhqczc gnq knfx tmlm nvnx zdqd zsggkm hjn jqlp gqkf bgjcg fdjrml (contains shellfish, dairy, sesame) +dmjzc qgl jjmmn mgbv qjktms qszr zlfm kgfld qkbm xjksh hnvhqczc xjcvt fsxj hjn fjqv rglsgs zbhp ccn kshg bsdc pvnr bgjcg nvnx hnnmrxh cntfq rpgrk gqkf shc nxbn qrdpc jrspd ktsnt brjcp dvjrrkv tgkxxjm jkgf kgpbh kgdvd zfqhnt lfgh ncksb nrdtprm vchxzh fsxf zdqd kphbtmkx skrxt flg gtsslgk zgcf tvgcv dftg lpm nxcrg dgdn xcljh qfgbx nzxs gbmv sgdlhb gdmv jdcbc fsr zjlz ctkjrt xntpsg hcc tkqp ptcnh gdljd rfcl znzx hpsrqbl xjqkbq jfm lqbcg nqbjlf mlcvjc tgkgj xbdhth zkhpc kscd nkgzzg svzfl sm jvgbct htxvfq rnsqjkq hnh mkmcq (contains wheat, sesame) +rnsqjkq zsggkm jqlp zdmhtpg bpvmb svjp pkrdz fsxf tkxxdnh zczht dcvtrq ndnlm cntfq jfm nkgzzg rqxfdd nrlbfc bzlnnv mkmcq fjqv tpdc hnh gtdb nxbn bbxsn mgbv pvpfn ncrn qfgbx sgqrvd knfx xjcvt brhmkh tvgcv gqkf prgjph qgl nvnx hqhnh dvjrrkv lfgh mknsj qzln jxftql kscd gtsslgk kpzbxfp hjn xcsxh gnq dmjzc xjksh tgkxxjm gzthtlg rzhktt zjlz kphbtmkx fsr fdqp sm bbtn lqbcg crjddsgj shc zbhp rglsgs nkcl hxgdp rfcl kgfld qrdpc skrxt gdljd znzx drj mlcvjc (contains shellfish, nuts, dairy) +svzfl fsxj jjmmn chjqncr lqbcg mxm zkhpc rqxfdd gnq kshg zczht gdljd ndvnj fzl rfcl dftg qbvxrbs qfgbx ndnlm mlcvjc mgbv bgjcg bpvmb vhbjp htxvfq lpm nrdtprm hnvhqczc gppfld brjcp jkgf rnsqjkq fzckq rglsgs dmjzc skrxt nsnzxsc kssncfd xcljh zbhp tgkgj kphbtmkx dgdn fsr knfx zdqd jqlp zfqhnt svjp (contains dairy) +nrlbfc bgc hhxch lsll qfgbx bsdc hqhnh tnvtm gnnzj gtdb dmjzc fsr lqbcg hrtd kvqq lgjsd jjmmn xjksh ncksb jvgbct vchxzh ndnlm htxvfq zkhpc fsxj ctkjrt lxgxp gdljd mgbv sdclrlb hnh kscd gzhlbn zdqd flg ncrn ckzg vhbjp mv jfm ptcnh gbmv sm kphbtmkx hcrsbr rpqss skrxt kgpbh kssncfd lvft bgjcg zczht bgjs nrdtprm xcljh bpvmb qckqc nzxs kqxz gdmv bzlnnv ndvnj jxftql hkdls jkgf xjqkbq hnvhqczc lfgh prgj mlcvjc pfhfb zbhp dgdn qrdpc nvnx prgjph bdfmncs nxcsxc tmlm jqlp tkqp sgdlhb fnkdvt qjn fzckq bsgnsc qbvxrbs (contains shellfish, peanuts, dairy) +bzlnnv zcxthb ndnlm jrspd lctltv mvtkk zjkt hqhnh fjqv gppfld zbhp sgdlhb knfx qfgbx hkdls jqlp pkrdz jxftql kvqq zkhpc gbmv fdjrml sgqrvd fmcnhq dcvtrq hnnmrxh tpdc kscd skrxt bsdc qzln xcljh lqbcg pvnr rpqss qckqc shc rnsqjkq dvjrrkv qrdpc znzx mgbv ssk gtsslgk bgjcg kqxz pvpfn hnvhqczc ptcnh bpvmb bbxsn hrtd hvrrhc gnq bgjs nxbn nxcsxc tkvddn qgl ndvnj (contains shellfish, nuts, wheat) +tgkgj kgpbh brhmkh bbxsn rnln mgbv bpvmb pvpfn rqxfdd hrtd kpzbxfp gtdb bbtn dgdn gfzjc kshg ltjt flg nrgn qrdpc chjqncr jrspd nrdtprm crjddsgj bdfmncs bhghks ncksb hkdls zlfm dvjrrkv gtsslgk sgqrvd sgdlhb xntpsg zbhp dcvtrq lxgxp gfq kphbtmkx lqbcg bqjqf qjn zkhpc xbdhth qzln bgjcg jkgf ncrn nxbn znzx nxcsxc brjcp nqbjlf zdmhtpg tgxvz fsr nrlbfc prgjph gppfld qkbm xcljh rzhktt ndvnj ndnlm fjqv hvrrhc (contains peanuts, dairy, soy) +tpdc nkcl nqbjlf ncksb crjddsgj prgj htxvfq gtdb bzlnnv nvnx hkdls fzl dvjrrkv sdclrlb tkqp xcsxh bqjqf hrtd dscm pfhfb svjp rqxfdd hvrrhc nrdtprm mgbv xjqkbq zkhpc zczht rfcl fsr rnsqjkq zbhp nhlxntg ndnlm jqlp bsdc hjn ntbqk gtsslgk brjcp rzhktt tlv tgkxxjm knfx ssk xjksh nxcrg dmjzc kgpbh nrgn lvtj svzfl shc mlcvjc lgjsd gbmv kvqq mhqxk nxcsxc gzhlbn tmlm zcxthb zfqhnt qpp xcljh lctltv hcc kscd fjqv mxm qrdpc zdmhtpg kvhbj skrxt qszr ptcnh xvzlpx zgcf dcvtrq bbtn zlfm jjdgtt jxftql fdqp xntpsg (contains fish, shellfish, sesame) +fsr dvjrrkv ckzg zjlz cntfq hcc nqbjlf svzfl ssk vchxzh nkcl zbhp mgbv hcrsbr fsxj xcsxh ccn rpgrk bhghks qckqc ptcnh gdljd hxgdp qkbm mvtkk rnsqjkq rnln prgjph gppfld dftg mlcvjc gtsslgk bgjcg bgc jdcbc zczht lctltv gfzjc svjp xvzlpx sdclrlb skrxt qfgbx nxcrg dcvtrq shc sgqrvd tgkgj kphbtmkx fzckq bqjqf crjddsgj nhlxntg jqlp gzthtlg zgcf ctkjrt zmnflgt bbtn drj ndnlm rpqss lvft xcljh (contains shellfish) +pkrdz ndvnj znzx xjksh zbhp hrtd kscd kgdvd ctkjrt zsggkm fzl zjkt zdmhtpg xcsxh tkqp lqbcg kssncfd bbxsn bzlnnv mgbv kgpbh krhmfb nsnzxsc ssk prgjph fmcnhq lfgh bgjcg fsr bbtn brjcp kqxz nxcrg skrxt rfcl kvqq brhmkh qbvxrbs hpsrqbl lgjsd kphbtmkx nzxs ndnlm bsgnsc mv xvzlpx ncksb nrgn rpqss tmlm nkcl dvjrrkv tnvtm lpm xbdhth sgqrvd lxgxp ktsnt mkmcq nhlxntg (contains fish, shellfish, nuts) From 0be38033f42adf995348bfe67490ac77df5e4a69 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 21 Dec 2020 12:04:18 +0100 Subject: [PATCH 109/129] 2020: d21: ex1: add solution --- 2020/d21/ex1/ex1.py | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 2020/d21/ex1/ex1.py diff --git a/2020/d21/ex1/ex1.py b/2020/d21/ex1/ex1.py new file mode 100755 index 0000000..f305249 --- /dev/null +++ b/2020/d21/ex1/ex1.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +import functools +import re +import sys +from collections import defaultdict +from copy import deepcopy +from typing import Dict, List, Set, Tuple + + +def parse(raw: List[str]) -> Tuple[List[Set[str]], List[Set[str]]]: + def parse_ingredients(line: str) -> Set[str]: + pos = line.find(" (contains ") + if pos != -1: + line = line[:pos] + return set(line.split()) + + def parse_allergens(line: str) -> Set[str]: + pos = line.find("(contains ") + if pos == -1: + return set() + return set(re.findall("([^ ]+)[,\\)]", line)) + + ingredients = [] + allergens = [] + + for line in raw: + ingredients.append(parse_ingredients(line)) + allergens.append(parse_allergens(line)) + + return ingredients, allergens + + +def find_allergens( + ingredients: List[Set[str]], allergens: List[Set[str]] +) -> Dict[str, Set[str]]: + all_ingredients = functools.reduce(lambda lhs, rhs: lhs | rhs, ingredients) + possibilities: Dict[str, Set[str]] = defaultdict(lambda: deepcopy(all_ingredients)) + + for ing, all in zip(ingredients, allergens): + for allergen in all: + possibilities[allergen] &= set(ing) + + return dict(possibilities) + + +def solve(raw: List[str]) -> int: + ingredients, allergens = parse(raw) + possibilities = functools.reduce( + lambda lhs, rhs: lhs | rhs, find_allergens(ingredients, allergens).values() + ) + + return sum( + bool(ingredient not in possibilities) for i in ingredients for ingredient in i + ) + + +def main() -> None: + input = [line.strip() for line in sys.stdin] + print(solve(input)) + + +if __name__ == "__main__": + main() From e8a8d36ac9cf8683da845ae577c93b888a642f8e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 21 Dec 2020 12:04:25 +0100 Subject: [PATCH 110/129] 2020: d21: ex2: add input --- 2020/d21/ex2/input | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 2020/d21/ex2/input diff --git a/2020/d21/ex2/input b/2020/d21/ex2/input new file mode 100644 index 0000000..3860abd --- /dev/null +++ b/2020/d21/ex2/input @@ -0,0 +1,40 @@ +zdmhtpg mlcvjc kgdvd htxvfq lxgxp kqxz pfhfb fnkdvt ccn vhbjp hqhnh xcljh ndnlm shc ncrn nrdtprm skrxt qrdpc dcvtrq gdmv nxcrg hhxch mv dscm qzln zjlz qkbm dmjzc fjqv jqlp zcxthb sdclrlb bbtn jrspd lqbcg gdljd mvtkk zbhp hcc ntbqk lvft glj fsr hnh nvnx dvjrrkv fdqp lctltv hjn mknsj gtsslgk (contains sesame, shellfish, dairy) +gtdb nxcrg fzl gtsslgk sgdlhb fzckq mknsj kscd dgdn svzfl mlcvjc ntbqk ctkjrt gdmv tkvddn rzhktt zgcf jfm gzhlbn kphbtmkx mgbv pkrdz fsr drj lqgn tgkgj ndnlm zczht tlv qkbm ccn hhxch lgjsd dvjrrkv qfgbx rqxfdd hrtd ktsnt jmt kgfld mxm knfx kshg nhlxntg zdmhtpg qpp mv ssk tgxvz brjcp skrxt xjksh fsxf tpdc crjddsgj hcrsbr bgc jqlp dmjzc hxgdp xcljh xjqkbq hnh bsgnsc gqkf bzlnnv jjmmn gbmv zdqd zbhp (contains dairy) +hxgdp nkgzzg tgxvz tgkgj hqhnh fdjrml gnnzj fsxj zbhp rqxfdd ndnlm fsr nrgn hhxch gnq sgqrvd sm qjktms jjmmn xcljh qzln jqlp nxcrg bsgnsc jxftql lxgxp kgfld jmt ntbqk kvqq fnkdvt gppfld flg kscd jjdgtt nvnx vhbjp nhlxntg zkhpc bgjcg tpdc jkgf tnvtm rnln mgbv nrdtprm cntfq brhmkh rnsqjkq mv dvjrrkv crjddsgj mxm nqbjlf pkrdz xvzlpx dmjzc brjcp hcrsbr nkcl skrxt zfqhnt rglsgs pfhfb nsnzxsc ncrn fzckq rzhktt dcvtrq zgcf qgl (contains soy, wheat, sesame) +sgqrvd dvjrrkv qszr brhmkh znzx tkvddn mgbv kgpbh gtdb gdmv zjkt zdqd mhqxk cntfq hrtd sgdlhb lxgxp zbhp bgjs hxgdp rfcl lvft qgl ndvnj glj ptcnh xjqkbq zkhpc bgc rnln xntpsg xvzlpx zfqhnt xxbnf ntbqk tgkxxjm ncksb flg nrgn kqxz hkdls gqkf fjqv qpp krhmfb fdjrml tmlm tpdc rpqss qzln ckzg xcljh jdcbc kgfld ndnlm kvhbj svzfl jfm nrlbfc tkxxdnh fsr qjn lqbcg sdclrlb nxcrg gnq vchxzh rzhktt tvgcv (contains shellfish) +pfhfb rpqss bzlnnv vchxzh ctkjrt hjn ckzg hpsrqbl nzxs zcxthb jmt lqbcg ndvnj qbvxrbs dvjrrkv jvgbct zjkt ndnlm nrgn mxm xcljh rzhktt fnkdvt hcc knfx tgkxxjm hqhnh bhghks kgfld tkqp qgl tkvddn gzhlbn rglsgs jjdgtt kvqq gfq zmnflgt fsr qjktms ssk jdcbc kshg dgdn jfm gzthtlg mkmcq tpdc nxcrg mgbv xjqkbq qkbm qpp rnln zbhp chjqncr sm jxftql xjksh tnvtm gbmv tgxvz zczht tkxxdnh kssncfd ptcnh bdfmncs mvtkk rfcl zkhpc qjn xxbnf gdmv fzl lxgxp mhqxk (contains soy, dairy) +xjqkbq xvzlpx nqbjlf qbvxrbs gtsslgk bqjqf sdclrlb ccn qpp nsnzxsc zmnflgt pkrdz ndnlm bsgnsc zgcf zbhp tgkgj jfm lvft nrgn xcljh shc bpvmb ltjt jjdgtt dvjrrkv ckzg mgbv sm hxgdp fsxf nhlxntg kqxz kvqq gzthtlg pfhfb htxvfq nvnx jxftql lgjsd sgqrvd skrxt cntfq glj bgjs mxm bbxsn rpgrk tmlm fsr rqxfdd bgjcg qkbm fdqp hpsrqbl gppfld vchxzh svjp qjktms rnsqjkq nxcrg mv tgxvz krhmfb nxcsxc zcxthb hcrsbr qjn tnvtm qrdpc lvtj qfgbx fjqv rpqss nkgzzg (contains fish, wheat, sesame) +jdcbc prgj rnln zdqd zbhp cntfq mgbv gfq dgdn sm gdmv hkdls hnvhqczc ltjt ckzg skkt tkvddn lsll ndnlm flg nxcrg kgpbh zjlz dvjrrkv zgcf mhqxk gnq qgl ccn hcc hvrrhc bgc rpqss gqkf hqhnh nxbn bsgnsc lqgn gzthtlg xcljh jxftql nrdtprm bdfmncs bhghks kgfld zczht hrtd lqbcg rqxfdd bbtn dmjzc fsr mkmcq zkhpc (contains sesame) +nqbjlf dcvtrq cntfq sdclrlb kvhbj skkt jvgbct xjqkbq knfx lsll zdmhtpg hnh fnkdvt gtdb tgxvz xjksh gzthtlg bhghks qpp zgcf ptcnh mvtkk pfhfb jjmmn ktsnt kpzbxfp tgkgj glj rfcl fsr fsxf lqgn gppfld ssk mlcvjc mhqxk kqxz kshg jjdgtt tvgcv xcljh qszr prgj gfzjc jmt qrdpc hhxch bgc mgbv zbhp kssncfd nhlxntg hkdls bgjs gfq nxcrg hcc fdqp lpm jrspd bsdc nrgn dscm bzlnnv bpvmb qjn nkgzzg rglsgs fjqv xvzlpx xxbnf qjktms xcsxh lqbcg bdfmncs qbvxrbs nkcl skrxt hxgdp ndnlm vhbjp nxcsxc flg nxbn kgpbh (contains soy, wheat, peanuts) +zjlz jdcbc nkcl rpqss gqkf lsll flg zbhp ltjt jmt fzckq rnln mknsj ccn qkbm chjqncr lfgh bsdc bzlnnv bbtn fsr skrxt kvhbj hpsrqbl kgdvd lpm dvjrrkv ptcnh tnvtm sgdlhb rfcl gtdb tvgcv rpgrk mkmcq hvrrhc qjktms bsgnsc zsggkm pvnr shc zcxthb lhcm bqjqf fzl rnsqjkq lqgn brhmkh jkgf mv xntpsg mgbv fdjrml dgdn mhqxk ktsnt xcljh qfgbx tkvddn xjksh lqbcg pkrdz brjcp bbxsn (contains fish, peanuts) +xjcvt kgfld gbmv fsxj bqjqf qgl rnln hcrsbr nxbn zcxthb zfqhnt skrxt tgkxxjm dscm hkdls dvjrrkv lvtj gdljd zmnflgt pkrdz xcljh bsgnsc zjkt zkhpc xxbnf tpdc znzx tgkgj qszr bbxsn qfgbx rzhktt rfcl xcsxh ctkjrt bgjs mhqxk mgbv qrdpc ktsnt jjmmn fmcnhq tkxxdnh jrspd qkbm qpp qbvxrbs kshg prgjph skkt mvtkk ncksb hpsrqbl kphbtmkx dgdn ncrn fnkdvt dcvtrq mv nrdtprm kvqq zdqd gzhlbn drj vchxzh fsr nrlbfc zsggkm tlv bgc sgqrvd lctltv mlcvjc lsll hnnmrxh lfgh bgjcg ntbqk htxvfq rnsqjkq hrtd bhghks gtsslgk dftg lqbcg jqlp zbhp qjn bdfmncs (contains peanuts, sesame) +zkhpc lpm fdqp kpzbxfp hkdls mlcvjc bgjs qckqc ndnlm skrxt zdmhtpg dgdn nkgzzg qjn tvgcv brjcp bsdc kshg kgdvd xcljh crjddsgj jvgbct glj xjksh xvzlpx shc mxm gzhlbn ctkjrt ckzg fsr rnsqjkq mgbv rpgrk zdqd rnln gdljd dcvtrq fjqv fmcnhq svzfl fdjrml hrtd dmjzc nxcsxc sgdlhb mhqxk jdcbc qzln dscm zbhp bbxsn fnkdvt kgpbh zjkt tgkxxjm lhcm ptcnh skkt jqlp mv nrdtprm gtdb htxvfq cntfq tnvtm lqbcg (contains soy, nuts) +ntbqk ccn pkrdz krhmfb hkdls kgpbh bhghks bqjqf hpsrqbl bpvmb fzckq nhlxntg pfhfb xcljh bzlnnv nkgzzg cntfq zbhp jqlp ndnlm tlv qbvxrbs nrdtprm gdmv ssk mgbv gdljd dvjrrkv bsgnsc tpdc rnsqjkq znzx flg fsr zlfm zjkt nvnx glj knfx lqbcg hjn (contains wheat, sesame) +qjn sgdlhb rnsqjkq gdljd dvjrrkv nkcl jxftql kssncfd jvgbct kgfld bgc nxcsxc ndnlm nrdtprm kpzbxfp fsxf gnq vhbjp nvnx hvrrhc tgxvz nsnzxsc tvgcv xvzlpx prgjph kqxz fsr hnnmrxh lqbcg hkdls glj ctkjrt zdmhtpg qszr nhlxntg gqkf tlv hxgdp nrgn ndvnj qckqc xntpsg ltjt rnln zbhp gdmv xxbnf hhxch fnkdvt knfx xcljh kgdvd bdfmncs gfq lpm mkmcq skrxt hnvhqczc krhmfb dftg gtsslgk gzthtlg flg zgcf zkhpc brhmkh pvpfn ssk dgdn bsdc jdcbc (contains fish, sesame, dairy) +bpvmb jvgbct nrgn zbhp dvjrrkv bqjqf mkmcq xcljh fsxf mknsj kssncfd lqbcg skrxt tvgcv xbdhth tkvddn nrdtprm mhqxk chjqncr ndnlm lctltv hnnmrxh rpgrk ccn rnln jdcbc gdljd dmjzc svjp lsll bdfmncs rnsqjkq qgl prgjph hqhnh xjqkbq jjmmn hcrsbr xcsxh drj cntfq fsr bsgnsc rfcl pvnr flg tgkxxjm zczht shc (contains soy, shellfish, sesame) +mlcvjc prgj xntpsg pfhfb gtsslgk nrgn kvqq lhcm fmcnhq qgl nrdtprm hcrsbr tgkxxjm lctltv fnkdvt hjn tvgcv prgjph zjlz rpqss bzlnnv zbhp dftg mkmcq tnvtm rqxfdd mknsj fsr xjqkbq pkrdz dscm gdljd nxcrg sm svjp ndnlm zlfm bgjcg rglsgs lvft mhqxk kpzbxfp lpm rnsqjkq ccn skrxt gqkf mxm gzthtlg dmjzc flg tkqp bgjs qpp bsgnsc cntfq skkt gtdb lqbcg xcljh gnnzj hqhnh jjdgtt gfzjc zgcf brhmkh sgqrvd dvjrrkv (contains shellfish, sesame) +dvjrrkv ccn lqbcg lctltv jvgbct tkqp hxgdp lhcm zsggkm bgc qjktms zjkt nvnx nxcsxc kqxz skrxt bhghks gzthtlg chjqncr htxvfq mv rnsqjkq sgdlhb crjddsgj rglsgs nrgn ndvnj ltjt hhxch xcljh hrtd fmcnhq nkgzzg dscm ncrn zbhp mgbv prgj pfhfb tgkgj hpsrqbl kscd lxgxp bbxsn gdmv tgkxxjm glj nzxs tpdc fsr tmlm lgjsd bsgnsc qjn rqxfdd hqhnh cntfq (contains fish) +hpsrqbl brjcp qpp shc tgkxxjm bbtn xcljh gbmv znzx jkgf zcxthb jjmmn zczht bgc lvtj drj rzhktt tkxxdnh tlv dcvtrq nsnzxsc hkdls tvgcv dvjrrkv qkbm knfx zjkt mhqxk bpvmb ckzg bgjs gfzjc bhghks gtdb nzxs gnnzj sm jjdgtt zjlz rnln xjqkbq ctkjrt xvzlpx xntpsg htxvfq tmlm zdqd lqbcg fsr ndnlm rfcl kgdvd skrxt mgbv hhxch mknsj hxgdp fjqv ssk qszr hqhnh xcsxh chjqncr dmjzc crjddsgj prgjph dscm sgdlhb hjn cntfq bsgnsc qjn nvnx sdclrlb jqlp ncksb (contains sesame) +fnkdvt nxcrg sgdlhb kshg glj jvgbct tlv lgjsd qbvxrbs tgkxxjm xcsxh jfm fdjrml mgbv kvqq xbdhth fsr rpgrk qkbm hjn rfcl dftg tkxxdnh mhqxk nsnzxsc zgcf dvjrrkv fzckq prgjph lqbcg skrxt bgc hpsrqbl lsll tmlm bgjcg gtdb nvnx qszr lxgxp zbhp hcc tgxvz xjqkbq nxbn fdqp zdqd xxbnf fsxf ltjt ptcnh xcljh tkqp tkvddn nrlbfc jqlp jrspd (contains fish, peanuts) +nzxs ckzg nrlbfc nsnzxsc xbdhth pvpfn tvgcv tmlm mvtkk ncksb mhqxk ltjt zbhp fjqv rfcl tkqp lpm gzthtlg hkdls hcrsbr qckqc bhghks qgl kvhbj nkcl jmt lhcm bgjcg flg nqbjlf kvqq kqxz xcljh nrgn pvnr bzlnnv lqgn gnnzj bdfmncs ccn lvtj xjcvt dvjrrkv jjmmn qrdpc ntbqk sgqrvd kscd hcc cntfq gnq tgkgj jxftql jrspd fzl fsr lqbcg qkbm mgbv brjcp bgjs gtdb drj qjktms bqjqf hxgdp skkt prgj kssncfd xntpsg hhxch fsxf hqhnh qpp nxcsxc jvgbct qjn lfgh ndnlm mknsj zjkt mlcvjc lgjsd (contains shellfish) +qgl rnsqjkq hnnmrxh lsll nkcl fsr qjktms ndnlm krhmfb rpgrk xcljh jfm lfgh xntpsg skkt gdmv dvjrrkv zbhp kphbtmkx lhcm vhbjp mgbv zsggkm fsxf ccn nrgn nrdtprm bpvmb znzx bbtn dgdn bhghks zjkt svzfl jjmmn tlv bsgnsc bgc qkbm skrxt bgjcg fdqp ltjt rfcl bgjs rnln gtsslgk zjlz (contains wheat) +nhlxntg hqhnh qfgbx kssncfd zkhpc bdfmncs zcxthb drj sgqrvd lqgn rqxfdd hvrrhc prgj tgkgj nrdtprm skrxt jxftql fsr xcljh qpp shc zbhp qjktms zsggkm ccn chjqncr znzx pkrdz prgjph ntbqk ndnlm nrgn kgdvd tkxxdnh tpdc dvjrrkv qzln knfx nkgzzg rnsqjkq kpzbxfp bbtn tkqp mgbv rzhktt lhcm rglsgs fdqp fmcnhq gzthtlg nvnx ssk bhghks kvhbj hhxch tlv fnkdvt htxvfq zfqhnt xvzlpx lpm qszr hnnmrxh hcrsbr jqlp nsnzxsc (contains dairy, peanuts, wheat) +gfzjc hhxch rzhktt gtdb ssk zbhp zfqhnt jkgf tkqp dvjrrkv kgpbh mknsj bsdc lgjsd mgbv zcxthb hrtd nqbjlf mlcvjc hxgdp tgxvz gqkf fmcnhq tpdc lxgxp hcrsbr znzx zlfm fjqv kvqq nhlxntg zjlz brjcp zkhpc skrxt nrlbfc jdcbc qfgbx svzfl fzckq kgfld prgj gzhlbn lhcm qkbm fsxj hqhnh kscd vhbjp fsr lsll qbvxrbs gfq tnvtm lqbcg nkcl ndnlm sgqrvd xjqkbq (contains wheat, shellfish, fish) +gdmv bbxsn kvqq hnvhqczc lqbcg xjqkbq jvgbct mlcvjc gfq jrspd lxgxp jkgf tkvddn bsgnsc lqgn xcljh fsxf qjktms dscm mgbv fsr ndvnj nrdtprm jjmmn xvzlpx nkgzzg rnln nxcsxc zjkt sdclrlb nhlxntg kphbtmkx gnq zbhp fzckq zlfm hvrrhc zsggkm xcsxh ntbqk skkt jdcbc bgc bsdc prgj shc nzxs bpvmb hcc ncrn xjcvt nrlbfc jqlp ktsnt nvnx gnnzj tkqp nxbn ndnlm sgdlhb bqjqf kqxz qzln zjlz tkxxdnh bdfmncs kpzbxfp hrtd fzl skrxt sgqrvd zdmhtpg dftg fnkdvt lgjsd mv (contains nuts, fish) +nxcrg jqlp xcljh nkcl qjn rpgrk xbdhth vhbjp kqxz zfqhnt nrdtprm ltjt tkxxdnh rqxfdd fdqp bsdc gzhlbn bpvmb ndnlm bbtn skrxt jdcbc fmcnhq pkrdz zsggkm rzhktt ccn gbmv ncrn rglsgs dmjzc sgdlhb prgjph lpm zcxthb dftg qjktms pvnr hnnmrxh kssncfd bdfmncs bhghks lhcm lgjsd ssk bgc fsr gfzjc rnsqjkq zbhp lqbcg krhmfb mkmcq zlfm brhmkh xntpsg hnh bsgnsc dvjrrkv tvgcv sm fdjrml prgj hhxch tpdc fsxf nkgzzg nzxs gnq tmlm (contains dairy) +nrlbfc nxcsxc jvgbct dvjrrkv prgjph gqkf ndnlm lhcm mvtkk xcsxh gtsslgk mgbv kgpbh zbhp qbvxrbs kshg gfq ktsnt bbxsn hjn jfm jxftql jmt xbdhth xcljh zmnflgt kgfld nrgn fnkdvt fdqp skrxt svzfl bgjcg sgqrvd ssk svjp sgdlhb vchxzh kgdvd dgdn xntpsg tpdc zjlz zgcf rnsqjkq zlfm chjqncr tmlm dftg tgxvz jkgf lpm hcc qjn tkxxdnh lqbcg kscd lctltv pvnr ntbqk lsll qszr mv hvrrhc fjqv (contains wheat) +vhbjp fsxj jxftql tkxxdnh nzxs fnkdvt fmcnhq lgjsd chjqncr xcljh brjcp hrtd kssncfd ssk mgbv xvzlpx bgjs rpgrk kgfld gbmv ndvnj ccn rnsqjkq xjksh ncrn brhmkh lxgxp qzln zdmhtpg tkvddn lsll nrgn pvpfn lqgn nxbn lvtj dvjrrkv dscm bsdc hqhnh mxm fsr nrdtprm skrxt nhlxntg tpdc mkmcq bqjqf lhcm hxgdp jkgf hkdls fsxf jmt fzl kshg xjcvt lqbcg jdcbc flg rnln ktsnt zbhp gqkf kphbtmkx rglsgs (contains wheat, sesame, dairy) +fmcnhq prgjph jdcbc gtsslgk xcljh fsr zdqd hnh bzlnnv krhmfb mknsj nrdtprm kgpbh lpm tnvtm zbhp fzckq xcsxh lvft hqhnh hcrsbr jfm bsgnsc qfgbx mgbv lsll qjn hrtd tkvddn sdclrlb dscm lxgxp jjdgtt kqxz zjlz tlv xjksh fdqp ptcnh rglsgs dvjrrkv flg ntbqk bsdc xjqkbq gdljd jmt zjkt gdmv fjqv nxcrg zczht bbxsn nkgzzg zmnflgt skrxt ndnlm brhmkh glj zfqhnt tkxxdnh gqkf (contains peanuts, shellfish) +svzfl bdfmncs mlcvjc xjksh fsr shc ssk mknsj tkqp znzx hqhnh zdqd jjmmn svjp ndnlm lctltv tkvddn bzlnnv jrspd kssncfd zjlz pvpfn fdjrml tgkgj nrgn nvnx bqjqf hpsrqbl hnh rnln zjkt fdqp zlfm xjcvt gbmv tkxxdnh kgdvd mgbv dftg jdcbc fnkdvt tvgcv pkrdz zkhpc lqbcg jmt kvhbj nxcrg nsnzxsc gzhlbn zbhp gdljd skrxt skkt mv qjktms dvjrrkv (contains shellfish) +zjlz gzthtlg vchxzh zfqhnt dftg bdfmncs ndnlm dvjrrkv vhbjp shc znzx fdqp fsr svjp nrdtprm tgkxxjm zbhp nxcsxc ndvnj jjdgtt qjktms mhqxk skrxt rglsgs pvpfn xvzlpx jfm prgjph mlcvjc fmcnhq gppfld tvgcv qszr pvnr bsdc bqjqf jxftql hpsrqbl qjn zkhpc qzln crjddsgj lsll bgjcg fdjrml tgxvz ssk lpm brhmkh zczht zcxthb jrspd ltjt lxgxp lqbcg xcljh dgdn gdljd rfcl rqxfdd tpdc (contains nuts, sesame, dairy) +qjn nrgn pvpfn bsgnsc xxbnf jvgbct pfhfb lqbcg zsggkm xbdhth lvtj xcljh tlv lsll lqgn nrlbfc qckqc hrtd shc sgdlhb zcxthb ssk bdfmncs hkdls tnvtm nxbn jfm hnnmrxh dvjrrkv skrxt jdcbc ndvnj jjdgtt jjmmn gtdb hjn tmlm gdljd ndnlm nhlxntg hnh kpzbxfp bgjs fsr jqlp qjktms zczht rnsqjkq zbhp vhbjp brjcp (contains wheat) +hqhnh fsr zbhp nrgn zlfm ndvnj nkgzzg kgdvd ssk qckqc sdclrlb ptcnh bpvmb brhmkh dvjrrkv rpqss fnkdvt lfgh gdljd tvgcv nxcsxc dmjzc fmcnhq qzln sgdlhb qjn zmnflgt vchxzh tkvddn xcljh dgdn bgjs hhxch pfhfb lqbcg kscd lhcm nrlbfc pkrdz htxvfq skrxt znzx ntbqk hkdls ktsnt bzlnnv rnsqjkq ndnlm sgqrvd tlv hcc zjlz gzthtlg jkgf svzfl tkxxdnh pvpfn nxbn ccn gzhlbn rqxfdd qfgbx rnln bqjqf qrdpc kgfld hnvhqczc gnq knfx tmlm nvnx zdqd zsggkm hjn jqlp gqkf bgjcg fdjrml (contains shellfish, dairy, sesame) +dmjzc qgl jjmmn mgbv qjktms qszr zlfm kgfld qkbm xjksh hnvhqczc xjcvt fsxj hjn fjqv rglsgs zbhp ccn kshg bsdc pvnr bgjcg nvnx hnnmrxh cntfq rpgrk gqkf shc nxbn qrdpc jrspd ktsnt brjcp dvjrrkv tgkxxjm jkgf kgpbh kgdvd zfqhnt lfgh ncksb nrdtprm vchxzh fsxf zdqd kphbtmkx skrxt flg gtsslgk zgcf tvgcv dftg lpm nxcrg dgdn xcljh qfgbx nzxs gbmv sgdlhb gdmv jdcbc fsr zjlz ctkjrt xntpsg hcc tkqp ptcnh gdljd rfcl znzx hpsrqbl xjqkbq jfm lqbcg nqbjlf mlcvjc tgkgj xbdhth zkhpc kscd nkgzzg svzfl sm jvgbct htxvfq rnsqjkq hnh mkmcq (contains wheat, sesame) +rnsqjkq zsggkm jqlp zdmhtpg bpvmb svjp pkrdz fsxf tkxxdnh zczht dcvtrq ndnlm cntfq jfm nkgzzg rqxfdd nrlbfc bzlnnv mkmcq fjqv tpdc hnh gtdb nxbn bbxsn mgbv pvpfn ncrn qfgbx sgqrvd knfx xjcvt brhmkh tvgcv gqkf prgjph qgl nvnx hqhnh dvjrrkv lfgh mknsj qzln jxftql kscd gtsslgk kpzbxfp hjn xcsxh gnq dmjzc xjksh tgkxxjm gzthtlg rzhktt zjlz kphbtmkx fsr fdqp sm bbtn lqbcg crjddsgj shc zbhp rglsgs nkcl hxgdp rfcl kgfld qrdpc skrxt gdljd znzx drj mlcvjc (contains shellfish, nuts, dairy) +svzfl fsxj jjmmn chjqncr lqbcg mxm zkhpc rqxfdd gnq kshg zczht gdljd ndvnj fzl rfcl dftg qbvxrbs qfgbx ndnlm mlcvjc mgbv bgjcg bpvmb vhbjp htxvfq lpm nrdtprm hnvhqczc gppfld brjcp jkgf rnsqjkq fzckq rglsgs dmjzc skrxt nsnzxsc kssncfd xcljh zbhp tgkgj kphbtmkx dgdn fsr knfx zdqd jqlp zfqhnt svjp (contains dairy) +nrlbfc bgc hhxch lsll qfgbx bsdc hqhnh tnvtm gnnzj gtdb dmjzc fsr lqbcg hrtd kvqq lgjsd jjmmn xjksh ncksb jvgbct vchxzh ndnlm htxvfq zkhpc fsxj ctkjrt lxgxp gdljd mgbv sdclrlb hnh kscd gzhlbn zdqd flg ncrn ckzg vhbjp mv jfm ptcnh gbmv sm kphbtmkx hcrsbr rpqss skrxt kgpbh kssncfd lvft bgjcg zczht bgjs nrdtprm xcljh bpvmb qckqc nzxs kqxz gdmv bzlnnv ndvnj jxftql hkdls jkgf xjqkbq hnvhqczc lfgh prgj mlcvjc pfhfb zbhp dgdn qrdpc nvnx prgjph bdfmncs nxcsxc tmlm jqlp tkqp sgdlhb fnkdvt qjn fzckq bsgnsc qbvxrbs (contains shellfish, peanuts, dairy) +bzlnnv zcxthb ndnlm jrspd lctltv mvtkk zjkt hqhnh fjqv gppfld zbhp sgdlhb knfx qfgbx hkdls jqlp pkrdz jxftql kvqq zkhpc gbmv fdjrml sgqrvd fmcnhq dcvtrq hnnmrxh tpdc kscd skrxt bsdc qzln xcljh lqbcg pvnr rpqss qckqc shc rnsqjkq dvjrrkv qrdpc znzx mgbv ssk gtsslgk bgjcg kqxz pvpfn hnvhqczc ptcnh bpvmb bbxsn hrtd hvrrhc gnq bgjs nxbn nxcsxc tkvddn qgl ndvnj (contains shellfish, nuts, wheat) +tgkgj kgpbh brhmkh bbxsn rnln mgbv bpvmb pvpfn rqxfdd hrtd kpzbxfp gtdb bbtn dgdn gfzjc kshg ltjt flg nrgn qrdpc chjqncr jrspd nrdtprm crjddsgj bdfmncs bhghks ncksb hkdls zlfm dvjrrkv gtsslgk sgqrvd sgdlhb xntpsg zbhp dcvtrq lxgxp gfq kphbtmkx lqbcg bqjqf qjn zkhpc xbdhth qzln bgjcg jkgf ncrn nxbn znzx nxcsxc brjcp nqbjlf zdmhtpg tgxvz fsr nrlbfc prgjph gppfld qkbm xcljh rzhktt ndvnj ndnlm fjqv hvrrhc (contains peanuts, dairy, soy) +tpdc nkcl nqbjlf ncksb crjddsgj prgj htxvfq gtdb bzlnnv nvnx hkdls fzl dvjrrkv sdclrlb tkqp xcsxh bqjqf hrtd dscm pfhfb svjp rqxfdd hvrrhc nrdtprm mgbv xjqkbq zkhpc zczht rfcl fsr rnsqjkq zbhp nhlxntg ndnlm jqlp bsdc hjn ntbqk gtsslgk brjcp rzhktt tlv tgkxxjm knfx ssk xjksh nxcrg dmjzc kgpbh nrgn lvtj svzfl shc mlcvjc lgjsd gbmv kvqq mhqxk nxcsxc gzhlbn tmlm zcxthb zfqhnt qpp xcljh lctltv hcc kscd fjqv mxm qrdpc zdmhtpg kvhbj skrxt qszr ptcnh xvzlpx zgcf dcvtrq bbtn zlfm jjdgtt jxftql fdqp xntpsg (contains fish, shellfish, sesame) +fsr dvjrrkv ckzg zjlz cntfq hcc nqbjlf svzfl ssk vchxzh nkcl zbhp mgbv hcrsbr fsxj xcsxh ccn rpgrk bhghks qckqc ptcnh gdljd hxgdp qkbm mvtkk rnsqjkq rnln prgjph gppfld dftg mlcvjc gtsslgk bgjcg bgc jdcbc zczht lctltv gfzjc svjp xvzlpx sdclrlb skrxt qfgbx nxcrg dcvtrq shc sgqrvd tgkgj kphbtmkx fzckq bqjqf crjddsgj nhlxntg jqlp gzthtlg zgcf ctkjrt zmnflgt bbtn drj ndnlm rpqss lvft xcljh (contains shellfish) +pkrdz ndvnj znzx xjksh zbhp hrtd kscd kgdvd ctkjrt zsggkm fzl zjkt zdmhtpg xcsxh tkqp lqbcg kssncfd bbxsn bzlnnv mgbv kgpbh krhmfb nsnzxsc ssk prgjph fmcnhq lfgh bgjcg fsr bbtn brjcp kqxz nxcrg skrxt rfcl kvqq brhmkh qbvxrbs hpsrqbl lgjsd kphbtmkx nzxs ndnlm bsgnsc mv xvzlpx ncksb nrgn rpqss tmlm nkcl dvjrrkv tnvtm lpm xbdhth sgqrvd lxgxp ktsnt mkmcq nhlxntg (contains fish, shellfish, nuts) From be4a02ce443f58103e1d972a4e33358e6bd4efce Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 21 Dec 2020 12:04:32 +0100 Subject: [PATCH 111/129] 2020: d21: ex2: add solution --- 2020/d21/ex2/ex2.py | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 2020/d21/ex2/ex2.py diff --git a/2020/d21/ex2/ex2.py b/2020/d21/ex2/ex2.py new file mode 100755 index 0000000..4856636 --- /dev/null +++ b/2020/d21/ex2/ex2.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import functools +import re +import sys +from collections import defaultdict +from copy import deepcopy +from typing import Dict, List, Set, Tuple + + +def parse(raw: List[str]) -> Tuple[List[Set[str]], List[Set[str]]]: + def parse_ingredients(line: str) -> Set[str]: + pos = line.find(" (contains ") + if pos != -1: + line = line[:pos] + return set(line.split()) + + def parse_allergens(line: str) -> Set[str]: + pos = line.find("(contains ") + if pos == -1: + return set() + return set(re.findall("([^ ]+)[,\\)]", line)) + + ingredients = [] + allergens = [] + + for line in raw: + ingredients.append(parse_ingredients(line)) + allergens.append(parse_allergens(line)) + + return ingredients, allergens + + +def find_allergens( + ingredients: List[Set[str]], allergens: List[Set[str]] +) -> Dict[str, Set[str]]: + all_ingredients = functools.reduce(lambda lhs, rhs: lhs | rhs, ingredients) + possibilities: Dict[str, Set[str]] = defaultdict(lambda: deepcopy(all_ingredients)) + + for ing, all in zip(ingredients, allergens): + for allergen in all: + possibilities[allergen] &= set(ing) + + return dict(possibilities) + + +def cross_eliminate(possibilities: Dict[str, Set[str]]) -> None: + while True: + eliminated = False + for pos in possibilities: + if len(possibilities[pos]) != 1: + continue + for other_pos in possibilities: + if other_pos == pos: + continue + if len(possibilities[other_pos] & possibilities[pos]) == 0: + continue + eliminated = True + possibilities[other_pos] -= possibilities[pos] + if not eliminated: + break + + +def solve(raw: List[str]) -> str: + ingredients, allergens = parse(raw) + possibilities = find_allergens(ingredients, allergens) + cross_eliminate(possibilities) + matches = [ + (ingredient.pop(), allergen) for allergen, ingredient in possibilities.items() + ] + matches.sort(key=lambda tup: tup[1]) + return ",".join(ingredient for ingredient, __ in matches) + + +def main() -> None: + input = [line.strip() for line in sys.stdin] + print(solve(input)) + + +if __name__ == "__main__": + main() From 7851f1158f98e24f53f28ed859769ca3407ee902 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 22 Dec 2020 13:58:53 +0100 Subject: [PATCH 112/129] 2020: d22: ex1: add input --- 2020/d22/ex1/input | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 2020/d22/ex1/input diff --git a/2020/d22/ex1/input b/2020/d22/ex1/input new file mode 100644 index 0000000..4aed5fe --- /dev/null +++ b/2020/d22/ex1/input @@ -0,0 +1,53 @@ +Player 1: +31 +24 +5 +33 +7 +12 +30 +22 +48 +14 +16 +26 +18 +45 +4 +42 +25 +20 +46 +21 +40 +38 +34 +17 +50 + +Player 2: +1 +3 +41 +8 +37 +35 +28 +39 +43 +29 +10 +27 +11 +36 +49 +32 +2 +23 +19 +9 +13 +15 +47 +6 +44 From 84ac5bbb71889676f8ccbaf0dd5938e075662a30 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 22 Dec 2020 13:59:01 +0100 Subject: [PATCH 113/129] 2020: d22: ex1: add solution --- 2020/d22/ex1/ex1.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 2020/d22/ex1/ex1.py diff --git a/2020/d22/ex1/ex1.py b/2020/d22/ex1/ex1.py new file mode 100755 index 0000000..968e4ae --- /dev/null +++ b/2020/d22/ex1/ex1.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import itertools +import sys +from collections import deque +from typing import Deque, List, Tuple + +Deck = Deque[int] + + +def parse_decks(raw: List[str]) -> Tuple[Deck, Deck]: + deck_1 = deque(int(n) for n in itertools.takewhile(len, raw[1:])) + deck_2 = deque( + int(n) for n in itertools.islice(itertools.dropwhile(len, raw[1:]), 2, None) + ) + return deck_1, deck_2 + + +def play(deck_1: Deck, deck_2: Deck) -> Tuple[int, Deck]: + while len(deck_1) and len(deck_2): + left, right = deck_1.popleft(), deck_2.popleft() + if left > right: + deck_1.extend((left, right)) + else: + deck_2.extend((right, left)) + return (1, deck_1) if len(deck_1) else (2, deck_2) + + +def solve(raw: List[str]) -> int: + __, deck = play(*parse_decks(raw)) + + score = sum((i) * val for i, val in enumerate(reversed(deck), 1)) + + return score + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main() From dddd70813aa2e3c183f26d17302b483c115b9750 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 22 Dec 2020 13:59:09 +0100 Subject: [PATCH 114/129] 2020: d22: ex2: add input --- 2020/d22/ex2/input | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 2020/d22/ex2/input diff --git a/2020/d22/ex2/input b/2020/d22/ex2/input new file mode 100644 index 0000000..4aed5fe --- /dev/null +++ b/2020/d22/ex2/input @@ -0,0 +1,53 @@ +Player 1: +31 +24 +5 +33 +7 +12 +30 +22 +48 +14 +16 +26 +18 +45 +4 +42 +25 +20 +46 +21 +40 +38 +34 +17 +50 + +Player 2: +1 +3 +41 +8 +37 +35 +28 +39 +43 +29 +10 +27 +11 +36 +49 +32 +2 +23 +19 +9 +13 +15 +47 +6 +44 From 19b48862ceb6ea13db43392789d87f0dd66212db Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 22 Dec 2020 13:59:13 +0100 Subject: [PATCH 115/129] 2020: d22: ex2: add solution --- 2020/d22/ex2/ex2.py | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 2020/d22/ex2/ex2.py diff --git a/2020/d22/ex2/ex2.py b/2020/d22/ex2/ex2.py new file mode 100755 index 0000000..7b3ee6b --- /dev/null +++ b/2020/d22/ex2/ex2.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +import itertools +import sys +from collections import deque +from typing import Deque, List, Set, Tuple + +Deck = Deque[int] + + +def parse_decks(raw: List[str]) -> Tuple[Deck, Deck]: + deck_1 = deque(int(n) for n in itertools.takewhile(len, raw[1:])) + deck_2 = deque( + int(n) for n in itertools.islice(itertools.dropwhile(len, raw[1:]), 2, None) + ) + return deck_1, deck_2 + + +def play(deck_1: Deck, deck_2: Deck) -> Tuple[int, Deck]: + prev: Set[Tuple[Tuple[int, ...], Tuple[int, ...]]] = set() + + while len(deck_1) and len(deck_2): + state = (tuple(deck_1), tuple(deck_2)) + if state in prev: + return 1, deck_1 + prev |= {state} + + left, right = deck_1.popleft(), deck_2.popleft() + + if left <= len(deck_1) and right <= len(deck_2): + winner, __ = play(deque(list(deck_1)[:left]), deque(list(deck_2)[:right])) + if winner == 1: + deck_1.extend((left, right)) + else: + deck_2.extend((right, left)) + elif left > right: + deck_1.extend((left, right)) + else: + deck_2.extend((right, left)) + return (1, deck_1) if len(deck_1) else (2, deck_2) + + +def solve(raw: List[str]) -> int: + __, deck = play(*parse_decks(raw)) + + score = sum((i) * val for i, val in enumerate(reversed(deck), 1)) + + return score + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main() From 820794cc80ff739f3973e932110b1ece1347a597 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 23 Dec 2020 13:10:59 +0100 Subject: [PATCH 116/129] 2020: d23: ex1: add input --- 2020/d23/ex1/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2020/d23/ex1/input diff --git a/2020/d23/ex1/input b/2020/d23/ex1/input new file mode 100644 index 0000000..aea0f77 --- /dev/null +++ b/2020/d23/ex1/input @@ -0,0 +1 @@ +598162734 From d4c9aa4c5e71c5f7c04a5298febef387e23b0dac Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 23 Dec 2020 13:11:04 +0100 Subject: [PATCH 117/129] 2020: d23: ex1: add solution --- 2020/d23/ex1/ex1.py | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 2020/d23/ex1/ex1.py diff --git a/2020/d23/ex1/ex1.py b/2020/d23/ex1/ex1.py new file mode 100755 index 0000000..faae133 --- /dev/null +++ b/2020/d23/ex1/ex1.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +import itertools +import sys +from typing import List, Tuple + + +def solve(circle: List[int]) -> int: + def to_links(circle: List[int]) -> List[int]: + links = [-1 for __ in range(len(circle) + 1)] + cyclic = itertools.cycle(circle) + next(cyclic) # Advance it by one + for prev, cur in zip(circle, cyclic): + links[prev] = cur + return links + + def step(links: List[int], current: int) -> int: + cup0 = links[current] + cup1 = links[cup0] + cup2 = links[cup1] + + links[current] = links[cup2] # Remove 3-tuple from the linked-list + + # Find destination + dest = (current - 1) if current > 1 else (len(links) - 1) + while dest in (cup0, cup1, cup2): + dest = (dest - 1) if dest > 1 else (len(links) - 1) + + # Update our links + links[cup2], links[dest] = links[dest], cup0 + + return links[current] # What's the next value in the cycle ? + + def to_answer(links: List[int]) -> int: + next = links[1] + res = 0 + while next != 1: + res = res * 10 + next + next = links[next] + return res + + current = circle[0] + links = to_links(circle) + + for __ in range(100): + current = step(links, current) + + return to_answer(links) + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + assert len(input) == 1 + print(solve([int(c) for c in input[0]])) + + +if __name__ == "__main__": + main() From 20ee1946431d9f724c247cc8ed96013b3c4db91e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 23 Dec 2020 13:11:11 +0100 Subject: [PATCH 118/129] 2020: d23: ex2: add input --- 2020/d23/ex2/input | 1 + 1 file changed, 1 insertion(+) create mode 100644 2020/d23/ex2/input diff --git a/2020/d23/ex2/input b/2020/d23/ex2/input new file mode 100644 index 0000000..aea0f77 --- /dev/null +++ b/2020/d23/ex2/input @@ -0,0 +1 @@ +598162734 From 2418405955ef272f89d559851c1d768ac5b2effa Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 23 Dec 2020 13:11:17 +0100 Subject: [PATCH 119/129] 2020: d23: ex2: add solution --- 2020/d23/ex2/ex2.py | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 2020/d23/ex2/ex2.py diff --git a/2020/d23/ex2/ex2.py b/2020/d23/ex2/ex2.py new file mode 100755 index 0000000..90c8c81 --- /dev/null +++ b/2020/d23/ex2/ex2.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +import itertools +import sys +from typing import List, Tuple + + +def solve(circle: List[int]) -> int: + def to_links(circle: List[int]) -> List[int]: + links = [-1 for __ in range(len(circle) + 1)] + cyclic = itertools.cycle(circle) + next(cyclic) # Advance it by one + for prev, cur in zip(circle, cyclic): + links[prev] = cur + return links + + def step(links: List[int], current: int) -> int: + cup0 = links[current] + cup1 = links[cup0] + cup2 = links[cup1] + + links[current] = links[cup2] # Remove 3-tuple from the linked-list + + # Find destination + dest = (current - 1) if current > 1 else (len(links) - 1) + while dest in (cup0, cup1, cup2): + dest = (dest - 1) if dest > 1 else (len(links) - 1) + + # Update our links + links[cup2], links[dest] = links[dest], cup0 + + return links[current] # What's the next value in the cycle ? + + def to_answer(links: List[int]) -> int: + next = links[1] + return next * links[next] + + current = circle[0] + circle += [i + 1 for i in range(max(circle), 1000000)] + links = to_links(circle) + + for __ in range(10000000): + current = step(links, current) + + return to_answer(links) + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + assert len(input) == 1 + print(solve([int(c) for c in input[0]])) + + +if __name__ == "__main__": + main() From caf14a71b6bc5801d524c1a56216982d548ecfd1 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 24 Dec 2020 13:26:28 +0100 Subject: [PATCH 120/129] 2020: d24: ex1: add input --- 2020/d24/ex1/input | 471 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 471 insertions(+) create mode 100644 2020/d24/ex1/input diff --git a/2020/d24/ex1/input b/2020/d24/ex1/input new file mode 100644 index 0000000..9b35a80 --- /dev/null +++ b/2020/d24/ex1/input @@ -0,0 +1,471 @@ +swswswswneswswwwswnewswswweswnwsww +nwwewenenwnenwnwnwnwneswnwswnwnwswswnw +seneswwwswwnenwnenwswswswswsewseeww +esenesenesesesewseseswnesesweesesesese +seseseeseenesewseenwsesewswwsesenwse +eswenewnenenewneneneneenenenenwnene +nwseeseseeseseseseewseesenwseeesese +nwnwswswswweneseswwswwneswswswswswsw +senenenwnenewneneneseswneeeenenenew +eswnwnesenwnwnenwnwnwnwwnwsenwwswswenw +wswneswswseesewswseswswswnenesenenwswswne +seswseswneswswswwnwswwswseneswswswswsee +neseseswnwesesesesewswsesenesenesesesw +wwswwwsweswwwww +seswwnwneenwswneenwewneneneseenee +eswseenweswewseneeeeseeswnwnwse +swsweswswswnweswswneswwswnwswwwswswswsw +nwwnwnwnwnwnwnwnwwswwnweneswwenwnw +sewswwwwwwwweswwwwneswwnwswnw +nwneeneeneneseneseneneneneneneswnenwnene +swnenenweeneeeseswweneenenenenene +nwnwnwsenwewsesenwenwwwswwnwnesenw +swnwswswswswswsewseswnewneseswswswneesw +wwweswwswwsewswswwwwnwwesewwne +swswsweneswswswenwswnewnwswwneswseswswe +nwnesewwnwwnwwwsew +enwwwnenwnewwwwswwseeswewe +neswseswswsenwseswnwseswse +senwseneneneneneeseneswnenenenenwnenwnw +swseneswwseenwsenwneneswnewnenewene +ewwwwwwwewwwnwswwwwwwwne +eswswenwsenwnwsenenw +nwneseewseswwsewswnwnwnwwwwnewww +nwwwwwwwwewnwwswnew +neeeseeesewseeeeeeeewe +wweswnenwwnewnwnwwwewsewnwwsew +swwswwwswwewwswswnwsweswnwwwww +eseswneenwneenweseenweeseeeenw +neneswneneneneneneneneneswnenwnwnw +nwnwwnwewwswwnwwwnwsewnwwenwnw +seswswswnwswwwwswwswneswwseswnw +nwseswenwwneneneseswneenwnenenwnenwnenw +nwnenenenesewwnenwnwnesenwnwnwnwnenwnwnw +wseeeneseeeseseesesenwseseswsesese +sweseswnwseseseswseswseseseswswswse +ewwwswswsenwewnewwwenwwwnwww +nwwsewnwnwnwneswwnwesewnwwnwnwnwnwne +nenwnwnwnenenwnenwnwswswnwneenenwnwnwne +esenwneswsesesweeeeweseseeseseswnw +swswswswwsesweseswswswsw +swsweneswwseswswswwswsenewswwswseswnene +nenenewnwnenenwenwnesenwneseswnwnwnwne +nenenenewneeseneneswneneneswsenenenwne +nenenwnenwswwnweesenwsenwnwnwseswnwnwnw +seseeenwsenwswsesenwseeseeseeseswese +swneeseseneswswnwswnwwwwswswnee +seeseseseneseseswsewseenenwwneseswse +wswseseenwwswnewenwswswwwnewwsw +nenewswnwnenwnwneeneswseeneswnenwnenesene +nwswsenweweseeneseesesesesesesesee +seneswswwesenenwswseswnwseseseseseswne +wwnwwweswnwnwwweneseewnwsesenw +swswneneneneenewnesenewweenweswne +eseneseneseenenewwswseweenweenenene +nwwnwwnwsenwnwnwnwwnwwnww +swweswsewewwwwwwwwwwnewne +swswnewseseseesenewseesesesesesenwese +swswnenwnenwnwnwnwnenenenwnwwnenwseene +wnwwwwnwnwwnwwnwnwwwnwnwsenwe +nwseswwwnenwwwwesewwwwwwwnenwnw +nwswswnwswwswwnenenwnwnwnwnewnenw +seswswswnwswswswswswswswswswswswsw +neneseeneswnwnenwnwsenwnenenewne +wwwwwnenwnwnweswwnwsewwwesese +swwswswwwwseswswenwnewswwswweswnw +swwswseswswseeswswswewswswnwswswese +nwnwewsenenwnesewwwwswnwnenwswsee +seseseenwwswseneneseswswnwnewswnwsenwse +wwswwnwwwwsewwwenewnwswnwwwe +swwwwswwswwswneseswswswwnewswwse +nenenwneeswnenesweneneneeneneswsewesw +seswswswseswswswswsweenwswswwseswwsw +swswswsewneseesenwseseswseswswswnwsesw +nwwnewnwnwswnwnwswnwsenwwnwenwnenww +wswwnwwwswwwwswe +eewneeeeneeswsee +wseneseeseewseseseswsewse +wwswnwnwwnewnwsewenenwswwewswwne +seneesesesesewswswwnwseswswseseswseswsw +ewnweeeseneseeseseeneseswwwee +wwwwswwsewwwwewwwwwswnwwne +swsewswswswseswseseeswsenwseswswswsenw +nenenenenesenenenenenenewenewneswsene +newnewewwnwnwnwsewwswnwwwwesww +neseeeneneeewnee +wsenwwnwenwnwwnwnwnwwnwnwwnw +nweswenwseseswwseeenwseenwswsesewsw +wwwswwwwsewwwwwwwwne +nenwnwnwnenwnwnwnenwwnwnwnwnwnwe +eeeeeweneeseeeesweeeeew +seneseeeeewewnweseeseseseeseese +swenenenenwesweewneeeneneeeeeee +wnenwseswnwwwsenwnwwnwnwwnwwnwnwnwnw +sewwwswnwwnwwwswwnewwewwwsw +swwwwswswwswswwwswnew +esweeneeswenwnweesweneeeeswee +eenweeseneeeeeeeeeseeenenwsw +nwneswweeneseswnwswnweeesesesenwe +neneneeswnwnwnwnenenwnenene +wseewseeseseneswsenwsenewsesweseswswse +eseswneneseneenenewswwnwnenenesenenenw +seswsesesweseswseswseswwsw +nwnenenenenwnenenwsenenwwsenewnenenene +eneneneneswnenenenenenenenwneneneswnwnw +neneeneneenwnenenesweneneewsweneene +swnwnwneswnwnwseenwnwnenwenewnwnwnwwnw +swswwnwwswnwwseswewswneseneswewneswe +neswswnewwswswwwswwsewww +nwneeenwswnwsenwnwnwnwnenwswnwnwsenwnw +neeswnwnwwnwseswesweneswnw +swnenwenwnwnwnwsesenwswnwnwnwnwnwnwnwnw +swseswswnenwwwwseswwwwsw +seswneseswseswswswsewesenwsenesewsesw +eseeneswseenwewseewneeeene +swnenenenenenenewwneneswnenenesenesenw +swnenwnenwnwenenenwnenenwnwnene +eswneenwwnwwwneewneneneswneseswee +neseneseneewneeeweewnwneeseee +nesenenenenwnwnenwswnwnenwnenenwnw +seswsesesenwseeeeseseeesesewseenw +eneswsewneeswnenweswneeswnewwswseene +eeseseseswneswseseeeeeeeeewne +wwwseswnenwwnwnwenenwnw +sesenesweeeeeweeeweeenwwe +wsewnwwsewwewwnew +esesenwnwwwneswwswsenwnwnwseswneswwew +nenwwnwnwnwswwenwwwenwwwnwnwwnw +seeeneeneeseeswnenenwsweweewee +swswswwswswswswwswswwswneswswsw +nweseneweseeswwnwwswswnw +wnwsweswseswswswswseswne +swnenenwneenenenenenenenenenenenene +swswswswswseswswwswswswwnwwenwnwseswesw +wswwswswwswswsweswewswwswnwnesw +neneeewneneeswnewneneeseseswewnw +seseswseeesenwsesweseneseeseeesese +nenenenwnesewneswneneseneenewnene +neneneneneneswwneneneneneesenenenenene +swswswnwswnwswsweeswswseswswswswswswnw +sweeseseneeeseeswnewnwnwwewsee +neswsenwnewwnwwwwwwswweseenenww +nwwwwnwwwsewnwwswnewwwnewww +nwswsweswswneswseswswswswwneseswwnesww +wsewwnwwwwswnewwwwsewswwwsw +nwwwwwsenewneewwseenewwsesw +nwnenwwnwwnwwnenenwnenwenesenwenwne +nwnenwnwsewnenwsenwnenenwnwnenenenwnene +wswswwwenwswenesewwnenwe +wseswneeswneseenwnwsenwswewwweswesw +swnwseseeeeewseswnwseneseswsenwsesene +sweneswnwnwswsweneswnwswneswneswsweswsw +eeeswnwswneeneenewswnewneneeee +senwwnenwenwnwwsenwnwnwnenw +esesenweseeeeseseeesesese +seeeeseneseseeeswseeeeseewsene +wneswwwwswswwwewwnesesenwwwse +wnwnwwwsenwnwswnwnwnenewnwnwwnwwnw +senewsesesesesesesesesesesese +eenweswneeenee +nwnenwwnwnwnwnwwwseenwnwnwwnwnwnwswnw +esweneseeneeneeneneneneneswnenewnee +nwwwwswwewnwnwww +neneeneewneeneneneswnwnesenenenenwnesene +wneswsesenewswwwwwwwnwswwwseww +wesenesewswsenwswneswswseswneesesese +sesesenwswsewnwsenwswseswesenenwseeseew +wwnwswwneswwweswwwwwwwswww +nenenwnesewwswswewsenwswnewwswew +wwwnwwwnenwwwwwnwswnwnw +nenwswneneneenenenenwnenwnwnwnenwnw +swenwswewswswswewnwwswnewswseswne +swsenweeseswenwseseswsenwsesewseswswse +eeeweswnwnenenweeswneeeseneeee +swwswneseswnwseneswnewswweseswnwww +swswswswnenwswswseswseswswswneswwseswsw +enwsewsweeseseseneweeseswesenwese +nesenweneneneneneswnwnwnenwnenwnenwnene +seswseeenwsesenweseseseseseneseeseeswse +senenwsewnwnwnenwewnwswwneswnwnwsweenw +neeewnenweseseseeswnesweneneewwse +eeenwswswseneweseneenweneneneew +swswneneswnenenenwnenwnenenenwnwnwwnwe +swsweswwswswswwnwwwweswswswwswnw +wewwewwwwnwswswwwwswwswsww +swwnwwswnweseswnwswseweenewwww +neswswswseswswseswswswseswwswswswsesenw +eneeneneneewneneneeneneenesew +nwnwnwnwnwnwnwsenwenenenwnwnwnwwnwnwswne +weneswnwsenewseseswseeseene +eseseweneenwnweseeseseneneweswswe +swswswswseswswsenwnwseswseeswswsweswnw +sweswwsweswswwswswsweswswwnwswnwenw +eeeseseeenwsewswesesewsenwsenesw +seneswseseseseneseseseweesesesw +ewnwnwwnenwwnwwnenwwnwsewwnwswww +senweeswseswneweesesesesewnwnwsee +wseseseseseseeneseese +neswneswewnwswwwwwwwswwwseewnwse +sewwsesesewnwswswswseeneeesesewse +sweswwneseneswswswswnwswnesene +eesweeenenweeneeeswenwneeeene +eseseeneweeseeeeneenwneeenwne +neneneneneswneenenwnewneneneneswnenenenee +nwnesewwswswseswnwwneswswwswwsesesw +eeneeswesenwewenwneneeeseenwesw +nenwneneneneswnenenenwnwnenw +wwseewnewwneenwwnwswsewseenwse +wsenwwnwwswwwwwswnweewnenwsee +nweseswseseseeeseeseeseeesenwsese +neneswseesewesenenenwneswwswnewswswsenw +wwneseenwwsenwnwnwneswswewnwswwnwne +eneneeneneeneesw +nwnenenwenwnwseeenwwswnwnenwnenewnw +swsweswswsewewswswnwnwwsewwe +swseneswswswswswswsesewswswseseswswnesw +eseseesenwsenwseseeeweesesweeene +neswnwsewsweseswseseswsesesenwnwneseseswse +eeneeeseeseenwneeneeeeeewne +nenwswewnwsweneswwenwswneseseneenew +weeswwwwnenwswnwsenewnwswwnwnwenw +wwnewswswswwnwseswwwswswwwnwsew +newsenwwneswwnwwnwswseeswseswsenwww +swswwsweneswwwnwnee +nwswswswswswswswswnwnwswenwseswswseeswsw +nwnwnwnewswwswnwnwnenwsenweenwnwnwnese +nwenwseseseswswswswswswenwseswnwewswswse +swneswwewsenwnwnweeenenweeseese +nwwwwwswnwesenwwnee +nwnwwwwnwwnwnwsenw +nwseseseswswneseswswnwseseswsweswsweswsw +enweswnweswnweneeeneneneeeswee +sesenwseswnwswswnenesesesesweseseesesw +swseswsewnwnwwneswswswseswswneseswwsw +nenwnenwnwnwnwnesenwnwnwnwswnene +swwenweesenesweesenweseeeeee +swnewsesenwswesweeneneesewnw +swneweswsenwnenesese +nwnweseeseseseswseewseseenenwsee +neswswneseeeeenenwwneeenenwneseneene +swswswsesesesenwsesesenwseswsesese +nwswnwenwnwnwnwnwnwnwnwnwnwsenwnw +eeneesweeeeeeseswnweeneneewe +eeenweseseeeswnwwnwnenwswnewsenenw +neswswswswseseesweswsenwsesenwnwswswsesew +eseeeseenweseeeeseese +swwwswwswwswwsewwswswnwsww +swswwsenwswwswswswswwwswew +eeeseeeseswewneeswneee +sweseswswenwnwwswswnwnenwwseewwwsee +wwnwwwwnwnwwwwewwenewnwswww +sewneswnwseeneswwwnewnwenewseswwnw +seswswswswwswswswnwsweswswswswseswswe +seswswswswswnwneswnwswswsesesenese +eenweseeeseeeeneneeeweseesw +swnwseswswnweneswenwnewenenwnwswnenese +wweenewnwsewnwwnwnenwswseweesw +wwseneeneneneneseenwwswsewwesee +wwsenewwswswwwswwwwswsw +nwwswwwnwwwnenwnwwnwnenwwswwnesw +eneseeweseesesesweewnwenwwswe +eneneeeweneeseeeenesenenenwne +neeneeeeesweseweeeeeewee +swsewnesenweenwenwnwneseseswnwnenene +sewseswseseswseseseswswesenwneswsesese +nwwwnewsewswswwnwseewwwsenewne +enwneseeeeswswneeenwnweeewwsw +wnwswswswswswsweswsw +nenenenwnesenwnenwnwswwswnene +swseseseseenwesenwsesewseesewnwseenw +eswenwsweeeenwneswseeeenwwnee +sweeswswwswswnwwnwswseseeswsesw +nweenwswsesenwneswnweeeeseseswswsenw +wnewseenwnwswneseeeeswnenwneene +nwsewnwnwnenwnwnwswenwnwnwnwwnwnwnwse +swswswswswswswnwswswswswseeswnwseswswsw +senwseswseeseneseewnwnweeseesesesesese +eeseeeenweeeneeeeneeeew +seswsenwswseesesenwswsesweswneseswsesese +nwwnenwnwwwnwwwsenwwnwnwsewnwnewsew +swneswswswswnwwswswswseswswsweswseenw +swwnenwnwneneenenenwnenwnenenenwnwne +ewneswsenwnwenenenwswseeesewnwsww +wswswenwwnenwnwseeswwnweswswnweeswse +nwnwnwsewnwnwnwenwswwsewnwenwnwwnw +neneswneneneneneneeneenenwnenewnwneenesw +eeeseseeweeeeenee +nwnwnwswsenenwenwnwnwnwswnwnwsenwnwsweene +wwsewwwwswwnewwnewwswwswwsw +nesesewwneseneseweeenwsweenwswwse +eeenweesweeewweeeeneeeee +eseswnwwsenwswneswsesweseneeneneswwwsw +wnwnwnwnwewnwnwseenwwnww +enwsenwseseeneseeseseseeswnwseesesee +neneseseseeswswwseswnesesewswnwnwwee +neenwnwnwnenwsenwnwnwsenwnenenwnwneneswnwnw +senewnwnenweeewnenwnenenwswnwnenwswnwne +seseswseswsesesesesenesewseesesesesew +nenenenwwnwneeneenwswnwnenwnwnenewnee +wwwwwseswneewnewneswnwewswsenw +nwnenwnwnwnwenwnwnenenwnwsenwnwwwnwne +wswwsenewnenenesewneneseseseewnewsw +nwnwsenwnwnwnenwnwnwnwnwnwnwnw +nwswswnwnenenwenenewneeeneswswnenwwnene +sesenwnwenwnwwnwnwnwnwnwnwnwsenwneswsenw +nwneneneswnenwnwnwnenenwnenwsenwnene +seneswneewswnenwwneeeeneeneneewe +seswswswswswneswswswswwweswwswnwswwne +swnenwnwwnenwnwnwsenenwweesenenenew +swsewwnenwnwwwwsenwwwewnwwsenew +eeeeeneeneeweneeeneenwnewswene +nwnwnwnwwnwwwwnwwwwnewnwwswneswe +swwnwsweneseswwswnewswswnwswseswnwseswe +swswswswswswswswswswseswswswswneewnwww +senwnenwsenenewnwnwwsenenwnwnwnwenenw +wswnwenwenewnwwwwwnwnwwswwwsw +swseseswswseswseneswwseneseswwseswsesese +eeeswsenewenweseeeeseeeenesw +enwnenwneswwewnwsewnwnenenwnwse +nwnenwnenwenwnwnenwnwnwswnwnwnwneneswnw +sweswseswswnwswswswswswswseenwswsewsw +wnwnwewnweenwnwewnwwsenwweswnw +senenwnwwnwnwnwwnwwwnwnwnwnwnwnwnwsesw +nwnwnwneswnwnwenwnwnewnwneenwnwnwswne +seesenewnwneswnenenenenenenenesewnene +seswwswnenwnwseseswseswswswseseweneesw +swwswenwwnwnwwewwwnwwnwnwwe +nwnwnenenwnwsenenwnwsenwnwswnwnwnwnwnw +wewsesenwswnewnwnwwnw +nesenenewneesenenweneweneeneeneeswne +senwwsenwswswnwneesewwnwneenwwnwswe +nwnwenwnwnwswnwnwnwnwnwswnwnwwenwnwnwnw +nwnwnwswnwnwneewnesenwnwnwnewnenwnenwnwe +wseseenwswseneseseneeeseeeeesenw +nenewwsewwenenwwsewswwnwwswww +nwwwnwwnesewewwwwswwewwseww +eeswseneswwsenwesesweswwsenwnwnwnese +wnwwswwewwwwwwwsenwnwwnwwsenw +nwnwnwnwnwneseneenwnenwwneenenwnwwnw +nwnwsewswnesenenwenweneseeneswwnenwwne +nwseeneneneneeneneneneneswwwwewswse +nwnenwnenenenwwswneneswnwneneneeenenwne +swswswsweswnwwswswswsweswneswswswswsw +seswseseswseswseswswnwseswswswseneswew +senwwwweswnwneswenwwswnwnwnenwwse +swswswswsewseswsewsesesesweneswsesesw +enenewneneneeeewneneseeneeneseene +nwnwnwnwnwwsenwnwsenwnwsenwnwwnwnenwnwnesw +nenenenwswnwneneneneneneneenwsenenenenw +nwnenwnwnwnwnwenwnwnwswneswnwnwnwnwnwsenw +neenenwseswnwseswswnwwnenwnwnenenenwswsew +sewnenwnenwenesenwwnwsenenwwne +wswnwwswwnwnwnwnenewnwnw +senwswneeswswswswwwswswswwsweswwsw +esewswneeeeneeewneneneneseenenwnene +nenwnwwneswnwswnwnenwswnwnwsenenwnenwnwnw +wswswnwswswwswnwswwsweweswswswsw +swswenewweswwwsweewwseswwnwnw +swwwseswswwsenesweesweenwnewsese +eseeseneseewsweneeeeseeeeee +wwnwwnwnwnwwswsewnwnwnwnwewwwnw +nwneswnwswnenwenwnwnenwnwwsenwnwnwnwne +eeeeeeneneneeweeeese +seseswseswneneseseswsenwseseseswseswsesee +wswwseswswswswswewwswnwnewsww +esenwwwseswwwnewwewnewwwww +seeeeeneeseeesenweseesewnwesese +eswwewwwwnwwwwwsewwwewnwsw +seeseeseesenwnwseeswsweswseseseesesenw +eeseeweeeseeeeeeeee +seeeseewswsenwseenwseeseneneswese +nwnwnwwneneneneewnwenenenenwsenwswnw +wsesweswnewswneswsenesewswnwseswnesene +seswseseseswseseseseswnwswswseswsesenwe +newnenesewneneneeneneseneeneneneesw +swswswswwsweswswwwwswsenweswnwwne +enwwwnwswswswwsew +nwnwnwneswnenwnwnwnenenwe +nenwneneseswnenwnenwneswneswwswneseee +eneneneeneswswneneenwswenwwneseenenw +seseswnwsenwsewswnewnwwneewneswswnew +eneneenenenenenenenenewnenenenesw +neswneswwneneewseneneeewnwnenenwne +swnwnewneeseswnweneswnwsenwnwwsewe +swwenenwswwnwsweseswswsw +senenwnenenenewnwnewnwenwnwneeneswnee +wnewneswswswwneseswww +sewwweswsewseswswswswnewseeneesw +wnwnwwsewwnwneseewwwnwsenwwww +swswswwswwswewwswswswseeswswnwswsw +seswneswsewswswswseseeswsw +nwwwnwsenwwseseneewwnwnwwwwnw +swswswswnwswwswsewne +sewneswswwweseneneeswnwnwswewswswe +nenwenwenwnwwnwnenwnenenenwnwneswnenw +eeneseseseseenwseswnewsesenwwew +nenwnesenenwwnenenenwnenenwneene +swseeseseseswsenewseseeswswnwswwswnwnwne +nwnenwnenwwnewswswseenwnwnwnw +seseswseswwsweswswswsenwswsenenwswswseswsw +nwwwsewwwwwnenwnwwwwwnwsenwsew +nenwnenwnenenenwnenwnenenesewneswnenenw +neenwnenesenwnenwnwneenwseswnwwwnwne +nenwnwnesenwnwenwnwsenwnwnwnwnwnwnwnww +swwwwwswwneswwwwsewwswwswenw +nwswswwswnwseseenww +nenwsesewneeswnwnenesenesenenewnwneee +swnewweneswseswswswswswswswswneswswswnwsw +eneseneeswwnwwnwnwsesewswenwnwsewnw +nweswnenenesenwneneneneswenenenenenenwnw +swnwnweneseenwewnweeswsenwswswnwese +esenwsweenwseeseeeeeesesweeese +wwwwwwwwwwwnesewww +swseswsesesenwseswswse +seseseswseesewseswseseseswswsese +wseeswswneseseswnwnwswswswnewwwwsw +wnwenwnwswnwnwswnwewewwnwnewnwnwse +enenwnwwwnwwwsenenwswnwseneseswnenw +eeeeswseseeeeseeeenwswnweeese +nwneswswswseswswwswswseeswswswwseswswsw +swseswnwswseswneswswswswswswsweswswsww +swswswswnwswswswsenweseseswseneseswswne +eswwnweseesesewnwsesesenwseseneesesese +enwseewnesweeenenwneseeswneeswenwe +wswwswswwseewswwnwwwseswnwswenw +nwnwnwwnwnwnwswnwnwnwe +swsenwnenwnwnwnwwe +nwseeseneeeeseeeeeeeswneseswe +neeeeewnenewnesesw +nwsewesenwnwnenenwnwsewwseneenwswnwnw +nwsewwnenenenesenwnwsenwsewnesenenwse +swsenenenwseseseswswsenwweeswsenwwsesw +wewswswwswwwwnenweswwsw +sewwwwneswnewwswwwwwwwnewwww +nenwnesenwenenwnenesenenwswswenewwnenene +eneeneeseeewneeneee +seswnwwwnenwewewnwenwwnwnwsesew +swseenewnesenwwsenwwseswnese +senwwwwewsenwwnwnwnwnwswnwnenwwswnwne +nwseseseneswsenenesesenewnesesenwswwseswe +sesewnwnwnweeswnwnwwnwnwwnwnenwnwnese +nwneneneenenwneswnwnwneneneneswnenenene +wweseseswswneswsesweseswseseswsewswe +esweseeeseswnwsenwseenwsenweesew +neswseeweeesweseeseesesenwseee +nwwnwnwswesewneenwsesewwwnwnwnww +nesewneseneeneneeeeenenewnenenenenenw +eswswswwswswwwwswnwswswwwswswsene +eeneneeneenenenwnenenewneeeeewsw +swseswneswswseseswswneseneswsesesese +weweseneneesweswswnenwenwnwwseswse +nenewnweesenenwneneneneeseneeneenenese +enenwwnwnwnwnwnewnwnwwswwwnwnwwnwse +seeseswseseeenwsesenesenwseseeeese +neenwwnesenwneneneswsenenenwnwsenwnwwne +swwwswswswnwwewswnewwnewwwswswsw +seswsesesesesewsesesenewneneseesesese +neswswnwswswswseswwnesewswnwse +wseseswnwsenwswswswseseeeswnewseeswsw +seseewenwseseseesesew +seneswseswnweneseswnwwnwsenenwsenwsesww +wwseneswswwswwneseswswswswwseswswwne From 96db7c6d0237d3379f0682015b5941ca56538f0a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 24 Dec 2020 13:26:37 +0100 Subject: [PATCH 121/129] 2020: d24: ex1: add solution --- 2020/d24/ex1/ex1.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 2020/d24/ex1/ex1.py diff --git a/2020/d24/ex1/ex1.py b/2020/d24/ex1/ex1.py new file mode 100755 index 0000000..8c6d8ac --- /dev/null +++ b/2020/d24/ex1/ex1.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +import sys +from collections import defaultdict +from typing import Dict, List, Tuple + +Offset = Tuple[int, int] + +DELTAS = { + "nw": (0, -1), + "ne": (1, -1), + "e": (1, 0), + "se": (0, 1), + "sw": (-1, 1), + "w": (-1, 0), +} + + +def to_offset(path: str) -> Offset: + offset = 0, 0 + i = 0 + while i < len(path): + direction = path[i] + i += 1 + if direction in ["s", "n"]: + direction += path[i] + i += 1 + x, y = offset + dx, dy = DELTAS[direction] + offset = x + dx, y + dy + return offset + + +def solve(raw: List[str]) -> int: + blacks: Dict[Offset, bool] = defaultdict(bool) + + for offset in map(to_offset, raw): + blacks[offset] = not blacks[offset] + + return sum(blacks.values()) + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main() From a21b197240f09557a61bf97d6494acf264b12b77 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 24 Dec 2020 13:26:45 +0100 Subject: [PATCH 122/129] 2020: d24: ex2: add input --- 2020/d24/ex2/input | 471 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 471 insertions(+) create mode 100644 2020/d24/ex2/input diff --git a/2020/d24/ex2/input b/2020/d24/ex2/input new file mode 100644 index 0000000..9b35a80 --- /dev/null +++ b/2020/d24/ex2/input @@ -0,0 +1,471 @@ +swswswswneswswwwswnewswswweswnwsww +nwwewenenwnenwnwnwnwneswnwswnwnwswswnw +seneswwwswwnenwnenwswswswswsewseeww +esenesenesesesewseseswnesesweesesesese +seseseeseenesewseenwsesewswwsesenwse +eswenewnenenewneneneneenenenenwnene +nwseeseseeseseseseewseesenwseeesese +nwnwswswswweneseswwswwneswswswswswsw +senenenwnenewneneneseswneeeenenenew +eswnwnesenwnwnenwnwnwnwwnwsenwwswswenw +wswneswswseesewswseswswswnenesenenwswswne +seswseswneswswswwnwswwswseneswswswswsee +neseseswnwesesesesewswsesenesenesesesw +wwswwwsweswwwww +seswwnwneenwswneenwewneneneseenee +eswseenweswewseneeeeseeswnwnwse +swsweswswswnweswswneswwswnwswwwswswswsw +nwwnwnwnwnwnwnwnwwswwnweneswwenwnw +sewswwwwwwwweswwwwneswwnwswnw +nwneeneeneneseneseneneneneneneswnenwnene +swnenenweeneeeseswweneenenenenene +nwnwnwsenwewsesenwenwwwswwnwnesenw +swnwswswswswswsewseswnewneseswswswneesw +wwweswwswwsewswswwwwnwwesewwne +swswsweneswswswenwswnewnwswwneswseswswe +nwnesewwnwwnwwwsew +enwwwnenwnewwwwswwseeswewe +neswseswswsenwseswnwseswse +senwseneneneneneeseneswnenenenenwnenwnw +swseneswwseenwsenwneneswnewnenewene +ewwwwwwwewwwnwswwwwwwwne +eswswenwsenwnwsenenw +nwneseewseswwsewswnwnwnwwwwnewww +nwwwwwwwwewnwwswnew +neeeseeesewseeeeeeeewe +wweswnenwwnewnwnwwwewsewnwwsew +swwswwwswwewwswswnwsweswnwwwww +eseswneenwneenweseenweeseeeenw +neneswneneneneneneneneneswnenwnwnw +nwnwwnwewwswwnwwwnwsewnwwenwnw +seswswswnwswwwwswwswneswwseswnw +nwseswenwwneneneseswneenwnenenwnenwnenw +nwnenenenesewwnenwnwnesenwnwnwnwnenwnwnw +wseeeneseeeseseesesenwseseswsesese +sweseswnwseseseswseswseseseswswswse +ewwwswswsenwewnewwwenwwwnwww +nwwsewnwnwnwneswwnwesewnwwnwnwnwnwne +nenwnwnwnenenwnenwnwswswnwneenenwnwnwne +esenwneswsesesweeeeweseseeseseswnw +swswswswwsesweseswswswsw +swsweneswwseswswswwswsenewswwswseswnene +nenenewnwnenenwenwnesenwneseswnwnwnwne +nenenenewneeseneneswneneneswsenenenwne +nenenwnenwswwnweesenwsenwnwnwseswnwnwnw +seseeenwsenwswsesenwseeseeseeseswese +swneeseseneswswnwswnwwwwswswnee +seeseseseneseseswsewseenenwwneseswse +wswseseenwwswnewenwswswwwnewwsw +nenewswnwnenwnwneeneswseeneswnenwnenesene +nwswsenweweseeneseesesesesesesesee +seneswswwesenenwswseswnwseseseseseswne +wwnwwweswnwnwwweneseewnwsesenw +swswneneneneenewnesenewweenweswne +eseneseneseenenewwswseweenweenenene +nwwnwwnwsenwnwnwnwwnwwnww +swweswsewewwwwwwwwwwnewne +swswnewseseseesenewseesesesesesenwese +swswnenwnenwnwnwnwnenenenwnwwnenwseene +wnwwwwnwnwwnwwnwnwwwnwnwsenwe +nwseswwwnenwwwwesewwwwwwwnenwnw +nwswswnwswwswwnenenwnwnwnwnewnenw +seswswswnwswswswswswswswswswswswsw +neneseeneswnwnenwnwsenwnenenewne +wwwwwnenwnwnweswwnwsewwwesese +swwswswwwwseswswenwnewswwswweswnw +swwswseswswseeswswswewswswnwswswese +nwnwewsenenwnesewwwwswnwnenwswsee +seseseenwwswseneneseswswnwnewswnwsenwse +wwswwnwwwwsewwwenewnwswnwwwe +swwwwswwswwswneseswswswwnewswwse +nenenwneeswnenesweneneneeneneswsewesw +seswswswseswswswswsweenwswswwseswwsw +swswswsewneseesenwseseswseswswswnwsesw +nwwnewnwnwswnwnwswnwsenwwnwenwnenww +wswwnwwwswwwwswe +eewneeeeneeswsee +wseneseeseewseseseswsewse +wwswnwnwwnewnwsewenenwswwewswwne +seneesesesesewswswwnwseswswseseswseswsw +ewnweeeseneseeseseeneseswwwee +wwwwswwsewwwwewwwwwswnwwne +swsewswswswseswseseeswsenwseswswswsenw +nenenenenesenenenenenenewenewneswsene +newnewewwnwnwnwsewwswnwwwwesww +neseeeneneeewnee +wsenwwnwenwnwwnwnwnwwnwnwwnw +nweswenwseseswwseeenwseenwswsesewsw +wwwswwwwsewwwwwwwwne +nenwnwnwnenwnwnwnenwwnwnwnwnwnwe +eeeeeweneeseeeesweeeeew +seneseeeeewewnweseeseseseeseese +swenenenenwesweewneeeneneeeeeee +wnenwseswnwwwsenwnwwnwnwwnwwnwnwnwnw +sewwwswnwwnwwwswwnewwewwwsw +swwwwswswwswswwwswnew +esweeneeswenwnweesweneeeeswee +eenweeseneeeeeeeeeseeenenwsw +nwneswweeneseswnwswnweeesesesenwe +neneneeswnwnwnwnenenwnenene +wseewseeseseneswsenwsenewsesweseswswse +eseswneneseneenenewswwnwnenenesenenenw +seswsesesweseswseswseswwsw +nwnenenenenwnenenwsenenwwsenewnenenene +eneneneneswnenenenenenenenwneneneswnwnw +neneeneneenwnenenesweneneewsweneene +swnwnwneswnwnwseenwnwnenwenewnwnwnwwnw +swswwnwwswnwwseswewswneseneswewneswe +neswswnewwswswwwswwsewww +nwneeenwswnwsenwnwnwnwnenwswnwnwsenwnw +neeswnwnwwnwseswesweneswnw +swnenwenwnwnwnwsesenwswnwnwnwnwnwnwnwnw +swseswswnenwwwwseswwwwsw +seswneseswseswswswsewesenwsenesewsesw +eseeneswseenwewseewneeeene +swnenenenenenenewwneneswnenenesenesenw +swnenwnenwnwenenenwnenenwnwnene +eswneenwwnwwwneewneneneswneseswee +neseneseneewneeeweewnwneeseee +nesenenenenwnwnenwswnwnenwnenenwnw +seswsesesenwseeeeseseeesesewseenw +eneswsewneeswnenweswneeswnewwswseene +eeseseseswneswseseeeeeeeeewne +wwwseswnenwwnwnwenenwnw +sesenesweeeeeweeeweeenwwe +wsewnwwsewwewwnew +esesenwnwwwneswwswsenwnwnwseswneswwew +nenwwnwnwnwswwenwwwenwwwnwnwwnw +seeeneeneeseeswnenenwsweweewee +swswswwswswswswwswswwswneswswsw +nweseneweseeswwnwwswswnw +wnwsweswseswswswswseswne +swnenenwneenenenenenenenenenenenene +swswswswswseswswwswswswwnwwenwnwseswesw +wswwswswwswswsweswewswwswnwnesw +neneeewneneeswnewneneeseseswewnw +seseswseeesenwsesweseneseeseeesese +nenenenwnesewneswneneseneenewnene +neneneneneneswwneneneneneesenenenenene +swswswnwswnwswsweeswswseswswswswswswnw +sweeseseneeeseeswnewnwnwwewsee +neswsenwnewwnwwwwwwswweseenenww +nwwwwnwwwsewnwwswnewwwnewww +nwswsweswswneswseswswswswwneseswwnesww +wsewwnwwwwswnewwwwsewswwwsw +nwwwwwsenewneewwseenewwsesw +nwnenwwnwwnwwnenenwnenwenesenwenwne +nwnenwnwsewnenwsenwnenenwnwnenenenwnene +wswswwwenwswenesewwnenwe +wseswneeswneseenwnwsenwswewwweswesw +swnwseseeeeewseswnwseneseswsenwsesene +sweneswnwnwswsweneswnwswneswneswsweswsw +eeeswnwswneeneenewswnewneneeee +senwwnenwenwnwwsenwnwnwnenw +esesenweseeeeseseeesesese +seeeeseneseseeeswseeeeseewsene +wneswwwwswswwwewwnesesenwwwse +wnwnwwwsenwnwswnwnwnenewnwnwwnwwnw +senewsesesesesesesesesesesese +eenweswneeenee +nwnenwwnwnwnwnwwwseenwnwnwwnwnwnwswnw +esweneseeneeneeneneneneneswnenewnee +nwwwwswwewnwnwww +neneeneewneeneneneswnwnesenenenenwnesene +wneswsesenewswwwwwwwnwswwwseww +wesenesewswsenwswneswswseswneesesese +sesesenwswsewnwsenwswseswesenenwseeseew +wwnwswwneswwweswwwwwwwswww +nenenwnesewwswswewsenwswnewwswew +wwwnwwwnenwwwwwnwswnwnw +nenwswneneneenenenenwnenwnwnwnenwnw +swenwswewswswswewnwwswnewswseswne +swsenweeseswenwseseswsenwsesewseswswse +eeeweswnwnenenweeswneeeseneeee +swwswneseswnwseneswnewswweseswnwww +swswswswnenwswswseswseswswswneswwseswsw +enwsewsweeseseseneweeseswesenwese +nesenweneneneneneswnwnwnenwnenwnenwnene +seswseeenwsesenweseseseseseneseeseeswse +senenwsewnwnwnenwewnwswwneswnwnwsweenw +neeewnenweseseseeswnesweneneewwse +eeenwswswseneweseneenweneneneew +swswneneswnenenenwnenwnenenenwnwnwwnwe +swsweswwswswswwnwwwweswswswwswnw +wewwewwwwnwswswwwwswwswsww +swwnwwswnweseswnwswseweenewwww +neswswswseswswseswswswseswwswswswsesenw +eneeneneneewneneneeneneenesew +nwnwnwnwnwnwnwsenwenenenwnwnwnwwnwnwswne +weneswnwsenewseseswseeseene +eseseweneenwnweseeseseneneweswswe +swswswswseswswsenwnwseswseeswswsweswnw +sweswwsweswswwswswsweswswwnwswnwenw +eeeseseeenwsewswesesewsenwsenesw +seneswseseseseneseseseweesesesw +ewnwnwwnenwwnwwnenwwnwsewwnwswww +senweeswseswneweesesesesewnwnwsee +wseseseseseseeneseese +neswneswewnwswwwwwwwswwwseewnwse +sewwsesesewnwswswswseeneeesesewse +sweswwneseneswswswswnwswnesene +eesweeenenweeneeeswenwneeeene +eseseeneweeseeeeneenwneeenwne +neneneneneswneenenwnewneneneneswnenenenee +nwnesewwswswseswnwwneswswwswwsesesw +eeneeswesenwewenwneneeeseenwesw +nenwneneneneswnenenenwnwnenw +wwseewnewwneenwwnwswsewseenwse +wsenwwnwwswwwwwswnweewnenwsee +nweseswseseseeeseeseeseeesenwsese +neneswseesewesenenenwneswwswnewswswsenw +wwneseenwwsenwnwnwneswswewnwswwnwne +eneneeneneeneesw +nwnenenwenwnwseeenwwswnwnenwnenewnw +swsweswswsewewswswnwnwwsewwe +swseneswswswswswswsesewswswseseswswnesw +eseseesenwsenwseseeeweesesweeene +neswnwsewsweseswseseswsesesenwnwneseseswse +eeneeeseeseenwneeneeeeeewne +nenwswewnwsweneswwenwswneseseneenew +weeswwwwnenwswnwsenewnwswwnwnwenw +wwnewswswswwnwseswwwswswwwnwsew +newsenwwneswwnwwnwswseeswseswsenwww +swswwsweneswwwnwnee +nwswswswswswswswswnwnwswenwseswswseeswsw +nwnwnwnewswwswnwnwnenwsenweenwnwnwnese +nwenwseseseswswswswswswenwseswnwewswswse +swneswwewsenwnwnweeenenweeseese +nwwwwwswnwesenwwnee +nwnwwwwnwwnwnwsenw +nwseseseswswneseswswnwseseswsweswsweswsw +enweswnweswnweneeeneneneeeswee +sesenwseswnwswswnenesesesesweseseesesw +swseswsewnwnwwneswswswseswswneseswwsw +nenwnenwnwnwnwnesenwnwnwnwswnene +swwenweesenesweesenweseeeeee +swnewsesenwswesweeneneesewnw +swneweswsenwnenesese +nwnweseeseseseswseewseseenenwsee +neswswneseeeeenenwwneeenenwneseneene +swswswsesesesenwsesesenwseswsesese +nwswnwenwnwnwnwnwnwnwnwnwnwsenwnw +eeneesweeeeeeseswnweeneneewe +eeenweseseeeswnwwnwnenwswnewsenenw +neswswswswseseesweswsenwsesenwnwswswsesew +eseeeseenweseeeeseese +swwwswwswwswwsewwswswnwsww +swswwsenwswwswswswswwwswew +eeeseeeseswewneeswneee +sweseswswenwnwwswswnwnenwwseewwwsee +wwnwwwwnwnwwwwewwenewnwswww +sewneswnwseeneswwwnewnwenewseswwnw +seswswswswwswswswnwsweswswswswseswswe +seswswswswswnwneswnwswswsesesenese +eenweseeeseeeeneneeeweseesw +swnwseswswnweneswenwnewenenwnwswnenese +wweenewnwsewnwwnwnenwswseweesw +wwseneeneneneneseenwwswsewwesee +wwsenewwswswwwswwwwswsw +nwwswwwnwwwnenwnwwnwnenwwswwnesw +eneseeweseesesesweewnwenwwswe +eneneeeweneeseeeenesenenenwne +neeneeeeesweseweeeeeewee +swsewnesenweenwenwnwneseseswnwnenene +sewseswseseswseseseswswesenwneswsesese +nwwwnewsewswswwnwseewwwsenewne +enwneseeeeswswneeenwnweeewwsw +wnwswswswswswsweswsw +nenenenwnesenwnenwnwswwswnene +swseseseseenwesenwsesewseesewnwseenw +eswenwsweeeenwneswseeeenwwnee +sweeswswwswswnwwnwswseseeswsesw +nweenwswsesenwneswnweeeeseseswswsenw +wnewseenwnwswneseeeeswnenwneene +nwsewnwnwnenwnwnwswenwnwnwnwwnwnwnwse +swswswswswswswnwswswswswseeswnwseswswsw +senwseswseeseneseewnwnweeseesesesesese +eeseeeenweeeneeeeneeeew +seswsenwswseesesenwswsesweswneseswsesese +nwwnenwnwwwnwwwsenwwnwnwsewnwnewsew +swneswswswswnwwswswswseswswsweswseenw +swwnenwnwneneenenenwnenwnenenenwnwne +ewneswsenwnwenenenwswseeesewnwsww +wswswenwwnenwnwseeswwnweswswnweeswse +nwnwnwsewnwnwnwenwswwsewnwenwnwwnw +neneswneneneneneneeneenenwnenewnwneenesw +eeeseseeweeeeenee +nwnwnwswsenenwenwnwnwnwswnwnwsenwnwsweene +wwsewwwwswwnewwnewwswwswwsw +nesesewwneseneseweeenwsweenwswwse +eeenweesweeewweeeeneeeee +eseswnwwsenwswneswsesweseneeneneswwwsw +wnwnwnwnwewnwnwseenwwnww +enwsenwseseeneseeseseseeswnwseesesee +neneseseseeswswwseswnesesewswnwnwwee +neenwnwnwnenwsenwnwnwsenwnenenwnwneneswnwnw +senewnwnenweeewnenwnenenwswnwnenwswnwne +seseswseswsesesesesenesewseesesesesew +nenenenwwnwneeneenwswnwnenwnwnenewnee +wwwwwseswneewnewneswnwewswsenw +nwnenwnwnwnwenwnwnenenwnwsenwnwwwnwne +wswwsenewnenenesewneneseseseewnewsw +nwnwsenwnwnwnenwnwnwnwnwnwnwnw +nwswswnwnenenwenenewneeeneswswnenwwnene +sesenwnwenwnwwnwnwnwnwnwnwnwsenwneswsenw +nwneneneswnenwnwnwnenenwnenwsenwnene +seneswneewswnenwwneeeeneeneneewe +seswswswswswneswswswswwweswwswnwswwne +swnenwnwwnenwnwnwsenenwweesenenenew +swsewwnenwnwwwwsenwwwewnwwsenew +eeeeeneeneeweneeeneenwnewswene +nwnwnwnwwnwwwwnwwwwnewnwwswneswe +swwnwsweneseswwswnewswswnwswseswnwseswe +swswswswswswswswswswseswswswswneewnwww +senwnenwsenenewnwnwwsenenwnwnwnwenenw +wswnwenwenewnwwwwwnwnwwswwwsw +swseseswswseswseneswwseneseswwseswsesese +eeeswsenewenweseeeeseeeenesw +enwnenwneswwewnwsewnwnenenwnwse +nwnenwnenwenwnwnenwnwnwswnwnwnwneneswnw +sweswseswswnwswswswswswswseenwswsewsw +wnwnwewnweenwnwewnwwsenwweswnw +senenwnwwnwnwnwwnwwwnwnwnwnwnwnwnwsesw +nwnwnwneswnwnwenwnwnewnwneenwnwnwswne +seesenewnwneswnenenenenenenenesewnene +seswwswnenwnwseseswseswswswseseweneesw +swwswenwwnwnwwewwwnwwnwnwwe +nwnwnenenwnwsenenwnwsenwnwswnwnwnwnwnw +wewsesenwswnewnwnwwnw +nesenenewneesenenweneweneeneeneeswne +senwwsenwswswnwneesewwnwneenwwnwswe +nwnwenwnwnwswnwnwnwnwnwswnwnwwenwnwnwnw +nwnwnwswnwnwneewnesenwnwnwnewnenwnenwnwe +wseseenwswseneseseneeeseeeeesenw +nenewwsewwenenwwsewswwnwwswww +nwwwnwwnesewewwwwswwewwseww +eeswseneswwsenwesesweswwsenwnwnwnese +wnwwswwewwwwwwwsenwnwwnwwsenw +nwnwnwnwnwneseneenwnenwwneenenwnwwnw +nwnwsewswnesenenwenweneseeneswwnenwwne +nwseeneneneneeneneneneneswwwwewswse +nwnenwnenenenwwswneneswnwneneneeenenwne +swswswsweswnwwswswswsweswneswswswswsw +seswseseswseswseswswnwseswswswseneswew +senwwwweswnwneswenwwswnwnwnenwwse +swswswswsewseswsewsesesesweneswsesesw +enenewneneneeeewneneseeneeneseene +nwnwnwnwnwwsenwnwsenwnwsenwnwwnwnenwnwnesw +nenenenwswnwneneneneneneneenwsenenenenw +nwnenwnwnwnwnwenwnwnwswneswnwnwnwnwnwsenw +neenenwseswnwseswswnwwnenwnwnenenenwswsew +sewnenwnenwenesenwwnwsenenwwne +wswnwwswwnwnwnwnenewnwnw +senwswneeswswswswwwswswswwsweswwsw +esewswneeeeneeewneneneneseenenwnene +nenwnwwneswnwswnwnenwswnwnwsenenwnenwnwnw +wswswnwswswwswnwswwsweweswswswsw +swswenewweswwwsweewwseswwnwnw +swwwseswswwsenesweesweenwnewsese +eseeseneseewsweneeeeseeeeee +wwnwwnwnwnwwswsewnwnwnwnwewwwnw +nwneswnwswnenwenwnwnenwnwwsenwnwnwnwne +eeeeeeneneneeweeeese +seseswseswneneseseswsenwseseseswseswsesee +wswwseswswswswswewwswnwnewsww +esenwwwseswwwnewwewnewwwww +seeeeeneeseeesenweseesewnwesese +eswwewwwwnwwwwwsewwwewnwsw +seeseeseesenwnwseeswsweswseseseesesenw +eeseeweeeseeeeeeeee +seeeseewswsenwseenwseeseneneswese +nwnwnwwneneneneewnwenenenenwsenwswnw +wsesweswnewswneswsenesewswnwseswnesene +seswseseseswseseseseswnwswswseswsesenwe +newnenesewneneneeneneseneeneneneesw +swswswswwsweswswwwwswsenweswnwwne +enwwwnwswswswwsew +nwnwnwneswnenwnwnwnenenwe +nenwneneseswnenwnenwneswneswwswneseee +eneneneeneswswneneenwswenwwneseenenw +seseswnwsenwsewswnewnwwneewneswswnew +eneneenenenenenenenenewnenenenesw +neswneswwneneewseneneeewnwnenenwne +swnwnewneeseswnweneswnwsenwnwwsewe +swwenenwswwnwsweseswswsw +senenwnenenenewnwnewnwenwnwneeneswnee +wnewneswswswwneseswww +sewwweswsewseswswswswnewseeneesw +wnwnwwsewwnwneseewwwnwsenwwww +swswswwswwswewwswswswseeswswnwswsw +seswneswsewswswswseseeswsw +nwwwnwsenwwseseneewwnwnwwwwnw +swswswswnwswwswsewne +sewneswswwweseneneeswnwnwswewswswe +nenwenwenwnwwnwnenwnenenenwnwneswnenw +eeneseseseseenwseswnewsesenwwew +nenwnesenenwwnenenenwnenenwneene +swseeseseseswsenewseseeswswnwswwswnwnwne +nwnenwnenwwnewswswseenwnwnwnw +seseswseswwsweswswswsenwswsenenwswswseswsw +nwwwsewwwwwnenwnwwwwwnwsenwsew +nenwnenwnenenenwnenwnenenesewneswnenenw +neenwnenesenwnenwnwneenwseswnwwwnwne +nenwnwnesenwnwenwnwsenwnwnwnwnwnwnwnww +swwwwwswwneswwwwsewwswwswenw +nwswswwswnwseseenww +nenwsesewneeswnwnenesenesenenewnwneee +swnewweneswseswswswswswswswswneswswswnwsw +eneseneeswwnwwnwnwsesewswenwnwsewnw +nweswnenenesenwneneneneswenenenenenenwnw +swnwnweneseenwewnweeswsenwswswnwese +esenwsweenwseeseeeeeesesweeese +wwwwwwwwwwwnesewww +swseswsesesenwseswswse +seseseswseesewseswseseseswswsese +wseeswswneseseswnwnwswswswnewwwwsw +wnwenwnwswnwnwswnwewewwnwnewnwnwse +enenwnwwwnwwwsenenwswnwseneseswnenw +eeeeswseseeeeseeeenwswnweeese +nwneswswswseswswwswswseeswswswwseswswsw +swseswnwswseswneswswswswswswsweswswsww +swswswswnwswswswsenweseseswseneseswswne +eswwnweseesesewnwsesesenwseseneesesese +enwseewnesweeenenwneseeswneeswenwe +wswwswswwseewswwnwwwseswnwswenw +nwnwnwwnwnwnwswnwnwnwe +swsenwnenwnwnwnwwe +nwseeseneeeeseeeeeeeswneseswe +neeeeewnenewnesesw +nwsewesenwnwnenenwnwsewwseneenwswnwnw +nwsewwnenenenesenwnwsenwsewnesenenwse +swsenenenwseseseswswsenwweeswsenwwsesw +wewswswwswwwwnenweswwsw +sewwwwneswnewwswwwwwwwnewwww +nenwnesenwenenwnenesenenwswswenewwnenene +eneeneeseeewneeneee +seswnwwwnenwewewnwenwwnwnwsesew +swseenewnesenwwsenwwseswnese +senwwwwewsenwwnwnwnwnwswnwnenwwswnwne +nwseseseneswsenenesesenewnesesenwswwseswe +sesewnwnwnweeswnwnwwnwnwwnwnenwnwnese +nwneneneenenwneswnwnwneneneneswnenenene +wweseseswswneswsesweseswseseswsewswe +esweseeeseswnwsenwseenwsenweesew +neswseeweeesweseeseesesenwseee +nwwnwnwswesewneenwsesewwwnwnwnww +nesewneseneeneneeeeenenewnenenenenenw +eswswswwswswwwwswnwswswwwswswsene +eeneneeneenenenwnenenewneeeeewsw +swseswneswswseseswswneseneswsesesese +weweseneneesweswswnenwenwnwwseswse +nenewnweesenenwneneneneeseneeneenenese +enenwwnwnwnwnwnewnwnwwswwwnwnwwnwse +seeseswseseeenwsesenesenwseseeeese +neenwwnesenwneneneswsenenenwnwsenwnwwne +swwwswswswnwwewswnewwnewwwswswsw +seswsesesesesewsesesenewneneseesesese +neswswnwswswswseswwnesewswnwse +wseseswnwsenwswswswseseeeswnewseeswsw +seseewenwseseseesesew +seneswseswnweneseswnwwnwsenenwsenwsesww +wwseneswswwswwneseswswswswwseswswwne From afec744618c93750f8c54cc2ba4aee1c59abbf95 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 24 Dec 2020 13:26:52 +0100 Subject: [PATCH 123/129] 2020: d24: ex2: add solution --- 2020/d24/ex2/ex2.py | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 2020/d24/ex2/ex2.py diff --git a/2020/d24/ex2/ex2.py b/2020/d24/ex2/ex2.py new file mode 100755 index 0000000..17728b2 --- /dev/null +++ b/2020/d24/ex2/ex2.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python + +import itertools +import sys +from collections import defaultdict +from copy import deepcopy +from typing import Dict, Iterator, List, Tuple + +Offset = Tuple[int, int] +Grid = Dict[Offset, bool] + +DELTAS = { + "nw": (0, -1), + "ne": (1, -1), + "e": (1, 0), + "se": (0, 1), + "sw": (-1, 1), + "w": (-1, 0), +} + + +def to_offset(path: str) -> Offset: + offset = 0, 0 + i = 0 + while i < len(path): + direction = path[i] + i += 1 + if direction in ["s", "n"]: + direction += path[i] + i += 1 + x, y = offset + dx, dy = DELTAS[direction] + offset = x + dx, y + dy + return offset + + +def neighbours(tile: Offset) -> Iterator[Offset]: + x, y = tile + for dx, dy in DELTAS.values(): + yield x + dx, y + dy + + +def step(blacks: Grid) -> Grid: + to_visit = set(itertools.chain.from_iterable(neighbours(tile) for tile in blacks)) + to_visit |= {tile for tile in blacks} + res: Grid = defaultdict(bool) + + for tile in to_visit: + num_neighbours = sum(blacks[n] for n in neighbours(tile)) + if blacks[tile]: + res[tile] = num_neighbours in (1, 2) + else: + res[tile] = num_neighbours == 2 + + return res + + +def solve(raw: List[str]) -> int: + blacks: Grid = defaultdict(bool) + + for offset in map(to_offset, raw): + blacks[offset] = not blacks[offset] + + for __ in range(100): + blacks = step(blacks) + + return sum(blacks.values()) + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main() From 17f62f1052aa775e945a3ea69799387e552aa821 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 25 Dec 2020 11:39:33 +0100 Subject: [PATCH 124/129] 2020: d25: ex1: add input --- 2020/d25/ex1/input | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 2020/d25/ex1/input diff --git a/2020/d25/ex1/input b/2020/d25/ex1/input new file mode 100644 index 0000000..fe514d8 --- /dev/null +++ b/2020/d25/ex1/input @@ -0,0 +1,2 @@ +8987316 +14681524 From a7d74dcae6804dc44da9b7470aa44b90ea18dda2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 25 Dec 2020 11:39:46 +0100 Subject: [PATCH 125/129] 2020: d25: ex1: add solution --- 2020/d25/ex1/ex1.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 2020/d25/ex1/ex1.py diff --git a/2020/d25/ex1/ex1.py b/2020/d25/ex1/ex1.py new file mode 100755 index 0000000..6e346d5 --- /dev/null +++ b/2020/d25/ex1/ex1.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import itertools +import sys +from typing import List + + +def step(value: int, subject: int) -> int: + value *= subject + value %= 20201227 + return value + + +def solve(raw: List[int]) -> int: + value = 1 + + for rounds in itertools.count(1): + value = step(value, 7) + if value == raw[0]: + break + + key = 1 + for __ in range(rounds): + key = step(key, raw[1]) + + return key + + +def main() -> None: + input = [int(line) for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main() From 55af2695f5afec0d7a00d2b023ffb0aa1346144f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 25 Dec 2020 11:40:36 +0100 Subject: [PATCH 126/129] 2020: d25: ex2: add input --- 2020/d25/ex2/input | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 2020/d25/ex2/input diff --git a/2020/d25/ex2/input b/2020/d25/ex2/input new file mode 100644 index 0000000..fe514d8 --- /dev/null +++ b/2020/d25/ex2/input @@ -0,0 +1,2 @@ +8987316 +14681524 From cb0348d87c88461d7ea2b1e95b02cdbd14b3df87 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 25 Dec 2020 11:40:47 +0100 Subject: [PATCH 127/129] 2020: d25: ex2: add solution --- 2020/d25/ex2/ex2.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 2020/d25/ex2/ex2.py diff --git a/2020/d25/ex2/ex2.py b/2020/d25/ex2/ex2.py new file mode 100755 index 0000000..918e0ec --- /dev/null +++ b/2020/d25/ex2/ex2.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python + + +def main() -> None: + print("There is no part two...") + + +if __name__ == "__main__": + main() From 8e0ec0b9626b166072cfaef79574699a0e0c4a69 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Dec 2021 10:41:02 +0100 Subject: [PATCH 128/129] nix: add flake --- flake.lock | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b743e83 --- /dev/null +++ b/flake.lock @@ -0,0 +1,69 @@ +{ + "nodes": { + "futils": { + "locked": { + "lastModified": 1638122382, + "narHash": "sha256-sQzZzAbvKEqN9s0bzWuYmRaA03v40gaJ4+iL1LXjaeI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "74f7e4319258e287b0f9cb95426c9853b282730b", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "master", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1638286143, + "narHash": "sha256-A+rgjbIpz3uPRKHPXwdmouVcVn5pZqLnaZHymjkraG4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "29d1f6e1f625d246dcf84a78ef97b4da3cafc6ea", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": [ + "futils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1637745948, + "narHash": "sha256-DmQG1bZk24eS+BAHwnHPyYIadMLKbq0d1b//iapYIPU=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "c3b4f94350b0e59c2546fa85890cc70d03616b9c", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "master", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "futils": "futils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..59cf9db --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + description = "Advent of Code answers"; + + inputs = { + futils = { + type = "github"; + owner = "numtide"; + repo = "flake-utils"; + ref = "master"; + }; + + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixos-unstable"; + }; + + pre-commit-hooks = { + type = "github"; + owner = "cachix"; + repo = "pre-commit-hooks.nix"; + ref = "master"; + inputs = { + flake-utils.follows = "futils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + }; + + outputs = { self, futils, nixpkgs, pre-commit-hooks }: + futils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + checks = { + pre-commit = pre-commit-hooks.lib.${system}.run { + src = self; + + hooks = { + black = { + enable = true; + }; + + isort = { + enable = true; + }; + + nixpkgs-fmt = { + enable = true; + }; + }; + }; + }; + + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + python310 # Latest version at the moment + ]; + + inherit (self.checks.${system}.pre-commit) shellHook; + }; + }); +} From da90cd8472f2f40d4e4b3c67ca6ac7e7de6c2ab2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Dec 2021 10:41:10 +0100 Subject: [PATCH 129/129] nix: add direnv integration --- .envrc | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c23bb91 --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +use_flake() { + watch_file flake.nix + watch_file flake.lock + eval "$(nix print-dev-env)" +} + +use flake