Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Created April 24, 2017 02:12
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 hyuki0000/8a84085715545078942163abf4d01aff to your computer and use it in GitHub Desktop.
Save hyuki0000/8a84085715545078942163abf4d01aff to your computer and use it in GitHub Desktop.
円周率のような数字列を頭から見て素数を探す
#!/usr/bin/env ruby
require 'prime'
s = "31415926535"
s.length.times do |k|
t = s[0..k].to_i
if t.prime?
puts "#{t} is prime."
else
puts "#{t} is not prime."
end
end
@hyuki0000
Copy link
Author

3 is prime.
31 is prime.
314 is not prime.
3141 is not prime.
31415 is not prime.
314159 is prime.
3141592 is not prime.
31415926 is not prime.
314159265 is not prime.
3141592653 is not prime.
31415926535 is not prime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment