(Original story) I'd like to increase or decrease the number by programming http://blog.livedoor.jp/itsoku/archives/39361879.html
--
I tried it with Python
#Generator that increases or decreases the value by size
def repeat_range(range_size, offset = 0):
def repeat_gen():
signed = 1
i = -1
while True:
i += signed
if i == 0 :
signed = 1
if i == range_size -1:
signed = -1
yield i + offset
return repeat_gen()
#Create iterations 1 to 4
repeat4 = repeat_range(4, 1)
for i in range(10):
print repeat4.next(),
result
1 2 3 4 3 2 1 2 3 4
Recommended Posts