def Given(rn):
Given_lengths = [0] * 1000000
def rn2(n):
if not Given_lengths[n]:
Given_lengths[n] = rn(n)
return memoized_lengths[n]
return rn2

def cycle_length(n):
if n == 1: return 1
if n % 2:
return cycle_length(n * 3 + 1) + 1
return cycle_length(n / 2) + 1

def problem(i,j):
for x in range(i, j+1):
return max(cycle_length(x))


def test_cycle_length():
assert cycle_length(22) == 16
assert cycle_length(10) == 7
assert cycle_length(11) == 15
print('OK')

def test_problem():
print (1, 10, problem(1, 10))
print (100, 200, problem(100, 200))
print (201, 210, problem(201, 210))
print (900, 100, problem(900, 1000))

if __name__ == '__main__': test_problem()

getting error:
def problem(i,j):
for x in range(i, j+1):
return max(cycle_length(x))
'int' object is not iterable

Please use the code tag! -

(can't interpret your code,
when Python's blocks are defined by
whitespace,
but here they don't exist.
imagine C, C++, C#, Java without brackets)

class BeautifulIndent(object):
    @staticmethod
    def BeautifulIndentedMethod():
        pass

Your error is caused because int isn't iterable, so somewhere you have something like this:
for x in 3:
I have to repythonify your code before I figure out what is the cause.

EDIT:
Is this what you are trying to write in the problem() function?

def problem(i,j):
    a = []
    for x in range(i, j+1):
        a.append(cycle_length(x))
    return max(a)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.