Skip to content

Instantly share code, notes, and snippets.

@thomasjslone
Created September 4, 2021 10:47
Show Gist options
  • Save thomasjslone/d83dadd7786b4473817fb2a5657a2a97 to your computer and use it in GitHub Desktop.
Save thomasjslone/d83dadd7786b4473817fb2a5657a2a97 to your computer and use it in GitHub Desktop.
The ruby prime method converted to python.
#
# 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