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 2019/02

+34
+31
2019/day02.py
··· 1 + import fileinput 2 + 3 + TARGET = 19690720 4 + NOUN_1 = 12 5 + VERB_1 = 2 6 + 7 + TAPE = [int(x) for x in fileinput.input()[0].split(',')] 8 + 9 + for noun in range(100): 10 + for verb in range(100): 11 + tape = TAPE[:] 12 + pc = 0 13 + tape[1] = noun 14 + tape[2] = verb 15 + 16 + while pc < len(tape): 17 + opcode = tape[pc] 18 + if opcode == 1: 19 + tape[tape[pc + 3]] = tape[tape[pc + 1]] + tape[tape[pc + 2]] 20 + pc += 4 21 + elif opcode == 2: 22 + tape[tape[pc + 3]] = tape[tape[pc + 1]] * tape[tape[pc + 2]] 23 + pc += 4 24 + elif opcode == 99: 25 + result = tape[0] 26 + if result == TARGET: 27 + print "100 * noun + verb =", 100 * noun + verb 28 + elif noun == NOUN_1 and verb == VERB_1: 29 + print "Value in position 0 for Part 1:", result 30 + 31 + break
+1
2019/inputs/02.txt
··· 1 + 1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,10,1,19,1,19,6,23,2,13,23,27,1,27,13,31,1,9,31,35,1,35,9,39,1,39,5,43,2,6,43,47,1,47,6,51,2,51,9,55,2,55,13,59,1,59,6,63,1,10,63,67,2,67,9,71,2,6,71,75,1,75,5,79,2,79,10,83,1,5,83,87,2,9,87,91,1,5,91,95,2,13,95,99,1,99,10,103,1,103,2,107,1,107,6,0,99,2,14,0,0
+2
2019/outputs/02.txt
··· 1 + 2842648 2 + 9074