2020: d10: ex1: add solution

This commit is contained in:
Bruno BELANYI 2020-12-10 07:29:12 +01:00
parent ed5cdb1a95
commit 386c912dbe

32
2020/d10/ex1/ex1.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import sys
from collections import defaultdict
from typing import Dict, List
def make_chain(adapters: List[int]) -> int:
adapters = sorted(adapters)
output = 0
device = adapters[-1] + 3
jolts: Dict[int, int] = defaultdict(int)
for adapter in adapters:
delt = adapter - output
jolts[delt] += 1
output = adapter
jolts[device - output] += 1
return jolts[1] * jolts[3]
def solve(raw: List[str]) -> int:
return make_chain([int(line) for line in raw])
def main() -> None:
input = [line.strip() for line in sys.stdin.readlines()]
print(solve(input))
if __name__ == "__main__":
main()