Changement d'ordi! (Non le jour 12 n'est pas terminé)
This commit is contained in:
parent
a9d7c6a101
commit
6df1e1c3ec
@ -1,8 +1,10 @@
|
||||
from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from typing import NamedTuple, NewType
|
||||
from typing import NamedTuple, NewType, Self
|
||||
import re
|
||||
import logging
|
||||
|
||||
|
||||
def im_replace(line: str, mask: str) -> str:
|
||||
idx = 0
|
||||
new_line = ""
|
||||
@ -29,7 +31,7 @@ class SpringLine(NamedTuple):
|
||||
debug_str += rep_str + " / "
|
||||
tentative = im_replace(self.line, rep_str)
|
||||
possible = SpringLine(tentative, self.groups)
|
||||
debug_str += str(possible)+": "
|
||||
debug_str += str(possible) + ": "
|
||||
if possible.is_valid():
|
||||
possibles.append(im_replace(self.line, rep_str))
|
||||
debug_str += "valid"
|
||||
@ -43,6 +45,14 @@ class SpringLine(NamedTuple):
|
||||
# logging.debug(pattern)
|
||||
return re.match(pattern, self.line)
|
||||
|
||||
def unfold(self) -> SpringLine:
|
||||
new_line = []
|
||||
new_groups = []
|
||||
for i in range(5):
|
||||
new_line.append(self.line)
|
||||
new_groups += self.groups
|
||||
return SpringLine("?".join(new_line), new_groups)
|
||||
|
||||
|
||||
Spring = NewType("Spring", list[SpringLine])
|
||||
|
||||
|
@ -3,5 +3,6 @@
|
||||
from common import *
|
||||
|
||||
|
||||
def part2(input_file:str) -> int:
|
||||
return 0
|
||||
def part2(input_file: str) -> int:
|
||||
spring = parse(input_file)
|
||||
return sum(list(map(len, map(lambda s: s.unfold().arrangments(), spring))))
|
||||
|
@ -4,9 +4,10 @@ import logging
|
||||
from unittest import TestCase, main
|
||||
from common import *
|
||||
from part1 import part1
|
||||
from part2 import part2
|
||||
|
||||
|
||||
class DayXTests(TestCase):
|
||||
class Day12Tests(TestCase):
|
||||
def test_parsing(self):
|
||||
parsed_spring = parse("example_input.txt")
|
||||
spring: Spring = [
|
||||
|
35
day13/common.py
Normal file
35
day13/common.py
Normal file
@ -0,0 +1,35 @@
|
||||
from dataclasses import dataclass
|
||||
from collections.abc import Iterator
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class MirrorField:
|
||||
_data: list[str]
|
||||
|
||||
def __getitem__(self, key: int) -> str:
|
||||
return self._data[key]
|
||||
|
||||
def __len__(self) -> int:
|
||||
return len(self._data)
|
||||
|
||||
def __iter__(self) -> Iterator[str]:
|
||||
return iter(self._data)
|
||||
|
||||
def iter_horizontal(self) -> Iterator[str]:
|
||||
return iter(self)
|
||||
|
||||
def iter_vertical(self) -> Iterator[str]:
|
||||
x = 0
|
||||
while x < len(self._data[0]):
|
||||
the_str = ""
|
||||
for line in self._data:
|
||||
the_str += line[x]
|
||||
yield the_str
|
||||
x += 1
|
||||
|
||||
def find_symetry(self) -> tuple[str, int] | None:
|
||||
"""Return a tuple indicating a symetry horizontal (h) or vertical (v) and the first row or column index"""
|
||||
|
||||
|
||||
def parse(input_file: str) -> MirrorField:
|
||||
return MirrorField()
|
15
day13/example_input.txt
Normal file
15
day13/example_input.txt
Normal file
@ -0,0 +1,15 @@
|
||||
#.##..##.
|
||||
..#.##.#.
|
||||
##......#
|
||||
##......#
|
||||
..#.##.#.
|
||||
..##..##.
|
||||
#.#.##.#.
|
||||
|
||||
#...##..#
|
||||
#....#..#
|
||||
..##..###
|
||||
#####.##.
|
||||
#####.##.
|
||||
..##..###
|
||||
#....#..#
|
7
day13/part1.py
Executable file
7
day13/part1.py
Executable file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env python3.11
|
||||
|
||||
from common import *
|
||||
|
||||
|
||||
def part1(input_file: str) -> int:
|
||||
return 0
|
7
day13/part2.py
Executable file
7
day13/part2.py
Executable file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env python3.11
|
||||
|
||||
from common import *
|
||||
|
||||
|
||||
def part2(input_file: str) -> int:
|
||||
return 0
|
23
day13/test.py
Executable file
23
day13/test.py
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3.11
|
||||
|
||||
from unittest import TestCase, main
|
||||
import logging
|
||||
from common import *
|
||||
from part1 import part1
|
||||
from part2 import part2
|
||||
|
||||
|
||||
class DayXTests(TestCase):
|
||||
def test_parsing(self):
|
||||
pass
|
||||
|
||||
def test_part1(self):
|
||||
self.assertEqual(405, part1("example_input.txt"))
|
||||
|
||||
def test_part2(self):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
main(verbosity=2)
|
@ -1,5 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
DAY=`date "+%-e"`
|
||||
mkdir day${DAY}
|
||||
if [ ! -d day${DAY0} ]; then
|
||||
mkdir day${DAY}
|
||||
cp template/* day${DAY}
|
||||
fi
|
||||
# You have to get your cookie header in text format (Cookie: session=xxxx)
|
||||
wget --verbose --header "`cat cookies.txt`" "https://adventofcode.com/2023/day/${DAY}/input" -O day${DAY}/input.txt
|
Loading…
x
Reference in New Issue
Block a user