Skip to content

Commit

Permalink
38,39,48 solved, 48 is so easy
Browse files Browse the repository at this point in the history
  • Loading branch information
wengjn committed Mar 24, 2012
1 parent aeeadb9 commit a9f6e59
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 10 additions & 3 deletions solutions/38.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
'''
What is the largest 1 to 9 pandigital 9-digit number that can be formed
as the concatenated product of an integer with(1,2..n) where n>1
starting with n=2
9?*1++9?*2 and 9??*1+9??*2 they will never yield a 9digit number
but 9???*1+9???*2 will, so our starting search must be a 4 digit number
beginnning with 9 and never contain 0
it should be obvious that any n>2 is impossible
'''
def isPandigital(n, s=9):
n = str(n)
return len(n)==s and not '1234567890'[:s].strip(n)

def main():
for i in range(1000000000, 918273644, -1):
if isPandigital(i):
#
for i in range(9876, 9123, -1):
p = str(i*1)+ str(i*2)
if isPandigital(int(p)):
print p
break

if __name__ == '__main__':
main()
22 changes: 22 additions & 0 deletions solutions/39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/python
# filename: 39.py

'''
If p is the perimeter of a right angle triangle {a,b,c},which value
for p<=1000, has the most solutions?
interesting: a+b+c=p and a**2+b**2=c**2
'''

def main():
t_max=0
p_limit = 1000
for p in range(p_limit/2, p_limit+1, 2):
t = 0
for a in range(2, p/4+1):
if p*(p-2*a)%(2*(p-a))==0: t+=1
if t> t_max: (t_max, p_max) = (t,p)

print p_max

if __name__ == '__main__':
main()

0 comments on commit a9f6e59

Please sign in to comment.