Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,14 @@
|
|||
function LCM(A) // A is an integer array (e.g. [-50,25,-45,-18,90,447])
|
||||
{
|
||||
var n = A.length, a = Math.abs(A[0]);
|
||||
for (var i = 1; i < n; i++)
|
||||
{ var b = Math.abs(A[i]), c = a;
|
||||
while (a && b){ a > b ? a %= b : b %= a; }
|
||||
a = Math.abs(c*A[i])/(a+b);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
/* For example:
|
||||
LCM([-50,25,-45,-18,90,447]) -> 67050
|
||||
*/
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// gcd :: Integral a => a -> a -> a
|
||||
let gcd = (x, y) => {
|
||||
let _gcd = (a, b) => (b === 0 ? a : _gcd(b, a % b)),
|
||||
abs = Math.abs;
|
||||
return _gcd(abs(x), abs(y));
|
||||
}
|
||||
|
||||
// lcm :: Integral a => a -> a -> a
|
||||
let lcm = (x, y) =>
|
||||
x === 0 || y === 0 ? 0 : Math.abs(Math.floor(x / gcd(x, y)) * y);
|
||||
|
||||
// TEST
|
||||
return lcm(12, 18);
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue