add day 15

This commit is contained in:
Juan José Gutiérrez de Quevedo Pérez 2020-12-15 10:04:21 +01:00
parent aeb3db0bdc
commit d96d701f34
2 changed files with 50 additions and 0 deletions

25
15/1.py Normal file
View file

@ -0,0 +1,25 @@
content = [2,0,6,12,1,3]
spoken = {}
new_number = 0
last_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:
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]
spoken[new_spoken] = turn
last_spoken = new_spoken
print(last_spoken)

25
15/2.py Normal file
View file

@ -0,0 +1,25 @@
content = [2,0,6,12,1,3]
spoken = {}
new_number = 0
last_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:
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]
spoken[new_spoken] = turn
last_spoken = new_spoken
print(last_spoken)