15
This commit is contained in:
parent
0379a51019
commit
f2d01c9f41
1 changed files with 35 additions and 0 deletions
35
15.py
Normal file
35
15.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
ex=[0,3,6]
|
||||
|
||||
def iter(start):
|
||||
spoke=dict()
|
||||
lastSpokeD=dict()
|
||||
turn=0
|
||||
nextSpeak=None
|
||||
for i in start:
|
||||
turn+=1
|
||||
spoke[i]=turn
|
||||
yield i
|
||||
nextSpeak=0
|
||||
|
||||
while True:
|
||||
turn+=1
|
||||
yield nextSpeak
|
||||
lastSpoke=spoke.get(nextSpeak)
|
||||
spoke[nextSpeak]=turn
|
||||
|
||||
if lastSpoke is None:
|
||||
nextSpeak=0
|
||||
else:
|
||||
nextSpeak=turn-lastSpoke
|
||||
|
||||
if turn%3000000==0:
|
||||
print(f"turn {turn} of 30000000 ({100*turn/30000000.0}%)")
|
||||
|
||||
import itertools
|
||||
print(list(itertools.islice(iter(ex), 10)))
|
||||
|
||||
def nth(start, n):
|
||||
return next(x for i,x in enumerate(start) if i==n-1)
|
||||
|
||||
# print(nth(iter([0,3,6]), 30000000))
|
||||
print(nth(iter([5,1,9,18,13,8,0]), 30000000))
|
Loading…
Reference in a new issue