[Python/2017] Move solutions into .py files
This commit is contained in:
parent
fbc5fda60f
commit
7b1efc0d9c
51 changed files with 1100 additions and 4546 deletions
42
Python/2017/23.py
Normal file
42
Python/2017/23.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2017, 23)
|
||||
|
||||
lines = input.splitlines()
|
||||
|
||||
|
||||
registers = {chr(i): 0 for i in range(97, 105)}
|
||||
pc = 0
|
||||
out = 0
|
||||
while pc in range(len(lines)):
|
||||
cmd, *args = lines[pc].split()
|
||||
get = lambda a: registers[a] if a in registers else int(a)
|
||||
if cmd == "set":
|
||||
registers[args[0]] = get(args[1])
|
||||
elif cmd == "sub":
|
||||
registers[args[0]] -= get(args[1])
|
||||
elif cmd == "mul":
|
||||
registers[args[0]] *= get(args[1])
|
||||
out += 1
|
||||
elif cmd == "jnz":
|
||||
if get(args[0]):
|
||||
pc += get(args[1])
|
||||
continue
|
||||
pc += 1
|
||||
|
||||
print(out)
|
||||
|
||||
|
||||
b = 109900 - 17
|
||||
h = 0
|
||||
while b != 126900:
|
||||
b += 17
|
||||
f = 1
|
||||
for d in range(2, b):
|
||||
if b % d == 0:
|
||||
f = 0
|
||||
break
|
||||
if f == 0:
|
||||
h += 1
|
||||
|
||||
print(h)
|
Loading…
Add table
Add a link
Reference in a new issue