Last active
February 19, 2017 03:28
-
-
Save opan/7925ed05f192b563b270c9481ad2720a to your computer and use it in GitHub Desktop.
Generate palindromic prime numbers using Enum#lazy method
This file contains 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
n = gets.to_i | |
# Get infinity list of number | |
2.upto(Float::INFINITY) | |
# Use Enum#lazy method | |
.lazy | |
# Find prime number | |
.select { |i| (2..Math.sqrt(i)).none? { |a| (i % a).zero? }} | |
# Limit infinity list of number by 200 | |
.first(200) | |
# Find palindrome prime number | |
.select { |i| i.to_s == i.to_s.reverse }.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment