- Print Hello World:
>>> •println "Hello World!"
Hello World!
- Execute a Brainfuck program that prints Hello World:
>>> op←(
... '>‿{tp←↗tp;⧍(t←⊢0 t)(≥↔t tp)}
... '<‿{tp←↙tp;⧍(tp←0)(<0 tp)}
... '+‿{t←≘↗tp t;⧍(t←≘(0⦸)tp t)(>255⊏tp t)}
... '-‿{t←≘↙tp t;⧍(t←≘(255⦸)tp t)(<0⊏tp t)}
... '.‿(•fputc•stdout⊏tp t)
... ',‿(t←≘(•ord•fgetc•stdin⦸)tp t)
... '[‿(⧍(pc←⊏pc bm)(=0⊏tp t))
... ']‿(⧍(pc←⊏pc bm)(≠0⊏tp t))
... )
... p←ˀ⊸≥0˙(⊒⎉˙⊲op)"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."
... bm←⋆↔p0
... bs←()
... i←0
... ⨻{⧋(bs←⊢i bs)‿{e←⊳bs;bm←≘(e⦸) i bm;bm←≘(i⦸) e bm;bs←⍖¯1bs}‿⋅(⊒⊏i p6‿7);i←↗i}↔p
... t←`0
... tp←0
... pc←0
... ⟁{⊔⊳⊏⊏pc p op;pc←↗pc}(<↔p pc)
Hello World!
- Get the product of an array:
ᐟ×; Π
== Fold *; Product
== >>> [ᐟ×1‿2‿3‿4 Π1‿2‿3‿4]
╰─= (24 24)
- Get the sum of an array:
ᐟ+; Σ
== Fold Plus; Sum
== >>> [ᐟ+1‿2‿3 Σ1‿2‿3]
╰─= (6 6)
- Get the maximum / minimum value in an array:
ᐟ≫; ⋏; ᐟ≪; ⋎
== Fold Max; MaxOf; Fold Min; MinOf
== >>> [ᐟ≫1‿2‿3 ᐟ≪1‿2‿3]
╰─= (3 1)
- Sort an array ascending:
⍲; ⊏⍋⚇; ⍂⊏⍋
== SortUp; At GradeUp Dup; CopyLeft At GradeUp
== >>> [⍲4‿0‿6‿3‿¯1 ⊏⍋⚇4‿0‿6‿3‿¯1]
├─= ((¯1 0 3 4 6)
╰─= (¯1 0 3 4 6))
- Sort an array descending:
⍱; ⊏⍒⚇; ⍂⊏⍒
== SortDown; At GradeDown Dup; CopyLeft At GradeDown
== >>> [⍱4‿0‿6‿3‿¯1 ⊏⍒⚇4‿0‿6‿3‿¯1]
├─= ((6 4 3 0 ¯1)
╰─= (6 4 3 0 ¯1))
- Create a matrix of zeroes:
ρ⎉0⋈⚇
== Reshape Swap 0 Pair Dup
== >>> ρ⎉0⋈⚇3
├─= ((0 0 0)
├─= (0 0 0)
╰─= (0 0 0))
- Create an identity matrix:
⧺⎉⁼=⚇ε⚇
== Chunks Swap Merge = Dup Enum Dup
== >>> ⧺⎉⁼=⚇ε⚇3
├─= ((1 0 0)
├─= (0 1 0)
╰─= (0 0 1))
- Count occurences of the each unique element (produces a nice table):
˝⋈◩υ˙↔≍⎉ε↔⚇⋇⚇
== Pack Pair Far Unique Each Length Group Swap Enum Length Dup Classify Dup
== >>> ˝⋈◩υ˙↔≍⎉ε↔⚇⋇⚇"Hello World!"
├─= ((1 'H)
├─= (1 'e)
├─= (3 'l)
├─= (2 'o)
├─= (1 ' )
├─= (1 'W)
├─= (1 'r)
├─= (1 'd)
╰─= (1 '!))
- Compute the factorial (3 ways):
ᐟ×ι; Πι; fac←⧋(×◩∘it↙⚇)‿(1⦸)⊸=0⚇
== Fold * Iota; Product Iota; fac: Pick(*Far Atop it Pred Dup)_(1 Pop) Before=0 Dup
== >>> fac←⧋(×◩∘it↙⚇)‿(1⦸)⊸=0⚇
>>> fac 5
╰─= 120
- Compute the Nth fibonacci number (2 ways):
⊲⨻∘ᐠ+⤦⎉ε2; fib←⧋(+◧it◫↙⊸-2⚇)‿⋅⊸≤1⚇
== First Repeat Atop Scan+ Reverse Swap Enum 2; fib: Pick(+Over it Both Pred Before-2 Dup)_Id Before LessEquals 1 Dup
== >>> fib←⊲⨻∘ᐠ+⤦⎉ε2
>>> ⍁˝⋈˙fibι20
├─= ((1 1)
├─= (2 1)
├─= (3 2)
├─= (4 3)
├─= (5 5)
├─= (6 8)
├─= (7 13)
├─= (8 21)
├─= (9 34)
├─= (10 55)
├─= (11 89)
├─= (12 144)
├─= (13 233)
├─= (14 377)
├─= (15 610)
├─= (16 987)
├─= (17 1597)
├─= (18 2584)
├─= (19 4181)
╰─= (20 6765))
- Check if an array is a palindrome:
≡⤦⚇
== Match Reverse Dup
== >>> ≡⤦⚇"saippuakivikauppias"
╰─= 1
>>> ≡⤦⚇"hello"
╰─= 0
- Delete all instances of an element from an array:
⊏⌅≠⍥
== At Where NotEquals DupFar
== >>> ⊏⌅≠⍥4 1‿3‿4‿7‿4‿9
╰─= (1 3 7 9)
- Interleave two arrays:
⥊⊺⋈
== Flatten Transpose Pair
== >>> ⥊⊺⋈1‿2‿3 4‿5‿6
╰─= (1 4 2 5 3 6)
- Intersperse an element between elements in an array:
⍖¯1⥊⌝∾
== Drop ~1 Flatten EachRight Join
== >>> ⍖¯1⥊⌝∾',"abcdef"
╰─= "a,b,c,d,e,f"
- Split an array at an index (2 ways):
⩈; ⋈◨⍏⍖
== Split; Pair Together Take Drop
== >>> ⋈◨⍏⍖2 1‿2‿3‿4‿5‿6
├─= ((1 2)
╰─= (3 4 5 6))
- Filter an array with a predicate:
ˀ
== Check
== >>> ˀ⊸>0 2‿8‿43‿0‿¯5‿11
╰─= (2 8 43 11)
- Find index of the maximum / minimum number in an array:
⊒⋏⚇; ⊒⋎⚇
== IndexOf MaxOf Dup; IndexOf MinOf Dup
== >>> [⊒⋏⚇4‿1‿3 ⊒⋎⚇4‿1‿3]
╰─= (0 1)
- Find the mean of an array of integers:
÷◰↔Σ
== Divide Differ Length Sum
== >>> ÷◰↔Σ1‿2‿3‿4‿5
╰─= 3
- Check if a number is prime:
=2Σ=0⍂|ι
== =2 Sum =0 CopyLeft| Iota
== >>> ˜(=2Σ=0⍂|ι)ι30
╰─= (2 3 5 7 11 13 17 19 23 29)
- Split an array by a predicate:
˘
== Span
== >>> ˘⟜=',"a,b,c,d,e,f"
├─= ("a"
├─= "b"
├─= "c"
├─= "d"
├─= "e"
╰─= "f")
- Flatten an array (2 ways):
⥊; ⊳ᐦᐟ∾
== Flatten; Last Fix Fold Join
== >>> ⊳ᐦᐟ∾((1) 2‿3‿(4‿5‿(6‿7‿8 9‿10‿11)) 12‿13‿14)
╰─= (1 2 3 4 5 6 7 8 9 10 11 12 13 14)
- Generate a random integer in the specified range:
+◨(⌊וrandom↗-)⦻
== +Together(Floor * .random Succ -) PopFar
== >>> +◨(⌊וrandom↗-)⦻1 5
╰─= 3
>>> ⌜∘+◨(⌊וrandom↗-)⦻0⋆100 100 # make an array of 100 random integers in the range from 0 to 100
╰─= (83 2 57 74 76 29 29 97 60 13 95 30 35 38 65 13 44 52 51 84 38 68 94 7 76 7 69 99 3 47 14 40 81 77 34 86 36 35 49 73 73 68 18 34 29 53 62 76 94 33 7 48 62 57 77 35 32 7 89 29 39 1 37 54 63 96 45 2 46 27 21 3 10 13 83 65 64 45 41 15 54 6 33 20 77 57 91 18 91 69 6 9 21 21 4 32 64 47 46 39)
>>> ¿‥1 5
╰─= 2
- Remove leading, trailing and duplicate spaces:
⍂★∘∧∘◰ᐠ∨⍁∨⊸⋘0⟜≠'
== CopyLeft Multiply Atop And Atop Differ Scan Or CopyRight Or Before NudgeLeft 0 After NotEquals '
== >>> ⍂★∘∧∘◰ᐠ∨⍁∨⊸⋘0⟜≠' " a aaa a "
╰─= "a aaa a"
- Remove leading and trailing spaces:
⍂★∘∧∘◰ᐠ∨(⤦ᐠ∨⤦)⟜≠'
== CopyLeft Multiply Atop And Atop Differ Scan Or (Reverse Scan Or Reverse) After NotEquals '
== >>> ⍂★∘∧∘◰ᐠ∨(⤦ᐠ∨⤦)⟜≠' " a a a aaa "
╰─= "a a a aaa"
- Remove consecutive duplicate elements:
★⊣1¨≢⚇
== Multiply TackLeft 1 EachPair NotMatch Dup
== >>> ★⊣1¨≢⚇"aaa aaa ee aa a a"
╰─= "a a e a a a"
- Duplicate zeroes inside an array keeping the same shape:
⍏↔⎉★↗=0⚉
== Take Length Swap Multiply Succ =0 DupTwice
== >>> ⍏↔⎉★↗=0⚉1‿0‿2‿3‿0‿4‿5‿0
╰─= (1 0 0 2 3 0 0 4)