Skip to content

Instantly share code, notes, and snippets.

@cherenkov
Created February 24, 2016 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cherenkov/75242ab572084f65ffd1 to your computer and use it in GitHub Desktop.
Save cherenkov/75242ab572084f65ffd1 to your computer and use it in GitHub Desktop.
エラトステネスのふるい(おみくじ付き) #PictRuby
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