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]
|
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
18
15/2.py
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue