Skip to content

Instantly share code, notes, and snippets.

@sadasant
Created February 5, 2012 23:57
Show Gist options
  • Save sadasant/1748483 to your computer and use it in GitHub Desktop.
Save sadasant/1748483 to your computer and use it in GitHub Desktop.
Euler Problem 5 in JavaScript
// Euclidean Algorithm
function gcd(a,b) { while (b) { var t = b; b = a%b; a = t } return a }
function lcm() { return Array.prototype.reduce.call(arguments, function(a,b){ return (a*b)/gcd(a,b) }) }
// http://projecteuler.net/problem=5
// lcm(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1,18,19,20)
// but we only need... ehm... primes but from last to first?
lcm(20, 19, 18, 17, 16, 15, 14, 13, 12, 11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment