Skip to content

Instantly share code, notes, and snippets.

@marinuso
marinuso / gist:884915fb157c0c102fa8
Created October 12, 2014 21:30
Explanation of APL code.
type←{
''≡0↑⍵:'str' ⍝ if the first zero items are the empty string, this is a string.
⍬≢⍴⍵:'list' ⍝ if it is not a string, but it has more than zero dimensions, it is a list.
⍵=⌈⍵:'int' ⍝ if it is equal to its ceiling, it can be considered an int.
⍝ (there is literally no way to tell the difference between 1 and 1.0 in APL.)
'float' ⍝ if it isn't one of the above, it must then be a float.
}
round←{
0::1 ⍝ if something goes wrong, return 1
@marinuso
marinuso / gist:9f0e68a6ad15654e0849
Created October 7, 2014 00:29
Manhattan Amoebas
amoeba←{
idx←,⍳⍴field←' '⍴⍨2/size←⌈4×0.5*⍨(+/!⍳⍵)÷○1
field[G;G←⌈size÷2]←'0'
_←{
prevs←idx/⍨,field=⍕⍵-1
⍵∘{
⍵∘{
free←idx/⍨,field=' '
+((⊃free[⍋+/¨|free-⊂⍺])⌷field)←⍕⍵
}¨⍺/⍺