diff options
Diffstat (limited to '2021/06')
-rw-r--r-- | 2021/06/.gitignore | 1 | ||||
-rw-r--r-- | 2021/06/Makefile | 8 | ||||
-rw-r--r-- | 2021/06/input | 1 | ||||
-rw-r--r-- | 2021/06/puzzles.py | 31 |
4 files changed, 41 insertions, 0 deletions
diff --git a/2021/06/.gitignore b/2021/06/.gitignore new file mode 100644 index 0000000..ffc46fe --- /dev/null +++ b/2021/06/.gitignore @@ -0,0 +1 @@ +puzzle-[12].py diff --git a/2021/06/Makefile b/2021/06/Makefile new file mode 100644 index 0000000..9f2e236 --- /dev/null +++ b/2021/06/Makefile @@ -0,0 +1,8 @@ +all: + m4 -D DAYS=80 puzzles.py | sed '/START PART 2/,/END PART 2/d' >puzzle-1.py + m4 -D DAYS=256 puzzles.py | sed '/START PART 1/,/END PART 1/d' >puzzle-2.py + chmod +x puzzle-[12].py + +.PHONY: clean +clean: + rm -f puzzle-[12].py diff --git a/2021/06/input b/2021/06/input new file mode 100644 index 0000000..229caa9 --- /dev/null +++ b/2021/06/input @@ -0,0 +1 @@ +1,2,1,1,1,1,1,1,2,1,3,1,1,1,1,3,1,1,1,5,1,1,1,4,5,1,1,1,3,4,1,1,1,1,1,1,1,5,1,4,1,1,1,1,1,1,1,5,1,3,1,3,1,1,1,5,1,1,1,1,1,5,4,1,2,4,4,1,1,1,1,1,5,1,1,1,1,1,5,4,3,1,1,1,1,1,1,1,5,1,3,1,4,1,1,3,1,1,1,1,1,1,2,1,4,1,3,1,1,1,1,1,5,1,1,1,2,1,1,1,1,2,1,1,1,1,4,1,3,1,1,1,1,1,1,1,1,5,1,1,4,1,1,1,1,1,3,1,3,3,1,1,1,2,1,1,1,1,1,1,1,1,1,5,1,1,1,1,5,1,1,1,1,2,1,1,1,4,1,1,1,2,3,1,1,1,1,1,1,1,1,2,1,1,1,2,3,1,2,1,1,5,4,1,1,2,1,1,1,3,1,4,1,1,1,1,3,1,2,5,1,1,1,5,1,1,1,1,1,4,1,1,4,1,1,1,2,2,2,2,4,3,1,1,3,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,5,1,1,4,2,1,1,2,5,4,2,1,1,1,1,4,2,3,5,2,1,5,1,3,1,1,5,1,1,4,5,1,1,1,1,4 diff --git a/2021/06/puzzles.py b/2021/06/puzzles.py new file mode 100644 index 0000000..93dcfea --- /dev/null +++ b/2021/06/puzzles.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + + +# This is not my original solution, that one involved numpy and some more ugly code, but after +# seeing this solution I couldn't help but realize how obvious it was. + + +import collections +from typing import Counter + + +def main() -> None: + with open("input", "r", encoding="utf-8") as f: + acc = collections.Counter(map(int, f.read().split(","))) + + for _ in range(DAYS): + counts: Counter[int] = collections.Counter() + for a, c in acc.items(): + if a: + counts[a - 1] += c + else: + counts[6] += c + counts[8] += c + + acc = counts + + print(sum(acc.values())) + + +if __name__ == "__main__": + main() |