Changement d'ordi! (Non le jour 12 n'est pas terminé)

This commit is contained in:
2023-12-13 08:08:13 +01:00
parent a9d7c6a101
commit 6df1e1c3ec
9 changed files with 109 additions and 6 deletions

View File

@@ -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])

View File

@@ -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))))

View File

@@ -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 = [