2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1 +1,12 @@
|
|||
def pairs: while( .[0] > 0; [ (.[0] | halve), (.[1] | double) ]);
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -1,15 +1 @@
|
|||
def halve: (./2) | floor;
|
||||
|
||||
def double: 2 * .;
|
||||
|
||||
def isEven: . % 2 == 0;
|
||||
|
||||
def ethiopian_multiply(a;b):
|
||||
def pairs: recurse( if .[0] > 0
|
||||
then [ (.[0] | halve), (.[1] | double) ]
|
||||
else empty
|
||||
end );
|
||||
reduce ([a,b] | pairs
|
||||
| select( .[0] | isEven | not)
|
||||
| .[1] ) as $i
|
||||
(0; . + $i) ;
|
||||
ethMult('Ethiopian', 34)
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
ethiopian_multiply(17;34) # => 578
|
||||
def pairs: while( .[0] > 0; [ (.[0] | halve), (.[1] | double) ]);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
def halve: (./2) | floor;
|
||||
|
||||
def double: 2 * .;
|
||||
|
||||
def isEven: . % 2 == 0;
|
||||
|
||||
def ethiopian_multiply(a;b):
|
||||
def pairs: recurse( if .[0] > 0
|
||||
then [ (.[0] | halve), (.[1] | double) ]
|
||||
else empty
|
||||
end );
|
||||
reduce ([a,b] | pairs
|
||||
| select( .[0] | isEven | not)
|
||||
| .[1] ) as $i
|
||||
(0; . + $i) ;
|
||||
|
|
@ -0,0 +1 @@
|
|||
ethiopian_multiply(17;34) # => 578
|
||||
Loading…
Add table
Add a link
Reference in a new issue