blob: 727c5b15297ef5a90fcd68159217d9ae0047c0b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#!/usr/bin/python3
# Challenge 014
#
# Challenge #1
# Write a script to generate Van Eck's sequence starts with 0. For more
# information, please check out wikipedia page. This challenge was proposed by
# team member Andrezgz.
def van_eck_iter():
hist = []
# first two terms
hist.append(0)
yield hist[-1]
hist.append(0)
yield hist[-1]
while True:
found = False
for m in range(len(hist)-2, -1, -1):
if hist[m]==hist[-1]:
hist.append(len(hist)-1-m)
yield hist[-1]
found = True
break
if not found:
hist.append(0)
yield hist[-1]
sep = ""
output = ""
count = 0
for n in van_eck_iter():
output += sep + str(n)
sep = ", "
count += 1
if count >= 96:
break
print(output)
|