diff --git a/solutions/38.py b/solutions/38.py index e4f0422..968c9d0 100644 --- a/solutions/38.py +++ b/solutions/38.py @@ -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() diff --git a/solutions/39.py b/solutions/39.py new file mode 100644 index 0000000..3e1d9a5 --- /dev/null +++ b/solutions/39.py @@ -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()