Created
July 22, 2022 15:36
-
-
Save vulcansmithy/cfd4b3d0d040f15c45ad9aba036077e2 to your computer and use it in GitHub Desktop.
Calculate Prime Number
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
| =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