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] content = [2,0,6,12,1,3]
spoken = {} spoken = {}
new_number = 0 new_spoken = 0
last_spoken = 0
turn = 1 turn = 1
for c in content: for c in content:
spoken[c] = turn spoken[c] = turn
last_spoken = c
turn += 1 turn += 1
was_new = True last_turn = 0
for turn in range(len(content) + 1, 2021): while turn <= 2020:
if was_new: if not last_turn:
new_spoken = 0 new_spoken = 0
else: else:
new_spoken = turn - 1 - last_turn new_spoken = turn - 1 - last_turn
was_new = new_spoken not in spoken last_turn = spoken.get(new_spoken, 0)
if not was_new:
last_turn = spoken[new_spoken]
spoken[new_spoken] = turn 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] content = [2,0,6,12,1,3]
spoken = {} spoken = {}
new_number = 0 new_spoken = 0
last_spoken = 0
turn = 1 turn = 1
for c in content: for c in content:
spoken[c] = turn spoken[c] = turn
last_spoken = c
turn += 1 turn += 1
was_new = True last_turn = 0
for turn in range(len(content) + 1, 30000001): while turn <= 30000000:
if was_new: if not last_turn:
new_spoken = 0 new_spoken = 0
else: else:
new_spoken = turn - 1 - last_turn new_spoken = turn - 1 - last_turn
was_new = new_spoken not in spoken last_turn = spoken.get(new_spoken, 0)
if not was_new:
last_turn = spoken[new_spoken]
spoken[new_spoken] = turn spoken[new_spoken] = turn
last_spoken = new_spoken turn += 1
print(last_spoken) print(new_spoken)