a bit simplified solution

This commit is contained in:
Juan José Gutiérrez de Quevedo Pérez 2020-12-15 10:21:30 +01:00
parent d96d701f34
commit 041b87cd05
2 changed files with 14 additions and 22 deletions

18
15/1.py
View file

@ -1,25 +1,21 @@
content = [2,0,6,12,1,3]
spoken = {}
new_number = 0
last_spoken = 0
new_spoken = 0
turn = 1
for c in content:
spoken[c] = turn
last_spoken = c
turn += 1
was_new = True
for turn in range(len(content) + 1, 2021):
if was_new:
last_turn = 0
while turn <= 2020:
if not last_turn:
new_spoken = 0
else:
new_spoken = turn - 1 - last_turn
was_new = new_spoken not in spoken
if not was_new:
last_turn = spoken[new_spoken]
last_turn = spoken.get(new_spoken, 0)
spoken[new_spoken] = turn
last_spoken = new_spoken
turn += 1
print(last_spoken)
print(new_spoken)

18
15/2.py
View file

@ -1,25 +1,21 @@
content = [2,0,6,12,1,3]
spoken = {}
new_number = 0
last_spoken = 0
new_spoken = 0
turn = 1
for c in content:
spoken[c] = turn
last_spoken = c
turn += 1
was_new = True
for turn in range(len(content) + 1, 30000001):
if was_new:
last_turn = 0
while turn <= 30000000:
if not last_turn:
new_spoken = 0
else:
new_spoken = turn - 1 - last_turn
was_new = new_spoken not in spoken
if not was_new:
last_turn = spoken[new_spoken]
last_turn = spoken.get(new_spoken, 0)
spoken[new_spoken] = turn
last_spoken = new_spoken
turn += 1
print(last_spoken)
print(new_spoken)