require "prime"
def truncatable?(prime)
string = prime.to_s
string.length.times do |index|
ltr = string[index..-1].to_i
rtl = string[0..-1 - index].to_i
return false unless Prime.prime?(ltr)
return false unless Prime.prime?(rtl)
end
true
end
primes = Prime.each.lazy
.drop(4) # skip 2, 3, 5, 7
.select { |prime| truncatable?(prime) }
.take(11)
.force
puts primes
cmVxdWlyZSAicHJpbWUiCgpkZWYgdHJ1bmNhdGFibGU/KHByaW1lKQogIHN0cmluZyA9IHByaW1lLnRvX3MKICBzdHJpbmcubGVuZ3RoLnRpbWVzIGRvIHxpbmRleHwKICAgIGx0ciA9IHN0cmluZ1tpbmRleC4uLTFdLnRvX2kKICAgIHJ0bCA9IHN0cmluZ1swLi4tMSAtIGluZGV4XS50b19pCgogICAgcmV0dXJuIGZhbHNlIHVubGVzcyBQcmltZS5wcmltZT8obHRyKQogICAgcmV0dXJuIGZhbHNlIHVubGVzcyBQcmltZS5wcmltZT8ocnRsKQogIGVuZAoKICB0cnVlCmVuZAoKcHJpbWVzID0gUHJpbWUuZWFjaC5sYXp5CiAgLmRyb3AoNCkgIyBza2lwIDIsIDMsIDUsIDcKICAuc2VsZWN0IHsgfHByaW1lfCB0cnVuY2F0YWJsZT8ocHJpbWUpIH0KICAudGFrZSgxMSkKICAuZm9yY2UKCnB1dHMgcHJpbWVzCg==