Last active
January 1, 2016 22:19
-
-
Save jackhooper/8208835 to your computer and use it in GitHub Desktop.
Translation of the Ruby version. Should work in either Python 2.x or 3.x. Everything I said in the description of the Ruby version applies here, although I will point out that this version is probably faster simply because Python is generally faster than Ruby (assuming we're talking about CPython vs YARV or MRI - JRuby vs Jython may be a differe…
This file contains 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
# Returns True or False depending on whether a given number (n) is prime | |
# Translated from Ruby version | |
# Jack Hooper 2014 | |
def is_prime(n): | |
if n <= 1: | |
return False | |
if n == 2: | |
return True | |
for i in range(2, n): | |
if n % i == 0: return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment