Skip to content

Instantly share code, notes, and snippets.

@rixtox
Last active August 29, 2015 13:58
Show Gist options
  • Save rixtox/9949594 to your computer and use it in GitHub Desktop.
Save rixtox/9949594 to your computer and use it in GitHub Desktop.
bigf = (n) ->
for i in [2..Math.sqrt n]
return n / i unless n % i
n
LPF = (n) ->
bf = bigf n
return bf if bf == n
LPF bf
console.log LPF 600851475143
factorize = (n) ->
for i in [2..Math.sqrt n]
continue if n % i
[i, n / i]
find = ->
for i in [997..0]
j = parseInt (''+i).split('').reverse().join('')
k = i*1000+j
f = factorize k
for [a, b] in f
if 99 < a && a < 1000 && 99 < b && b < 1000
return [a, b]
console.log find()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment