Created
February 24, 2016 19:05
-
-
Save cherenkov/75242ab572084f65ffd1 to your computer and use it in GitHub Desktop.
エラトステネスのふるい(おみくじ付き) #PictRuby
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
def main | |
p = [] | |
x = Popup.input "入力した数の中から素数を探します" | |
x = x.to_i | |
s = [*2..x] | |
while (1) | |
t = s.shift | |
p << t | |
s.select! {|e| e % t != 0 } | |
break if (x**0.5) <= t | |
end | |
p += s | |
p p | |
p "length:#{p.size}" | |
Popup.msg "今日のラッキー素数は #{p.sample}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment