diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-10-29 23:02:39 +0200 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-10-29 23:02:39 +0200 |
commit | e7c9108b95e39d7ea5a29ae06d619c4727f11027 (patch) | |
tree | 237261eef3afd0720be77dbcbb9599fa66a24b67 /2020/16/puzzle-1.py |
Initial commit
Diffstat (limited to '2020/16/puzzle-1.py')
-rwxr-xr-x | 2020/16/puzzle-1.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/2020/16/puzzle-1.py b/2020/16/puzzle-1.py new file mode 100755 index 0000000..f4343c8 --- /dev/null +++ b/2020/16/puzzle-1.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + + +def main() -> None: + with open("input", "r") as f: + data = f.readlines() + + i = 0 + valid: list[int] = [] + while data[i] != "\n": + ranges = data[i].split(": ")[1].split(" or ") + for _range in ranges: + bounds = tuple(map(int, _range.split("-"))) + for j in range(bounds[0], bounds[1] + 1): + valid.append(j) + i += 1 + + # Skip to nearby tickets + i += 5 + acc = 0 + + for j in range(i, len(data)): + fields = tuple(map(int, data[j].split(","))) + acc += sum(field for field in fields if field not in valid) + + print(acc) + + +if __name__ == "__main__": + main() |