I am working on Project Euler problem 37 and I have the following program:
#!/usr/bin/ruby -w require 'prime' h=11 y=0 x=0 while x < 11 if h.prime? == true boo = true f=0 n=h c=0 while n > 0 f += (n%10) * 10**(10-c) n/=10 boo = false if n.prime? == false && n != 0 c+=1 end n=h c=10 while c > 0 n = n % (10**c) boo = false if n.prime? == false && n != 0 c-=1 end f /= 10 while f % 10 == 0 if boo == true y+=h x+=1 p h end end h+=2 end p y
It's designed to catch all of the eleven truncatable primes and does a good job of it, it catches the first ten is under one second, but it takes forty-nine seconds to find the last one, which happens to be, admittedly, a much larger number than the rest, is there any way to speed this up so that the eleventh one does not take so much time?