From f2d01c9f410a1cebaf6885fea4f89ea47d5787d5 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 14 Dec 2020 23:21:29 -0600 Subject: [PATCH] 15 --- 15.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 15.py diff --git a/15.py b/15.py new file mode 100644 index 0000000..685e25d --- /dev/null +++ b/15.py @@ -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))