Skip to main content
finished line-by-line commentary
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61

The k function yields a bitmapboolean scaled by 2 (ie. a 2D array of 0s and 2s) so the values can be distinguished from the ice cream values later on, in the mapping.

The k function yields a bitmap scaled by 2 (ie. a 2D array of 0s and 2s) so the values can be distinguished from the ice cream values later on, in the mapping.

The k function yields a boolean scaled by 2 so the values can be distinguished from the ice cream values later on, in the mapping.

finished line-by-line commentary
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61

edit: -6 combine 2 maps into 1.
edit: -2 remove useless ravels.
edit: nicer typescript.
edit: -10 apply repeated expression array-wise.
edit: -4 factor out repeated expression as a function.
edit: line-by-line commentary.

i:[((n%2)^2)>+/(qx y)^2 ( )^2 } square the result from q(x,y) +/ } sum the two numbers > } compare the left side (above) with the right (=> 0/1) [ } floor 

The floor should not be necessary. But apparently there's a bug in the interpreter.

The l function works similarly to the j function, using a jot-dot.

l:(@1+~]y%2)k.(~y) y%2 } y divided by 2 ] } ceiling ~ } iota 0..ceil(y/2)-1 1+ } add 1 => 1..ceil(y/2) @ } reverse => ceil(y/2)..1 ~y } iota y 0..y-1 ( )k.( ) } jot-dot using k 

The k function yields a bitmap scaled by 2 (ie. a 2D array of 0s and 2s) so the values can be distinguished from the ice cream values later on, in the mapping.

k:2*[x>[|qy x } k's left arg qy } y-(n-1)%2 | } abs [ } floor x } left-hand-side again > } compare [ } floor (should be unnecessary) 2* } scale by 2 

edit: -6 combine 2 maps into 1.
edit: -2 remove useless ravels.
edit: nicer typescript.
edit: -10 apply repeated expression array-wise.
edit: -4 factor out repeated expression as a function.

i:[((n%2)^2)>+/(qx y)^2 ( )^2 } square the result from q(x,y) +/ } sum the two numbers > } compare the left side (above) with the right (=> 0/1) [ } floor 

edit: -6 combine 2 maps into 1.
edit: -2 remove useless ravels.
edit: nicer typescript.
edit: -10 apply repeated expression array-wise.
edit: -4 factor out repeated expression as a function.
edit: line-by-line commentary.

i:[((n%2)^2)>+/(qx y)^2 ( )^2 } square the result from q(x,y) +/ } sum the two numbers > } compare the left side (above) with the right (=> 0/1) [ } floor 

The floor should not be necessary. But apparently there's a bug in the interpreter.

The l function works similarly to the j function, using a jot-dot.

l:(@1+~]y%2)k.(~y) y%2 } y divided by 2 ] } ceiling ~ } iota 0..ceil(y/2)-1 1+ } add 1 => 1..ceil(y/2) @ } reverse => ceil(y/2)..1 ~y } iota y 0..y-1 ( )k.( ) } jot-dot using k 

The k function yields a bitmap scaled by 2 (ie. a 2D array of 0s and 2s) so the values can be distinguished from the ice cream values later on, in the mapping.

k:2*[x>[|qy x } k's left arg qy } y-(n-1)%2 | } abs [ } floor x } left-hand-side again > } compare [ } floor (should be unnecessary) 2* } scale by 2 
add detailed commentary
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61

In action (piping throughmore detail, the entry-point is the trc to remove tab charsfunction which are the REPL's prompt):takes one argument implicitly named y.

josh@Z1c:y ~/incay#((jn<y),ly){' (V'  $ cat icecream n<y } assign y to 'n' i:[( jn<y } call j(n%2)^2y)> ly } call l(y) (x-(n-1)%2 )^2, )+ } catenate the results (y- ){' (n-V' } map 0 1)%2)^2 2 to ' ' '(' 'V' y y# } reshape to NxN 

The j function receives the same input value as its y parameter.

j:(~[y%2)i.(~y) k:2*[x>[|y-(n-1)%2 y%2 } y divided by 2 l: [ } floor ~ } iota. this generates the row indices 0..y/2 ~y } iota y. this generates the column indices 0..y (@1+~]y%2 )ki.(~y ) } jot-dot with the function i c

