Nimber arithmetic: Difference between revisions
Content deleted Content added
SqrtNegInf (talk | contribs) Added Perl |
Added Quackery. |
||
Line 1,116:
21508 + 42689 = 62149
21508 * 42689 = 35202
</pre>
=={{header|Quackery}}==
{{trans|Julia}} (Mostly translated from Julia, although 'translated' doesn't do the process justice.)
<lang Quackery>
[ dup negate & ] is hpo2 ( n --> n )
[ 1 & 0 = ] is even ( n --> b )
[ 0 swap hpo2
[ dup even while
1 >>
dip 1+ again ]
drop ] is lhpo2 ( n --> n )
[ ^ ] is nim+ ( n n --> n )
forward is nim* ( x y --> r )
[ over 2 < over 2 < or iff
* done
over dup hpo2
tuck > iff
[ 2dup swap nim*
dip [ rot nim+ swap nim* ]
nim+ ] done
drop
dup hpo2 over < iff
[ swap nim* ] done
over lhpo2 over lhpo2 &
dup 0 = iff
[ drop * ] done
hpo2 tuck >>
dip [ tuck >> ]
nim*
swap 1 - 3 swap <<
nim* ] resolves nim* ( x y --> r )
[ over size -
space swap of
swap join ] is justify ( $ n --> $ )
[ number$
3 justify
echo$ ] is j.echo ( n --> )
[ cr sp echo$ say "|"
temp put
16 times [ i^ j.echo ] cr
sp char - 3 of echo$
say "+"
char - 48 of echo$ cr
16 times
[ i^ dup j.echo
say " |"
16 times
[ dup i^
temp share do
j.echo ]
drop cr ]
temp release ] is tabulate ( $ x --> )
' nim+ $ "(+)" tabulate
cr
' nim+ $ "(+)" tabulate
cr
say " 21508 (+) 42689 = " 21508 42689 nim+ echo cr
say " 21508 (*) 42689 = " 21508 42689 nim* echo cr
</lang>
{{Out}}
<pre>
(+)| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
---+------------------------------------------------
0 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 | 1 0 3 2 5 4 7 6 9 8 11 10 13 12 15 14
2 | 2 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13
3 | 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12
4 | 4 5 6 7 0 1 2 3 12 13 14 15 8 9 10 11
5 | 5 4 7 6 1 0 3 2 13 12 15 14 9 8 11 10
6 | 6 7 4 5 2 3 0 1 14 15 12 13 10 11 8 9
7 | 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8
8 | 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7
9 | 9 8 11 10 13 12 15 14 1 0 3 2 5 4 7 6
10 | 10 11 8 9 14 15 12 13 2 3 0 1 6 7 4 5
11 | 11 10 9 8 15 14 13 12 3 2 1 0 7 6 5 4
12 | 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3
13 | 13 12 15 14 9 8 11 10 5 4 7 6 1 0 3 2
14 | 14 15 12 13 10 11 8 9 6 7 4 5 2 3 0 1
15 | 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
(+)| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
---+------------------------------------------------
0 | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 | 1 0 3 2 5 4 7 6 9 8 11 10 13 12 15 14
2 | 2 3 0 1 6 7 4 5 10 11 8 9 14 15 12 13
3 | 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12
4 | 4 5 6 7 0 1 2 3 12 13 14 15 8 9 10 11
5 | 5 4 7 6 1 0 3 2 13 12 15 14 9 8 11 10
6 | 6 7 4 5 2 3 0 1 14 15 12 13 10 11 8 9
7 | 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8
8 | 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7
9 | 9 8 11 10 13 12 15 14 1 0 3 2 5 4 7 6
10 | 10 11 8 9 14 15 12 13 2 3 0 1 6 7 4 5
11 | 11 10 9 8 15 14 13 12 3 2 1 0 7 6 5 4
12 | 12 13 14 15 8 9 10 11 4 5 6 7 0 1 2 3
13 | 13 12 15 14 9 8 11 10 5 4 7 6 1 0 3 2
14 | 14 15 12 13 10 11 8 9 6 7 4 5 2 3 0 1
15 | 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
21508 (+) 42689 = 62149
21508 (*) 42689 = 35202
</pre>
|