]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blob - day10/get_adaptor_chain.py
Day 14 - implemented in bash, because, well, I could
[advent-of-code-2020.git] / day10 / get_adaptor_chain.py
1 #!/usr/bin/python3
2
3 import sys
4
5 filename=(len(sys.argv) > 1) and sys.argv[1] or "22_10.txt"
6
7 cur_jolts=0
8 adaptors=[int(line.rstrip()) for line in open(filename, "r")]
9 adaptors.sort()
10 end_jolts=adaptors[-1]+3
11
12 diff_counts={}
13
14 for adaptor in adaptors:
15     if adaptor-cur_jolts == 3:
16         if 3 not in diff_counts:
17             diff_counts[3]=0
18         diff_counts[3]+=1
19     elif adaptor-cur_jolts == 1:
20         if 1 not in diff_counts:
21             diff_counts[1]=0
22         diff_counts[1]+=1
23     else:
24         raise Exception("Diff is not 1 or 3!")
25     cur_jolts=adaptor
26
27 diff_counts[3]+=1
28 print(diff_counts)
29 print(diff_counts[1] * diff_counts[3])