Bugfix in Syracuse sequence.

This commit is contained in:
cedricbonhomme 2011-12-28 18:40:32 +01:00
parent 98bebe3117
commit 8c51a96cf9

View file

@ -104,13 +104,13 @@ def syracuse(l=15):
while True: while True:
yield syracuse_gen(n, l) yield syracuse_gen(n, l)
n += 1 n += 1
def syracuse_gen(n, l=15): def syracuse_gen(n, l=15):
if n == 0: if n == 0:
return l return l
if n % 2 == 0: if syracuse_gen(n-1) % 2 == 0:
return syracuse_gen(n-1)/2 return syracuse_gen(n-1)/2
elif n % 2 == 1: elif syracuse_gen(n-1) % 2 == 1:
return 3*syracuse_gen(n-1)+1 return 3*syracuse_gen(n-1)+1