diff options
| author | blenovo <bk@gmail.com> | 2025-07-16 18:55:48 +0200 |
|---|---|---|
| committer | blenovo <bk@gmail.com> | 2025-07-16 18:55:48 +0200 |
| commit | 99a7d62c30069a5ffe2210a72c7cf81e76a1f241 (patch) | |
| tree | 71c5c529b7f2fda9b5b5897a56a4ef3199400709 /2020/aoc2020-d10.py | |
| parent | 15662865f0886209d871a7225bfc62cffd2e0783 (diff) | |
summertime warmup session with 2020 event
Diffstat (limited to '2020/aoc2020-d10.py')
| -rw-r--r-- | 2020/aoc2020-d10.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/2020/aoc2020-d10.py b/2020/aoc2020-d10.py new file mode 100644 index 0000000..a86b976 --- /dev/null +++ b/2020/aoc2020-d10.py @@ -0,0 +1,39 @@ +#advent of code 2020 +#day 10 +#very similar (if not identical) to towels puzzle, 2024-d19 +#memorize previous paths and just sum up the valid paths for each adapter +#although this one i think is easier due to no duplicates +#and working on numbers instead of characters +bag = []; +PuzzleInput = open("10.in","r"); +for num in PuzzleInput: bag.append(int(num)); +PuzzleInput.close(); +#first and last items are from puzzle description +bag = [0] + [x for x in sorted(bag)] + [max(bag) +3]; +connections = dict(); +connections[1] = 0; +connections[2] = 0; +connections[3] = 0; +#since there are no duplicates and all adapters must be connected +#we can just check against the previous value for part 1; +for index in range(1,len(bag)): + adapter1 = bag[index]; + adapter2 = bag[index-1]; + diff = adapter1 - adapter2; + connections[diff] += 1; + +p1 = connections[1] * connections[3]; + +p2 = 0; +options = dict(); +options[0] = 1; +for index in range(1,len(bag)): + previous = bag[:index]; + possible = [x for x in previous if bag[index] - x <=3]; + options[bag[index]] = 0; + for poss in possible: + options[bag[index]] += options[poss]; + +p2 = options[max(bag)]; +print("part 1 =",p1); +print("part 2 =",p2); |
