Skip to content

Instantly share code, notes, and snippets.

@cielavenir
Created August 28, 2012 18:35
Show Gist options
  • Select an option

  • Save cielavenir/3501863 to your computer and use it in GitHub Desktop.

Select an option

Save cielavenir/3501863 to your computer and use it in GitHub Desktop.
Project Euler 37
#!/usr/bin/ruby
require 'prime'
p=Prime::EratosthenesGenerator.new
a=[];h={}
h[p.next]=1;h[p.next]=1;h[p.next]=1;h[p.next]=1
while true do
e=p.next
h[e]=1
s=e.to_s
if (s.length-1).times{|i|
if !h[s[0,i+1].to_i]||!h[s[i+1,s.length-i-1].to_i] then break end
} then a.push(e) end
if a.length==11 then break end
end
p a.reduce(&:+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment