X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2020.git/blobdiff_plain/28a81dc1ba5ed0dfd92419d3a549a37b931fc9aa..83d85dde462ad0cab40462a2431e7cf6a1a9ba6c:/day10/get_adaptor_chain.py diff --git a/day10/get_adaptor_chain.py b/day10/get_adaptor_chain.py new file mode 100644 index 0000000..19c81f0 --- /dev/null +++ b/day10/get_adaptor_chain.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 + +import sys + +filename=(len(sys.argv) > 1) and sys.argv[1] or "22_10.txt" + +cur_jolts=0 +adaptors=[int(line.rstrip()) for line in open(filename, "r")] +adaptors.sort() +end_jolts=adaptors[-1]+3 + +diff_counts={} + +for adaptor in adaptors: + if adaptor-cur_jolts == 3: + if 3 not in diff_counts: + diff_counts[3]=0 + diff_counts[3]+=1 + elif adaptor-cur_jolts == 1: + if 1 not in diff_counts: + diff_counts[1]=0 + diff_counts[1]+=1 + else: + raise Exception("Diff is not 1 or 3!") + cur_jolts=adaptor + +diff_counts[3]+=1 +print(diff_counts) +print(diff_counts[1] * diff_counts[3])