Jump to content

Python and Euler #14

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Reason7194

Reason7194

    Newbie

  • Members
  • Pip
  • 1 posts
Hey all, I am trying to solve Project Euler problem #14 and I just do not understand what is wrong with my code:

MrList = []

n = 2

max = 0

def check(n):

	global max

	MrList.append(n)

	while(n > 1):

		if(n%2 == 0):

			n = n /2

			MrList.append(n)

		else:

			n = (3 * n) + 1

			MrList.append(n)

	if(len(MrList) > max):

		max = len(MrList)



while(n < 1,000,000):

	MrList = []

	check(n)

	n = n + 1


print MrList

print max

I don't want the answer to the problem, but can someone just tell me what my logical errors are? I am super stuck


EDit: I wasn't correctly solving for the right problem lol..

#2
JackomoLight

JackomoLight

    Newbie

  • Members
  • PipPipPip
  • 38 posts

while(n < 1,000,000):

MrList = []

check(n)

n = n + 1



It needs to be:


MrList = []

while
(n < 1,000,000):

check(n)

n = n + 1


Sorry for the bad indent I am newbie and have no idea how to fix it






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users