Skip to content

Instantly share code, notes, and snippets.

@CharlieTruong
Last active December 31, 2015 05:19
Show Gist options
  • Save CharlieTruong/7940170 to your computer and use it in GitHub Desktop.
Save CharlieTruong/7940170 to your computer and use it in GitHub Desktop.
def next_prime(number)
prime=false
while prime==false
number+=1
for i in 2..number
prime=true if i==number
break if number % i ==0
end
end
return number
end
def prime_factor(number)
factors=Array.new
prime=2
while prime<=number
if number % prime==0
until number % prime != 0
number=number/prime
factors.push(prime)
end
end
prime=next_prime(prime)
end
return factors.max
end
p prime_factor(600851475143)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment