Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active January 18, 2022 23:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/07e03e00f52ac65e60ca to your computer and use it in GitHub Desktop.
Save komasaru/07e03e00f52ac65e60ca to your computer and use it in GitHub Desktop.
Ruby script to check a prime number.
#! /usr/local/bin/ruby
# coding: utf-8
# --------------------------------------
# Check a prime number
# --------------------------------------
def is_prime(n)
res = (2..Math.sqrt(n)).any? { |i| n % i == 0 }
puts "#{n}: #{res || n == 1 ? '-----' : "PRIME"}"
end
is_prime(12345678923)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment