{100 doors} {Ackermann Function} {j i}[$[\$[1-^a;!][1+]?\1-a;!][%1+]?]a: { ^ ^ } { replace this and this ! with ( for tail recursion elimination } 3 3 a;! . { 61 } ------ {Address Operations} ------ {Apply a callback to an Array} [[$][($(;^!)\^:1+)1-]#%%%]m: {map} 0a: 0i: [%i;$1+i:]a;10m;! {init} [$$**]a;10m;! {cube} [$.' ,]a;10m;! {print} ------ {Arrays} 0a: 1a;[^6<][^^:\1+\1+]#%% ------ {Basic bitmap storage} 0h: { here } h; $b: 4 ^:1+ 3 ^:1+ 4 3*+ h: { allot 4x3 bitmap } b;;.' , {width} b;1+;.' , {height} b;$;\1+;*. {size} 0 b;$;^1+;*^+2+\2+[^^>][(^)\^;1+]#%%% {fill} [$(;*+)+2+]p: { pixel address } 255 2 1 b; p;! : { set at x=2 y=1 } 10, 0[$b;1+;<][0[$b;;<][^^\b;p;!;['*]['.]?,1+]#%10,1+]#% {show} ------ {Basic input loop} [{end start}%%]p: { process } [[^^>][$;,1+]#%%]p: 0[`$0<~][$10=[%0p;!0][^:1+]?]#%0p;! ------ {Basic integer arithmetic} {Basic pointer and reference operations} ------ {Binary search} [^^>[^^+2/\%3¿^;-$[0>[\%1+][@%\]?)%)%s;(][~((%%%))]?][(%%)0]?]s: 0"bcdefhijklmnop" 'a^0s;!..' , 'g^0s;!..' , 'p^0s;!..' , 't^0s;!.. ------ {Binary string manipulation functions} ------ {Bitwise operations} 10 3 ^^ & .' , { and } ^^ | .' , { xor } ^ ~ .' , { not } ^^ Ç .' , { shift left } ^^ È .' , { shift right } ^~&| . { or } {2 9 -11 80 1 11} ------ {Bubble Sort} [$;^1+;^^>[@\^:1+\^:1u:][%%1+]?]x: [1[][0u:1-^[^^>]x;#%u;]#%%%]b: 0$"randomÊtext"b;! ------ {Bulls and Cows} ------ {Change string case} 0$"alphaBETA"^- {str len} ^^[$][\$;32 ~& , 1+\1-]#10,%% {print upper} ^^[$][\$;32^~&|, 1+\1-]#10,%% {print lower} ------ {Comparing two integers} ``^^>[\,'>,,][ ^^<[\,'<,,][ ^^=[\,'=,,][%%]?]?]? ------ {Compound Data Type} {point} 0p: 4 5 p;\^1+:: {4 5} p;;. {x=4} p;1+;. {y=5} 7p;: {x:=7} ------ {Conditional Structures} condition[true][false]? ------ {Convert an integer into words} ------ {Conway's Game of Life} {1: same as forth} 8w: 8h: {width height} 0o: w;n: { old/new } w;2*h;*w;-1-m: {wrapping mask} [w;2*h;*0[^^>][0^:1+]#%%]c: {clear} [o;+ 1^: w;2*+1+1^: w;2*+1^: 1-1^: 1-1^:%]d: {glider} [o;+ 1^: 1+1^: 1+1^:%]b: {blinker} [w;2*h;*0[^^>][$w;+\[^^>][$o;+;['*][' ]?,1+]#%10,w;+]#%%]p: {print} { row col w@ } [$w;2*-1-$w;&+m;&o;+; ^w;2*- m;&o;+;+ ^w;2*-1+ m;&o;+;+ ^ 1-$w;&+m;&o;+;+ ^ 1+ m;&o;+;+ ^w;2*+1-$w;&+m;&o;+;+ ^w;2*+ m;&o;+;+ ^w;2*+1+ m;&o;+;+ {neighbors} ^o;+;^~&|3=1&^n;+:]g: {gen cell} [w;2*h;*0[^^>][$w;+\[^^>][g;!1+]#%w;+]#%% o;n;o:n:]l: {gen} c;! 1d;! p;! 19[$][l;!1-]# p;! ------ {Conway's Game of Life} {2: bit 1 current, bit 0 next, different wrapping} 8w: 8h: {width height} [w;h;*0[^^>][0^:1+]#%%]c: {clear} [w;h;*0[^^>][$;2*^:1+]#%%]a: {age new->old} [2^: w;+1+2^: w;+2^: 1-2^: 1-2^:%]d: {glider} [2^: 1+2^: 1+2^:%]b: {blinker} [w;h;*0[^^>][$w;+\[^^>][$;2&['*][' ]?,1+]#%10,]#%%]p: {print} {y x} [^1-$0<[h;+][]?w;*^1-$0<[w;+][]?^+;2& ( ^ ^+;2&)+( ^1+$w;=[%0][]? +;2&)+( ^ w;*^1-$0<[w;+][]?^+;2&)+( ^1+$w;=[%0][]? +;2&)+( ^1+$h;=[%0][]?w;*^1-$0<[w;+][]?^+;2&)+( ^ ^+;2&)+( ^1+$w;=[%0][]? +;2&)+( {neighbors} ^w;*^+$;$2&)^~&|6=1&|\:]g: [0[h;^>][0[w;^>][g;!1+]#%1+]#% a;!]l: {gen} c;! 1d;! p;! 21[$][l;!1-]#% p;! ------ {Copy a string} [[$][\$;,1+\1-]#%%]p: {src dst len}[[$][(^;^:\1+\1+)1-]#%%%]c: 0s: 0$"string" $d: ^- $l: d;\ c;! s;l;p;!10, d;l;p;!10, ------ {Data Munging} {Doubly-Linked List} {Ethiopian Multiplication} ------ {Exponentiation operator} [1\[2/\[(^*)][]?$][(($*))]#%\%]p: 3 5p;! ------ {Factorial function} [$1>[$1-f;!*][%1]?]f: 6f;! ------ {Fibonacci sequence} [0 1[@$][1-@@^+$.' ,\]#%%%]f: 20f;! ------ {FIFO} ------ {FizzBuzz} [0\$3/%[][\"Fizz"\]? $5/%[\][\"Buzz"]? $[0[^^>][$;,1+]#%%][%$.]?10,]f: 0[$100<][1+f;!]#% ------ {Factors} ------ {Greatest common divisor} [[$][\^/%]#%]g: 10 15g;!. { 5 } ------ {Happy Number} [0\[10/($*+)$][]#%]n: [0 0~0;[^^&][((1+^^;=)|)1-]#%\%]f: [0;1+$0::]a: [0$:[n;!f;!][$a;!]#1=]h: 8 0[^][1+$h;![$.' ,\1-\][]?]#%% ------ {Heapsort} {Index in a list} ------ {Insertion sort} [$;v:[^^<[v;^1-;<][0]?][1-$;^1+:]#v;\:]i: [^[1+^^>][@^i;!@@]#%%%]s: 0$"random text"s;! ------ {Knapsack Problem} ------ {Look and say sequence} [[(^^>)\][^;$,^:1+\1+\]#10,\%\%]m: [d;\^:1+\^:1+]r: [e;d: 0$;'0[(^e;<)\][(^;^=)\[1+][r;!d:$;'1]?((1+))]#r;! \0m;! e:]n: 0"1"e: '1,10, 9[$][n;!1-]#% ------ {Mandelbrot set} {Maximum Value} ------ {Memory Allocation} {using h for HERE} 0h: {init} {c}h;\: {create} {n}h;+h: {allot} {d}h;: h;1+h: {put} h;"string"h: {sput} ------ {Merge sort} {One dimensional cellular automata} {Palindrome} [1-^^<(^;^;=)&[\1+\)%p;(][<~]?]p: ------ {Pascal'sÊtriangle} {n}[0[^^>][$;.'Ê,1+]#%10,]p: {n}[0\[^^<][$1-\^;^;+\:]#%%]n:Ê 6ÊÊÊÊÊÊ{ÊhowÊmanyÊrowsÊ} 1Ê0: 1[^^>][0^:1+]#%ÊÊ{erase} 1[p;!^^>][$n;!1+]#%% -------- {Perfect Numbers} {Primality by trial division} ------ {Prime decomposition} [2[^^$*<~][^^/\[%1+][@%\$.' ,]?]#%.]d: 27720d;! ------ {Quicksort} [^^+2/;v:% ^^[^^<] [\[$;v;<][1+]# \[v;^;<][1-]# ^^>[][^^^;^;\@:\: \1+\1-]? ]#\@ ^^][^^^;^;\@:\:\1-\1+]#%% {reverse} ------ {Rot13} [`$1+][$32~&$'Z>^'A<|[%][13\'M>[-][+]?]?,]#% ------ {Run-length encoding} ------ {Sieve of Eratosthenes} [^^$*[^^>][1^:(^)+]#%%]c: [0[^^>][0^:1+]#%ÊÊ{erase} 2[^^$*>][$;[]c;?1+]#% 'P,'r,'i,'m,'e,'s,':, 2[^^>][$;[][' ,$.]?1+]#%%]p: 100p;! ------- {String length} {characters} 0$"m¿¿se"\-. ------- {String concatenation} [$1+\;]c: {count} [[$][\$;,1+\1-]#%%]t: {type} 0$1+$"Hello"\-^:s: {counted string} s;c;!t;!10, s;c;!+ $" there!"\- s;;+s;: {append} s;c;!t;!10, ------- {Sum and product of array} [[$][($(;@$(!)\)1+)1-]#%%\%]r: {reduce} 0a: 1a;[^6<][^^:\1+\1+]#%% {1 2 3 4 5} [+]0a;5r;!.' , {15} [*]1a;5r;!. {120} ------ {Tokenizing a String} ------ {User Input - text} [[`$' |][^:1+]#%]w: [0[`'0-$$9>0@>|~][\10*+]#%]d: 0$w;!.. d;!. {abcd 90 -> 4090} ------ {User Output - text} 'G,'o,'o,'d,'b,'y,'e,' ,'W,'o,'r,'l,'d,'!,10, [\[^^>][$;,1+]#%%]p: 0$"Goodbye World!"p;!10, ------ {Wireworld} a b & | ^ &~ a~ 0 0 0 0 0 1 1 0 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 0 0 0