User:Albedo: Difference between revisions
Content added Content deleted
Line 90: | Line 90: | ||
==Binary Digits== |
==Binary Digits== |
||
[[Binary Digits]] |
[[Binary Digits]] |
||
png image download: |
|||
[Image:https://copy.com/Ixp3nc7QJQTCrcDb] |
[Image:https://copy.com/Ixp3nc7QJQTCrcDb] |
||
Rendered as wikitableD |
|||
{| 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 |
|||
|- |
|||
|} |
|||
Program flow: |
Program flow: |
Revision as of 16:22, 10 July 2015
My Favorite Languages | |
Language | Proficiency |
Piet | Intermediate |
Julia | Beginner |
There aren’t any ways to upload images at the moment, so I’ll post links to the cloud storage place of my Piet examples on my user page, with explanations how they work—hopefully for later integration in the appropriate places on Rosettacode.
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
[Image:https://copy.com/TQuwy3dwBRl7nEOL]
ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | 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)
Binary Digits
png image download:
[Image:https://copy.com/Ixp3nc7QJQTCrcDb]
Rendered as wikitableD
ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww |
ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww | ww |
Program flow:
2Xn=2X/=1X!>#?N=1X . . 2 . > . @ X . . . X1X2%X2@X1 . . ? . . C+=X5............# . . ....
Example, with stack and output, for base-10 number 3:
1 1 \n | Output ———————————————————————————————————————————————————————————+——————— 10 | Stack 10 1 1 2 0 000 | 2 1 111 2 2 2 2 2 1 100 0000 1 | 3 311 1111 1 13 31 1 111 111 11111 1 10 1 5 | 33 333 3333 3 31 11 1 111 111 1111111 111 2 21 55 10 | 222 222 2222 2 22 22 2 222 222 2222222 22222 222 22 2 2 | ———————————————————————————————————————————————————————————+ 2Xn=2X/=1X!>#2X1X@2X%2X1X@=2X/=1X!>#?N=1X>#N=1X>#5X= + C ? ... 2Xn=2X ... (return to beginning)
The program executes short division with remainder.
l0: 2X : acts as marker for the end of the binary output n : input base-10 number 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, l2) and go through the loop 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 loop is finished, back to the beginning (l1) 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 (to l3) ? : pop division result from the stack l3: N : output first bit: 1 (1*2^1) = : duplicate next bit 1X># : is top of stack >1? It isn’t (end marker check). Thus, back to beggining of loop (l3) N : output next bit: 1 (1*2^0) = : duplicate next bit (which, in this case, is the marker) 1X># : is top of stack >1? It is (end marker reached). Thus, move on to (l4) l4: 5X=+ : 5+5=10, 10 is the ASCII value for the newline character (\n) C? : output top of stack as character (newline) and pop the marker. End reached, leading back to (l0) l0: 2Xn=2X/=...........
Flow diagram, with labels l0 to l3:
l0 l1 l3 ↓ ↓ ↓ 2Xn=2X/=1X!>#?N=1X . . . . . . . l2→2 . > . @ X . . . X1X2%X2@X1 . . ? . . C+=X5............# ↑ . . l4 ....