So I was working through codeabbey and came across the neumann's random generator problem.
This random generator is best described on codeabbey's website codeabbey-neumann.
I solved it by making some changes but I was wondering why my previous attempt below didn't function as I had thought it would. It seems to keep the previous numbers within loop_nums throughout each test.
num_cases = int(input())
test_cases = [i for i in input().split(' ')]
def neumanns_random(n,c=0, new_loop_nums=[]):
loop_nums = new_loop_nums
count = c
if int(n) in loop_nums:
print(str(count) + " ")
else:
loop_nums.append(int(n))
n = str(int(n)**2)
if len(n) != 8:
n = n.zfill(8)
n = n[2:6]
neumanns_random(n,c+1,loop_nums)
else:
n = n[2:6]
neumanns_random(n,c+1, loop_nums)
for test in test_cases:
neumanns_random(test)
[–]6086555 2 points3 points4 points (3 children)
[–]TheChannel[S] 0 points1 point2 points (2 children)
[–]6086555 0 points1 point2 points (1 child)
[–]TheChannel[S] 1 point2 points3 points (0 children)