a bit simplified solution
This commit is contained in:
parent
d96d701f34
commit
041b87cd05
18
15/1.py
18
15/1.py
|
@ -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
18
15/2.py
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue