Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
var eth = {
|
||||
|
||||
halve : function ( n ){ return Math.floor(n/2); },
|
||||
double: function ( n ){ return 2*n; },
|
||||
isEven: function ( n ){ return n%2 === 0); },
|
||||
|
||||
mult: function ( a , b ){
|
||||
var sum = 0, a = [a], b = [b];
|
||||
|
||||
while ( a[0] !== 1 ){
|
||||
a.unshift( eth.halve( a[0] ) );
|
||||
b.unshift( eth.double( b[0] ) );
|
||||
}
|
||||
|
||||
for( var i = a.length - 1; i > 0 ; i -= 1 ){
|
||||
|
||||
if( !eth.isEven( a[i] ) ){
|
||||
sum += b[i];
|
||||
}
|
||||
}
|
||||
return sum + b[0];
|
||||
}
|
||||
}
|
||||
// eth.mult(17,34) returns 578
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
function ethMult(m, n) {
|
||||
var o = !isNaN(m) ? 0 : ''; // same technique works with strings
|
||||
if (n < 1) return o;
|
||||
while (n > 1) {
|
||||
if (n & 1) o += m; // 3. integer odd/even? (bit-wise and 1)
|
||||
n >>= 1; // 1. integer halved (by right-shift)
|
||||
m += m; // 2. integer doubled (addition to self)
|
||||
}
|
||||
return o + m;
|
||||
}
|
||||
|
||||
ethMult(17, 34)
|
||||
|
|
@ -0,0 +1 @@
|
|||
ethMult('Ethiopian', 34)
|
||||
Loading…
Add table
Add a link
Reference in a new issue