Compare commits

..

20 commits

Author SHA1 Message Date
Bruno BELANYI 68bb1132a9 2021: d06: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 022672fcd0 2021: d06: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI de0afa76fd 2021: d06: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 1e274be43f 2021: d06: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 9534e5c929 2021: d05: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI e5ecef7eed 2021: d05: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 614bf9d842 2021: d05: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 7cf9f46040 2021: d05: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI a26d95809d 2021: d04: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI f8ddf5f4fd 2021: d04: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 7ec10eecd1 2021: d04: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 8e96f33b91 2021: d04: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 465f22bbee 2021: d03: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI b78f5b1f40 2021: d03: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI 8c90ac89b3 2021: d03: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI f5a30ee2da 2021: d03: ex1: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI a6f9104cb4 2021: d02: ex2: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 8ebb134cdf 2021: d02: ex2: add input 2021-12-06 12:30:19 +01:00
Bruno BELANYI f728552afa 2021: d02: ex1: add solution 2021-12-06 12:30:19 +01:00
Bruno BELANYI 3761139723 2021: d02: ex1: add input 2021-12-06 12:30:19 +01:00
4 changed files with 88 additions and 0 deletions

43
2021/d06/ex1/ex1.py Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python
import itertools
import sys
from collections import Counter
from dataclasses import dataclass
from typing import Iterator, List, Tuple
def nth(iterable: Iterator[int], n: int) -> int:
return next(itertools.islice(iterable, n, None))
def solve(input: List[str]) -> int:
fish = [0] * 9
for n, count in Counter(map(int, input[0].split(","))).items():
fish[n] = count
def step(fish: List[int]) -> List[int]:
# Count how many clones happen
new_fish = fish[0]
# Do the next cycle
fish[0:-1] = fish[1:]
fish[6] += new_fish
fish[8] = new_fish # Override number of new fish
return fish
def iter(fish: List[int]) -> Iterator[List[int]]:
while True:
yield (fish := step(fish))
return sum(nth(iter(fish), 80 - 1))
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

1
2021/d06/ex1/input Normal file
View file

@ -0,0 +1 @@
3,1,4,2,1,1,1,1,1,1,1,4,1,4,1,2,1,1,2,1,3,4,5,1,1,4,1,3,3,1,1,1,1,3,3,1,3,3,1,5,5,1,1,3,1,1,2,1,1,1,3,1,4,3,2,1,4,3,3,1,1,1,1,5,1,4,1,1,1,4,1,4,4,1,5,1,1,4,5,1,1,2,1,1,1,4,1,2,1,1,1,1,1,1,5,1,3,1,1,4,4,1,1,5,1,2,1,1,1,1,5,1,3,1,1,1,2,2,1,4,1,3,1,4,1,2,1,1,1,1,1,3,2,5,4,4,1,3,2,1,4,1,3,1,1,1,2,1,1,5,1,2,1,1,1,2,1,4,3,1,1,1,4,1,1,1,1,1,2,2,1,1,5,1,1,3,1,2,5,5,1,4,1,1,1,1,1,2,1,1,1,1,4,5,1,1,1,1,1,1,1,1,1,3,4,4,1,1,4,1,3,4,1,5,4,2,5,1,2,1,1,1,1,1,1,4,3,2,1,1,3,2,5,2,5,5,1,3,1,2,1,1,1,1,1,1,1,1,1,3,1,1,1,3,1,4,1,4,2,1,3,4,1,1,1,2,3,1,1,1,4,1,2,5,1,2,1,5,1,1,2,1,2,1,1,1,1,4,3,4,1,5,5,4,1,1,5,2,1,3

43
2021/d06/ex2/ex2.py Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python
import itertools
import sys
from collections import Counter
from dataclasses import dataclass
from typing import Iterator, List, Tuple
def nth(iterable: Iterator[int], n: int) -> int:
return next(itertools.islice(iterable, n, None))
def solve(input: List[str]) -> int:
fish = [0] * 9
for n, count in Counter(map(int, input[0].split(","))).items():
fish[n] = count
def step(fish: List[int]) -> List[int]:
# Count how many clones happen
new_fish = fish[0]
# Do the next cycle
fish[0:-1] = fish[1:]
fish[6] += new_fish
fish[8] = new_fish # Override number of new fish
return fish
def iter(fish: List[int]) -> Iterator[List[int]]:
while True:
yield (fish := step(fish))
return sum(nth(iter(fish), 256 - 1))
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()

1
2021/d06/ex2/input Normal file
View file

@ -0,0 +1 @@
3,1,4,2,1,1,1,1,1,1,1,4,1,4,1,2,1,1,2,1,3,4,5,1,1,4,1,3,3,1,1,1,1,3,3,1,3,3,1,5,5,1,1,3,1,1,2,1,1,1,3,1,4,3,2,1,4,3,3,1,1,1,1,5,1,4,1,1,1,4,1,4,4,1,5,1,1,4,5,1,1,2,1,1,1,4,1,2,1,1,1,1,1,1,5,1,3,1,1,4,4,1,1,5,1,2,1,1,1,1,5,1,3,1,1,1,2,2,1,4,1,3,1,4,1,2,1,1,1,1,1,3,2,5,4,4,1,3,2,1,4,1,3,1,1,1,2,1,1,5,1,2,1,1,1,2,1,4,3,1,1,1,4,1,1,1,1,1,2,2,1,1,5,1,1,3,1,2,5,5,1,4,1,1,1,1,1,2,1,1,1,1,4,5,1,1,1,1,1,1,1,1,1,3,4,4,1,1,4,1,3,4,1,5,4,2,5,1,2,1,1,1,1,1,1,4,3,2,1,1,3,2,5,2,5,5,1,3,1,2,1,1,1,1,1,1,1,1,1,3,1,1,1,3,1,4,1,4,2,1,3,4,1,1,1,2,3,1,1,1,4,1,2,5,1,2,1,5,1,1,2,1,2,1,1,1,1,4,3,4,1,5,5,4,1,1,5,2,1,3