Anonymous user
Nimber arithmetic: Difference between revisions
m
→{{header|REXX}}: simplified some code.
(Added translation in python) |
m (→{{header|REXX}}: simplified some code.) |
||
Line 1,531:
<br>two test numbers.
<lang rexx>/*REXX program performs nimber arithmetic (addition and multiplication); shows a table.*/
numeric digits 40; d= digits() %
parse arg sz aa bb . /*obtain optional argument from the CL.*/
if sz=='' | sz=="," then sz= 15 /*Not specified? Then use the default.*/
Line 1,539:
sz1= sz + 1; w1= w-1 /*define the "dash" character for table*/
do am=0 for 2 /*perform sums, then perform multiplies*/
do j=0 for sz1
if j==0 then call top '║'center("("@.am')', w1)
$= '║'center(j, w1)"║"
do k=0 for sz1
if am then $= $
else $= $
end /*k*/
say $ '║'
end /*j*/
call bot
end /*am*/
say 'nimber sum of ' comma(aa) " and " comma(bb) ' ───► ' comma( nsum(aa, bb))
Line 1,563:
hpo2: procedure; parse arg z; return 2 ** (length( d2b(z) + 0) - 1)
lhpo2: procedure; arg z; m=hpo2(z); q=0; do while m//2==0; m= m%2; q= q+1; end; return q
nsum: procedure expose d; parse arg x,y;
shl: procedure; parse arg z,h;
shr: procedure; parse arg z,h;
/*──────────────────────────────────────────────────────────────────────────────────────*/
nprod: procedure expose d; parse arg x,y; if x<2
if x>h then return nsum( nprod(h, y), nprod( nsum(x, h), y) )
if hpo2(y)<y then return nprod(y, x)
{{out|output|text= when using the input of: <tt> 25 </tt>}}
<pre>
|