Skip to content
silentbicycle edited this page Mar 31, 2011 · 11 revisions

&x x:int takes a list of ints and returns the ints from 0 to (length of x-1), each repeated as many times as x[i].

Some examples may make this clearer:

  &1 2 3 4 5
0 1 1 2 2 2 3 3 3 3 4 4 4 4 4
  &5 4 3 2 1          / 5 0s, 4 1s, 3 2s, 2 3s, 1 4
0 0 0 0 0 1 1 1 1 2 2 2 3 3 4
  &0 0 1 0 0 1 1 0    / where are the 1s?
2 5 6
  (!10)!2             / 0 to 9 modulus 2
0 1 0 1 0 1 0 1 0 1
  &0=(!10)!2          / where are the 1s in 0 to 9 modulus 2: filter even numbers
0 2 4 6 8
  sparse:{((#x)#0 1)[&x]}  / index repeating 0 1 by (where x)
{((#x)#0 1)[&x]}
  sparse 10 2 35 1 8 1 9   / 10 0s, 2 1s, 35 0s, 1 1, 8 0s, 1 1, 9 0s
0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
Clone this wiki locally