My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2018/14

+48
+45
2018/day14.py
··· 1 + import fileinput 2 + from itertools import count 3 + 4 + 5 + def slice_to_str(slice): 6 + return ''.join(str(n) for n in slice) 7 + 8 + 9 + INPUT = int(fileinput.input()[0]) 10 + input_str = str(INPUT) 11 + input_len = len(input_str) 12 + 13 + recipes = [3, 7] 14 + recipes_len = 2 15 + elf_1 = 0 16 + elf_2 = 1 17 + 18 + part_1 = None 19 + part_2 = None 20 + 21 + while part_1 is None or part_2 is None: 22 + score = recipes[elf_1] + recipes[elf_2] 23 + if score >= 10: 24 + recipes.append(score // 10) 25 + recipes.append(score % 10) 26 + recipes_len += 2 27 + else: 28 + recipes.append(score) 29 + recipes_len += 1 30 + 31 + elf_1 = (elf_1 + recipes[elf_1] + 1) % recipes_len 32 + elf_2 = (elf_2 + recipes[elf_2] + 1) % recipes_len 33 + 34 + if part_1 is None and recipes_len > INPUT + 10: 35 + part_1 = slice_to_str(recipes[INPUT:INPUT+10]) 36 + 37 + if part_2 is None: 38 + if score >= 10 and slice_to_str(recipes[-1-input_len:-1]) == input_str: 39 + part_2 = recipes_len - input_len - 1 40 + 41 + if slice_to_str(recipes[-input_len:]) == input_str: 42 + part_2 = recipes_len - input_len 43 + 44 + print "Scores of recipes after puzzle input:", part_1 45 + print "Number of recipes before puzzle input:", part_2
+1
2018/inputs/14.txt
··· 1 + 505961
+2
2018/outputs/14.txt
··· 1 + 9315164154 2 + 20231866