2 Replies - 462 Views - Last Post: 28 August 2012 - 11:47 PM Rate Topic: -----

#1 alexr1090  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 124
  • Joined: 08-May 11

Some Project Euler pointers requested

Posted 28 August 2012 - 08:29 PM

Hi D.I.C. heads. I'm attempting to do some of the Project Euler problems. Right now I'm having trouble with problem 21 and I was hoping I could receive some help for it. I'm not necessarily looking for code, just a point in the right direction. Oh yeah and basically I know this is wrong because I looked up the answer. The correct answer is supposed to be
Spoiler

def getProperDivisors(x):
	ams = []
	for y in range(1,x):
		if x%y == 0: ams.append(y)
	return ams
def addProperDivisors(ams):
	total = 0
	for x in ams:
		total +=x
	return total 
total = 0
dictionary = {}
for x in range(2,10001):
	if x in dictionary: 
		if dictionary[x] < x:
			continue
		else:
			b = addProperDivisors(getProperDivisors(dictionary[x]))
			if b == dictionary[x]:
				total += dictionary[x]+ b
				continue
	a = addProperDivisors(getProperDivisors(x))
	dictionary[x] = a
	b = addProperDivisors(getProperDivisors(a))
	dictionary[a] = b
	if a == b:
		total += a+b
		
print total



Is This A Good Question/Topic? 0
  • +

Replies To: Some Project Euler pointers requested

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,203
  • Joined: 21-June 11

Re: Some Project Euler pointers requested

Posted 28 August 2012 - 11:07 PM

The condition for an amicable pair is that "d(a) = b and d(b) = a, where a ≠ b". Your if condition if a == b does not express that.

This post has been edited by sepp2k: 28 August 2012 - 11:07 PM

Was This Post Helpful? 1
  • +
  • -

#3 alexr1090  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 44
  • View blog
  • Posts: 124
  • Joined: 08-May 11

Re: Some Project Euler pointers requested

Posted 28 August 2012 - 11:47 PM

Hey thanks a lot man. That helped me solve it :turned:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1