diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-12-06 06:57:57 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-12-06 06:57:57 +0100 |
commit | 7a58c33804fde0a070aa6faabb0ca385c324f61a (patch) | |
tree | fc933255743ff59c86669cc723d86df72e1c5931 /2021/06/puzzles.py | |
parent | 396d7ae9cd0b67483293553b2e0a966a98356c4a (diff) |
Add day 6 solutions
Diffstat (limited to '2021/06/puzzles.py')
-rw-r--r-- | 2021/06/puzzles.py | 31 |
1 files changed, 31 insertions, 0 deletions
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() |