]> git.sommitrealweird.co.uk Git - advent-of-code-2020.git/blob - day10/get_adaptor_choices.py
Day 13 - forays in to using Diophantine did not go well.
[advent-of-code-2020.git] / day10 / get_adaptor_choices.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 adaptors=[int(line.rstrip()) for line in open(filename, "r")]
8 adaptors.sort()
9 end_jolts=adaptors[-1]+3
10
11 adaptors.insert(0, 0)
12 adaptors.append(end_jolts)
13
14 cur_configs=1
15
16 def get_choices():
17     choice_count=1
18     can_reach={}
19     paths={0:1}
20     for adaptor in adaptors:
21         can_reach[adaptor]=[a for a in adaptors if (a >= adaptor+1 and a <= adaptor+3)]
22
23     for adaptor in adaptors:
24         for adaptor2 in can_reach[adaptor]:
25             if adaptor2 not in paths:
26                 paths[adaptor2]=0
27             paths[adaptor2]+=paths[adaptor]
28
29     return paths[adaptors[-1]]
30
31 total = get_choices()
32
33 print("Maybe possibly all the configs")
34 print(total)