Ver código fonte

Day 2

master
Noëlle Anthony 5 anos atrás
pai
commit
6d07f3a414
3 arquivos alterados com 57 adições e 0 exclusões
  1. 26
    0
      2019/02a.py
  2. 30
    0
      2019/02b.py
  3. 1
    0
      2019/02in.txt

+ 26
- 0
2019/02a.py Ver arquivo

@@ -0,0 +1,26 @@
# Python 3.7

def main(debug):
instrs = ""
if debug:
instrs = "1,1,1,4,99,5,6,0,99"
else:
with open("02in.txt","r") as file:
instrs = file.readline()
instrs.strip('\n')
ints = [int(x) for x in instrs.split(',')]
if not debug:
ints[1] = 12
ints[2] = 2
i = 0
while ints[i] != 99:
if ints[i] == 1:
v = ints[ints[i+1]] + ints[ints[i+2]]
if ints[i] == 2:
v = ints[ints[i+1]] * ints[ints[i+2]]
ints[ints[i+3]] = v
i += 4
print(ints)

if __name__ == "__main__":
main(False)

+ 30
- 0
2019/02b.py Ver arquivo

@@ -0,0 +1,30 @@
# Python 3.7

import copy

def main():
instrs = ""
with open("02in.txt","r") as file:
instrs = file.readline()
instrs.strip('\n')
ints = [int(x) for x in instrs.split(',')]
default_ints = copy.deepcopy(ints)
for j in range(100):
for k in range(100):
ints = copy.deepcopy(default_ints)
ints[1] = j
ints[2] = k
i = 0
while ints[i] != 99:
if ints[i] == 1:
v = ints[ints[i+1]] + ints[ints[i+2]]
if ints[i] == 2:
v = ints[ints[i+1]] * ints[ints[i+2]]
ints[ints[i+3]] = v
i += 4
if ints[0] == 19690720:
print((100*j) + k)
return

if __name__ == "__main__":
main()

+ 1
- 0
2019/02in.txt Ver arquivo

@@ -0,0 +1 @@
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,6,19,1,19,6,23,2,23,6,27,2,6,27,31,2,13,31,35,1,9,35,39,2,10,39,43,1,6,43,47,1,13,47,51,2,6,51,55,2,55,6,59,1,59,5,63,2,9,63,67,1,5,67,71,2,10,71,75,1,6,75,79,1,79,5,83,2,83,10,87,1,9,87,91,1,5,91,95,1,95,6,99,2,10,99,103,1,5,103,107,1,107,6,111,1,5,111,115,2,115,6,119,1,119,6,123,1,123,10,127,1,127,13,131,1,131,2,135,1,135,5,0,99,2,14,0,0

Carregando…
Cancelar
Salvar