fork download
  1. require "prime"
  2.  
  3. def truncatable?(prime)
  4. string = prime.to_s
  5. string.length.times do |index|
  6. ltr = string[index..-1].to_i
  7. rtl = string[0..-1 - index].to_i
  8.  
  9. return false unless Prime.prime?(ltr)
  10. return false unless Prime.prime?(rtl)
  11. end
  12.  
  13. true
  14. end
  15.  
  16. primes = Prime.each.lazy
  17. .drop(4) # skip 2, 3, 5, 7
  18. .select { |prime| truncatable?(prime) }
  19. .take(11)
  20. .force
  21.  
  22. puts primes
  23.  
Runtime error #stdin #stdout #stderr 0.02s 7696KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.rb:17:in `<main>': undefined method `lazy' for #<Prime::EratosthenesGenerator:0x8775198> (NoMethodError)