This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'prime'; | |
h={};a=[] | |
Prime.each(999999){|e|h[e]=1;a.push(e)} | |
p a.count{|x|s=x.to_s;s.length.times.map{|i|h[(s[i,s.length-i]+s[0,i]).to_i]}.all?} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
p 999999.times.map{|i|s,t=i.to_s,i.to_s(2);s.reverse==s&&t.reverse==t ?i:0}.reduce(&:+) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
def pan(n) | |
m='' | |
1.step(9){|i| | |
x=m+(n*i).to_s | |
if x.length>9 then break end | |
m=x | |
} | |
1.step(9){|i| unless m.index(i.to_s) then return 0 end} | |
return m.to_i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
p 4.step(1000).map{|x|[ | |
1.step(x/2-1).map{ | |
|i|i.step(x-1-i).select{|j|k=x-i-j;i*i+j*j==k*k}.count | |
}.reduce(&:+),x | |
]}.max[1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
s=1.step(299999).map{|i|i.to_s}.join | |
p [s[0,1],s[9,1],s[99,1],s[999,1],s[9999,1],s[99999,1],s[999999,1]].map(&:to_i).reduce(&:*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'prime' | |
p [1,2,3,4,5,6,7].permutation.map{|a|a.map(&:to_s).join.to_i}.select(&:prime?).max |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
#wget -O - http://projecteuler.net/project/words.txt | |
h={} | |
1.step(100){|i|h[i*(i+1)/2]=1} | |
s=gets.chomp | |
a=eval('['+s+']').sort | |
r=0 | |
a.length.times{|i| | |
x=0 | |
a[i].each_byte{|n|x+=n-64} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
sum=0 | |
[0,1,2,3,4,5,6,7,8,9].permutation{|a| | |
if a[0]==0 then next end | |
s=a.map(&:to_i).join | |
if s[1,3].to_i%2==0 && s[2,3].to_i%3==0 && s[3,3].to_i%5==0 && s[4,3].to_i%7==0 && s[5,3].to_i%11==0 && s[6,3].to_i%13==0 && s[7,3].to_i%17==0 then sum+=s.to_i end | |
} | |
p sum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
a=1.step(9999).map{|i|i*(3*i-1)/2} | |
h={} | |
a.each{|e|h[e]=1} | |
b=[] | |
a.length.times{|i| | |
(i+1).step(a.length-1){|j| | |
if h[a[j]+a[i]] && h[a[j]-a[i]] then b.push(a[j]-a[i]) end | |
} | |
} |
OlderNewer