Ormiston triples: Difference between revisions

Content added Content deleted
(→‎{{header|Ruby}}: anagram, not palindrome.)
Line 2,122: Line 2,122:
require 'prime'
require 'prime'


def all_palin?(arr)
def all_anagram?(arr)
sorted = arr.first.digits.sort
sorted = arr.first.digits.sort
arr[1..].all?{|a| a.digits.sort == sorted}
arr[1..].all?{|a| a.digits.sort == sorted}
end
end


res = Prime.each.each_cons(3).lazy.filter_map{|ar| ar.first if all_palin?(ar)}.first(25)
res = Prime.each.each_cons(3).lazy.filter_map{|ar| ar.first if all_anagram?(ar)}.first(25)
res.each_slice(5){|slice| puts slice.join(", ")}
res.each_slice(5){|slice| puts slice.join(", ")}


n = 1E9
n = 1E9
res = Prime.each(n).each_cons(3).count {|ar| all_palin?(ar)}
res = Prime.each(n).each_cons(3).count {|ar| all_anagram?(ar)}
puts "\nThere are #{res} Ormiston triples below #{n}"
puts "\nThere are #{res} Ormiston triples below #{n}"
</syntaxhighlight>
</syntaxhighlight>