Created
September 4, 2021 10:47
-
-
Save thomasjslone/d83dadd7786b4473817fb2a5657a2a97 to your computer and use it in GitHub Desktop.
The ruby prime method converted to python.
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
# | |
# Python | |
# | |
def prime(num): | |
rv=True;c=1;l=num-1 | |
while c<l: | |
c=c+1 | |
if int(str(num/c).split('.')[-1])==0: | |
rv=False;c=num | |
return rv | |
## | |
## Ruby | |
## | |
def prime? n | |
rv=true;c=1;l=n-1 | |
until c>=l | |
c+=1 | |
if (n.to_f/c.to_f).to_s.split(".")[-1].to_i==0 | |
rv=false;c=n | |
end | |
end | |
return rv | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment