Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python3
import collections
import subprocess
import sys
args = 3
size = 3
def f_and(x, y):
@jayfoad
jayfoad / hist.dyalog
Created May 21, 2016 09:52
Simple APL function to generate a histogram of its argument
⍝ Lamp character ⍝ introduces comments
⍝ Assignment arrow ← names things
⍝ Braces enclose an anonymous function definition
⍝ Inside the braces, ⍵ refers to the function's argument
hist ← {
n ← ⌈/ ⍵ ⍝ Find maximum value in argument vector
a ← n ⍴ 0 ⍝ Allocate a new vector of that length, filled with zeroes
a[⍵] +← 1 ⍝ For each item in argument, increment that position in a
a ⍝ Return a
}
@jayfoad
jayfoad / jugalbandi.dyalog
Created September 16, 2015 16:06
The Snakes and Ladders Jugalbandi from Functional Conf 2015, in APL
config←30(3 5 11 20 17 19 21 27)(22 8 26 29 4 7 9 1)
turn←{s f t←⍺ ⋄ n←⍵+{⍵⊣⎕←'throw ',⍕⍵}?6 ⋄ n>s:⍵ ⋄ (f⍳n)⊃t,n}
{}{⎕←config turn ⍵}⍣{⍺=30}1