The jot-dot here does the double-loop. It calls the i function with every combination of elements from the left and right arrays (0..n/2 and 0..n). So the i function receives as x the y index of the table, and it receives as y the x index. The names got a little backwards here :).

i:y y#[((jn<yn%2),ly^2){' >+/(V' '' 'c1'qx y)^2 c1 n%2 } n divided by 2 '' (n%2)^2 } squared 'c2' x y } make a 2-element array (x,y) c2 qx y } call q on this array ''  'c3'

where q does

q:y-(n-1)%2 c3 n-1 } n minus 1 '' %2 } divided by 2 'c4' y- } y minus that c4

back to i

i:[((n%2)^2)>+/(qx y)^2 '' ( )^2 } square the result from q(x,y) 'c5' +/ } sum the two numbers c5 > } compare the left side (above) with the right (=> 0/1)  [ } floor 

In action (piping through tr to remove tab chars which are the REPL's prompt):

josh@Z1 ~/inca $ ./inca2 <icecream | tr -d '\t' c1 V c2 (( VV c3 ((( VVV V c4 (( (((( VVVV VV c5 ((( ((((( VVVVV VVV V josh@Z1 ~/inca $ 

In action (piping through tr to remove tab chars which are the REPL's prompt):

josh@Z1 ~/inca $ cat icecream i:[((n%2)^2)>((x-(n-1)%2)^2)+(y-(n-1)%2)^2 j:(~[y%2)i.(~y) k:2*[x>[|y-(n-1)%2 l:(@1+~]y%2)k.(~y) c:y y#((jn<y),ly){' (V' '' 'c1' c1 '' 'c2' c2 '' 'c3' c3 '' 'c4' c4 '' 'c5' c5 josh@Z1 ~/inca $ ./inca2 <icecream | tr -d '\t' c1 V c2 (( VV c3 ((( VVV V c4 (( (((( VVVV VV c5 ((( ((((( VVVVV VVV V josh@Z1 ~/inca $ 

In more detail, the entry-point is the c function which takes one argument implicitly named y.

c:y y#((jn<y),ly){' (V'   n<y } assign y to 'n'  jn<y } call j(y) ly } call l(y) (( ), ) } catenate the results ( ){' (V' } map 0 1 2 to ' ' '(' 'V' y y# } reshape to NxN 

The j function receives the same input value as its y parameter.

j:(~[y%2)i.(~y)  y%2 } y divided by 2  [ } floor ~ } iota. this generates the row indices 0..y/2 ~y } iota y. this generates the column indices 0..y ( )i.( ) } jot-dot with the function i 

The jot-dot here does the double-loop. It calls the i function with every combination of elements from the left and right arrays (0..n/2 and 0..n). So the i function receives as x the y index of the table, and it receives as y the x index. The names got a little backwards here :).

i:[((n%2)^2)>+/(qx y)^2  n%2 } n divided by 2  (n%2)^2 } squared  x y } make a 2-element array (x,y)  qx y } call q on this array   

where q does

q:y-(n-1)%2  n-1 } n minus 1  %2 } divided by 2  y- } y minus that 

back to i

i:[((n%2)^2)>+/(qx y)^2  ( )^2 } square the result from q(x,y)  +/ } sum the two numbers  > } compare the left side (above) with the right (=> 0/1)  [ } floor 

In action (piping through tr to remove tab chars which are the REPL's prompt):

josh@Z1 ~/inca $ ./inca2 <icecream | tr -d '\t' c1 V c2 (( VV c3 ((( VVV V c4 (( (((( VVVV VV c5 ((( ((((( VVVVV VVV V josh@Z1 ~/inca $ 
factor-out repeated expression as a function
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61
Loading
apply repeated expression array-wise
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61
Loading
nicer typescript
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61
Loading
-2 remove useless ravels
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61
Loading
-6 combine 2 maps into 1
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61
Loading
corrected
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61
Loading
Source Link
luser droog
  • 5k
  • 2
  • 37
  • 61
Loading