Ethiopian multiplication: Difference between revisions
Content added Content deleted
m (add task to category) |
(added Ursala) |
||
Line 805: | Line 805: | ||
echo $(ethiopicmult 17 34)</lang> |
echo $(ethiopicmult 17 34)</lang> |
||
=={{header|Ursala}}== |
|||
The first implementation below relies on the representation of natural numbers as lists of bits, |
|||
lsb first, so that halving is the same as taking the tail, doubling |
|||
is inserting a zero, and filtering for oddness is filtering by the head, |
|||
all of which are expressible as primitives. |
|||
<lang Ursala> |
|||
#import nat |
|||
emul = @lrtK33PDNlCrXK9rhPFlS sum:-0 |
|||
</lang> |
|||
Here is a more verbose version (in keeping with the spirit of the task) treating natural numbers |
|||
as abstract types, and explicitly using the operators for distribution (*-), triangular iteration (|\), |
|||
and filtering (*~) among others. |
|||
<lang Ursala> |
|||
#import nat |
|||
emul = sum:-0@rS+ (odd@l)*~+ ^|(~&,double)|\+ *-^|\~& @iNC ~&h->tx :^/half@h ~& |
|||
</lang> |
|||
test program: |
|||
<lang Ursala> |
|||
#cast %n |
|||
test = emul(34,17) |
|||
</lang> |
|||
output: |
|||
<pre> |
|||
578 |
|||
</pre> |
|||
=={{header|x86 assembly}}== |
=={{header|x86 assembly}}== |