Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -0,0 +1 @@
def pairs: while( .[0] > 0; [ (.[0] | halve), (.[1] | double) ]);

View file

@ -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) ;

View file

@ -0,0 +1 @@
ethiopian_multiply(17;34) # => 578