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

This commit is contained in:
Fedaya 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 = ""
@ -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

@ -4,4 +4,5 @@ from common import *
def part2(input_file: str) -> int:
return 0
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 = [

35
day13/common.py Normal file
View 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
View File

@ -0,0 +1,15 @@
#.##..##.
..#.##.#.
##......#
##......#
..#.##.#.
..##..##.
#.#.##.#.
#...##..#
#....#..#
..##..###
#####.##.
#####.##.
..##..###
#....#..#

7
day13/part1.py Executable file
View 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
View 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
View 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)

View File

@ -1,5 +1,9 @@
#!/bin/bash
DAY=`date "+%-e"`
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