Albedo

Joined 24 August 2022
languages added
(languages added)
 
(16 intermediate revisions by the same user not shown)
Line 1:
{{mylangbegin}}
{{mylang|Piet|IntermediatePro}}
{{mylang|Julia|BeginnerIntermediate}}
{{mylang|Cardinal|Pro}}
{{mylang|DUP|Intermediate}}
{{mylang|FALSE|Intermediate}}
{{mylang|Beeswax|Creator}}
{{mylang|Glee|Beginner}}
{{mylang|Q'Nial|Beginner}}
{{mylangend}}
 
There aren’t any ways to upload images at the moment, so I’llall postexamples linksare torendered theas cloudwikitables. storage place ofSee my PietPNG examplesto onwikitable myconversion usercode page,written within explanationsJulia howat theythe work—hopefullybottom for later integration inof the appropriate places on Rosettacodepage.
 
 
 
==Explanation of shorthand code for Piet examples==
 
To shrink down the size of larger problems, I invented a shorthand text version for explaining the general program flow in a more compact form:
 
NOP ADD DIV GRT DUP INC END
. + / > = c ~
PSH SUB MOD PTR ROL OUN
X - % # @ N
POP MUL NOT SWI INN OUC
? * ! $ n C
 
==Integer Sequence==
 
[[Integer_sequence]]
 
==Ackermann Function==
[Image:https://copy.com/TQuwy3dwBRl7nEOL]
 
[[Ackermann_function#Piet]]
{| style="border-collapse: collapse; border-spacing: 0; font-family: courier-new,courier,monospace; font-size: 20px; line-height: 1em; padding: 0px"
 
{| style="border-collapse: collapse; border-spacing: 0; font-family: courier-new,courier,monospace; font-size: 10px; line-height: 1.2em; padding: 0px"
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#c00000; color:#c00000;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
| style="background-color:#00ffff; color:#00ffff;" | ww
| style="background-color:#00ffff; color:#00ffff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#c0ffff; color:#c0ffff;" | ww
| style="background-color:#ffff00; color:#ffff00;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#c00000; color:#c00000;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#c0ffc0; color:#c0ffc0;" | ww
| style="background-color:#00ff00; color:#00ff00;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#c0c000; color:#c0c000;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c00000; color:#c00000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#0000c0; color:#0000c0;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c00000; color:#c00000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#00ffff; color:#00ffff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c0ffff; color:#c0ffff;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#0000c0; color:#0000c0;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#00ffff; color:#00ffff;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffc0ff; color:#ffc0ff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#00c000; color:#00c000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c0c000; color:#c0c000;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c00000; color:#c00000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c0ffc0; color:#c0ffc0;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#ff00ff000000; color:#ff00ff000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffff00; color:#ffff00;" | ww
| style="background-color:#ffff00; color:#ffff00;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
|-
Line 33 ⟶ 304:
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#0000ff000000; color:#0000ff000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#c0ffff; color:#c0ffff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#ffc0ff; color:#ffc0ff;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
| style="background-color:#00ff00; color:#00ff00;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#c0c000; color:#c0c000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffc0ff; color:#ffc0ff;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#c0ffff; color:#c0ffff;" | ww
| style="background-color:#00c000; color:#00c000;" | ww
| style="background-color:#00ff00; color:#00ff00;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#0000c0; color:#0000c0;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#00ffff; color:#00ffff;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#c0ffff; color:#c0ffff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
|-
 
|}
 
Program flow (see explanation of the shorthand codes at the top of the page), with labels:
 
 
 
l1 l3
(7x3 codels)
↓ ↓
1X2X-nn2X1X@=1X=->!#2X1X@=1X=-
. l2→? >
. 2 !
................X1-X1?#
. X l4↑2←l5
. 1 X
. X 1
. @ X
. = @
. 1 =
. ~ X 3
. N = X
. + - 1
. X 2 X
. 1 X @
. l6→? 1 1
.+X1@X1X2#>@X X
. l7↑ -
...............-X1@X1X3
 
Opcodes:
 
Explanation with stack for the Ackermann Function(2,0):
1 PSH NOT DUP OUN 5 PSH
(for the meaning of the square brackets, please read below)
ROL
ADD DUP
PSH 1 OUC ADD
 
[A] [B]
Shorthand:
1 1
1 1 1 0 1 1 1 0
2 2 2 2 2 2 1 0 2 2 0 0 0 0 0 1
0 0 0 [2] 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 1 [1]
2 2 2 2 2 [0] 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 1 [1]
1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
———————————————————————————————————————————————————————————————————————————————————————
1X2X - n n 2X 1X @ = 1X = - > ! # 2X 1X @ = 1X = - > ! # ? 1X - 1X
↑ ↑ ↑
l1 l3 l4
---------------------------------------------------------------------------------------
explanation: correct order m>0? yes n>0? no A(m-1,1)
of m,n
 
1 X ! = N 5 X
@ .
+ =
X 1 C +
 
[B] [C]
1 1 1 1
1 1 1 0 1 1 1 0 1 3 3 1 3 3 1
2 2 1 1 1 1 1 0 2 2 1 1 1 1 1 0 2 2 1 1 1 1 1 0 0 0 1 1 [0]
1 1 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [1]
1 1 [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 [0]
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
——————————————————————————————————————————————————————————————————————————————————————————————————————
2X 1X @ = 1X = - > ! # 2X 1X @ = 1X = - > ! # 2X 1X @ = 3X 1X @ 1X - 3X 1X @ 1X -
↑ ↑ ↑
l1 l3 l5
-------------------------------------------------------------------------------------------------------
correct order m>0? yes n>0? yes A(m-1,A(m,n-1))
of m,n
 
0 \n 1 \n 2 \n 3 OUTPUT[D]
1 1 1
—————————————————————————————————————————————————————————————————————————————
1 1 51 0 1 5 1 1 0 5 1 1 0
2 2 0 1 1 5 5 101 1 1 0 1 2 52 5 10 0 0 0 0 0 1 2 5 5 10 1 2 2 3 0 0 0 0 STACK 0 1
0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 10 1 1 1 1 [1] 1 1 2 20 2 20 20 2 0 2 20 20 3 30 3 3 ...0
1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 [0] 0 0 1 1 1 1 1 1 1 1
—————————————————————————————————————————————————————————————————————————————
0 1X !0 = N0 5X =0 +0 C 1X0 + @0 = N0 5X =0 +0 C 1X0 + @0 = N0 5X =0 +0 C 1X0 + @0 = N0 ... 0 0 0 0 0 [0] 0 0 0 0 0 0 0 0 0 0
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
| \_____/ | | |
—————————————————————————————————————————————————————————————————————————————————————————————————————
| | | | +—————————— Repeating the Loop
2X 1X @ |= 1X = - > | ! # 2X 1X @ |= |1X = - > ! # ? 1X - 1X 2X 1X @ = 1X = - > ! #
| | | +———————————— ROL acting as NOP (stack too small), needed to guide the codel chooser ↑ ↑
l1 | | | l3 l4 l1
-----------------------------------------------------------------------------------------------------
| | +—————————————— Count up
correct order m>0? yes n>0? no A(m-1,1) correct order m>0?
| |
of m,n for inner inner for inner f.
| +———————————————————————— 10 = ASCII for \n (newline)
function function
|
 
+————————————————————————————————— !1=0 (Sequence begins at 0)
1
1 2 2 1
1 1 1 0 0 0 0 1 1 1 1 0
2 2 0 0 0 0 0 0 0 0 2 2 1 2 2 0 0 0 0 0 1
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 2 2 0 0 0 0 0 0 0 0
0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 2 2 2 2 2 2 2 2
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
———————————————————————————————————————————————————————————————————————————————————
? 2X 1X @ = 1X = - 2X 1X @ > # 2X 1X @ 1X + 2X 1X @ = 1X = - > ! #
↑ ↑ ↑
l2 l7 l1
 
 
output 3
—————————————————————————————————————————————————————
1
1 2 2
1 1 1 0 0 0 -1
2 2 -1 -1 -1 -1 -1 -1 0 1
2 2 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1
-1 -1 -1 2 2 2 2 2 2 2 2 2 2 2 2 3
—————————————————————————————————————————————————————
? 2X 1X @ = 1X = - 2X 1X @ > # ? 1X + N ~
↑ ↑
l2 l6
 
 
Which leads to the result Ackermann(2,0) = 3
 
What the program actually does is working through the whole steps of calculating the A(m,n) functions, according to:
 
A(2,0) = A(1,1) ,A(m,n)= A(m-1,1) if m>0 and n=0
A(1,1) = A(0,A(1,0)) ,A(m,n)= A(m-1,A(m,n-1)) if m>0 and n>0
A(0,A(1,0)) = A(0,A(0,1)) ,A(m,n)= A(m,n-1) if m>1 and n=0, for the inner function
A(0,A(0,1)) = A(0,2) ,A(m,n)= n+1 if m=0, for the inner function
A(0,2) = 3 ,A(m,n)= n+1 if m=0
 
The coefficients and the results can be found on the stack. See the places marked with square brackets [] and Labels in the program/stack flow above.
At each turn, the upper two values on the stack are flipped, so they are in the proper order for computing inner functions. For highly nested A(...,(A(A(A(...))))) functions the stack can grow to enormous proportions very fast, then computing its way outwards again, from innermost functions outwards. The innermost coefficients are always on top of the stack.
 
Checks for the appropriate substitute function and branching structures take the largest part of the program.
 
==Binary Digits==
[[Binary Digitsdigits#Piet]]
 
png image download:
 
[Image:https://copy.com/Ixp3nc7QJQTCrcDb]
 
Rendered as wikitable
Program flow:
 
{| style="border-collapse: collapse; border-spacing: 0; font-family: courier-new,courier,monospace; font-size: 18px; line-height: 1.2em; padding: 0px"
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#c0ffc0; color:#c0ffc0;" | ww
| style="background-color:#c0ffc0; color:#c0ffc0;" | ww
| style="background-color:#00ff00; color:#00ff00;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#00ff00; color:#00ff00;" | ww
| style="background-color:#00c000; color:#00c000;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#ffff00; color:#ffff00;" | ww
| style="background-color:#0000c0; color:#0000c0;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#c0c000; color:#c0c000;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
|-
 
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#0000c0; color:#0000c0;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
|-
 
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#00ff00; color:#00ff00;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#0000c0; color:#0000c0;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#c0ffc0; color:#c0ffc0;" | ww
| style="background-color:#00c000; color:#00c000;" | ww
| style="background-color:#00c000; color:#00c000;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
|-
 
| style="background-color:#c000c0; color:#c000c0;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#c0c0ff; color:#c0c0ff;" | ww
|-
 
| style="background-color:#ffc0ff; color:#ffc0ff;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#ffff00; color:#ffff00;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffff00; color:#ffff00;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffff; color:#ffffff;" | ww
| style="background-color:#ffffc0; color:#ffffc0;" | ww
|-
|}
 
 
Example output:
 
? 3
11
? 13
1101
 
Program flow (explanation of codes at the top of the page):
 
2Xn=2X/=1X!>#?N=1X
Line 123 ⟶ 695:
l1: = : duplicate number
2X/= : divide n by 2 and duplicate the result
1X!>#: is the result >0? (is n>=2?) It is, thus rotate the pointer by 1 (downwards, continue at l2) and go through the loop
l2: 2X1X@: move the result down (needed for further processing), and move n to the top of the stack
2X% : n mod 2 (remainder, last binary digit)
2X1X@: move binary digit down, move result of division up
Line 130 ⟶ 702:
l1: = : duplicate result of division
2X/= : divide n by 2 and duplicate the result
1X!>#: is the result >0? (is n>=2?) It is not, thus don’t rotate the pointer and move on (totowards l3)
? : pop division result from the stack
l3: N : output first bit: 1 (1*2^1)
Line 155 ⟶ 727:
↑ . .
l4 ....
 
==Integer Sequence==
 
[[Integer_sequence#Piet]]
 
PNG image download:
 
[Image:https://copy.com/TQuwy3dwBRl7nEOL]
 
Rendered as wikitable:
 
{| style="border-collapse: collapse; border-spacing: 0; font-family: courier-new,courier,monospace; font-size: 20px; line-height: 1.2em; padding: 0px"
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ff0000; color:#ff0000;" | ww
| style="background-color:#c0ffc0; color:#c0ffc0;" | ww
| style="background-color:#ffc0c0; color:#ffc0c0;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#c000c0; color:#c000c0;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#ff00ff; color:#ff00ff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
|-
 
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#000000; color:#000000;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
| style="background-color:#00c0c0; color:#00c0c0;" | ww
| style="background-color:#00ffff; color:#00ffff;" | ww
| style="background-color:#0000ff; color:#0000ff;" | ww
 
|}
 
 
 
 
(7x3 codels)
 
Opcodes:
 
1 PSH NOT DUP OUN 5 PSH
ROL
ADD DUP
PSH 1 OUC ADD
 
Shorthand:
 
1 X ! = N 5 X
@ .
+ =
X 1 C +
 
 
0 \n 1 \n 2 \n 3 OUTPUT
—————————————————————————————————————————————————————————————————————————————
5 5 5
0 5 5 10 1 1 5 5 10 1 2 5 5 10 1 3 STACK
1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 ...
—————————————————————————————————————————————————————————————————————————————
1X ! = N 5X = + C 1X + @ = N 5X = + C 1X + @ = N 5X = + C 1X + @ = N ...
| \_____/ | | |
| | | | +—————————— Repeating the Loop
| | | |
| | | +———————————— ROL acting as NOP (stack too small), needed to guide the codel chooser
| | |
| | +—————————————— Count up
| |
| +———————————————————————— 10 = ASCII for \n (newline)
|
+————————————————————————————————— !1=0 (Sequence begins at 0)
 
 
 
 
==Create Wikitable from PNG files==
 
This is the Julia code I use to generate wikitables from Piet program png files (codel size 1).
 
I just copy/paste the console output of the program.
 
Usage: convert("filename.png", blocksize)
 
using Images, ImageView
function convert(name::String,blocksize::Int)
img=Images.imread("$name")
view(img)
println("{| style=\"border-collapse: collapse; border-spacing: 0; font-family: courier-new,courier,monospace; font-size: $(blocksize)px; line-height: 1.2em; padding: 0px\"")
for y=1:height(img)
for x=1:width(img)
r=hex(int(img[x,y].r*255))
g=hex(int(img[x,y].g*255))
b=hex(int(img[x,y].b*255))
r=="0" ? r="00" : nothing
g=="0" ? g="00" : nothing
b=="0" ? b="00" : nothing
print("| style=\"background-color:#$r$g$b; color:#$r$g$b;\" | ww\n")
x==width(img) ? print("|-\n\n"):nothing
end
end
print("|}")
end
136

edits