Skip to content

Instantly share code, notes, and snippets.

@vulcansmithy
Created July 22, 2022 15:36
Show Gist options
  • Select an option

  • Save vulcansmithy/cfd4b3d0d040f15c45ad9aba036077e2 to your computer and use it in GitHub Desktop.

Select an option

Save vulcansmithy/cfd4b3d0d040f15c45ad9aba036077e2 to your computer and use it in GitHub Desktop.
Calculate Prime Number
=begin
Prime Time
Have the function PrimeTime(num) take the num parameter
being passed and return the string true if the parameter is
a prime number, otherwise return the string false. The
range will be between 1 and 2^16.
Examples
Input: 19
Output: true
Input: 110
Output: false
=end
def PrimeTime(num)
num < 2 ? false : (2..(num/2)).none? {|i| num % i == 0}
end
# keep this function call here
puts PrimeTime(STDIN.gets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment