APL Wiki logo: Difference between revisions

Jump to navigation Jump to search
485 bytes added ,  20:02, 7 January 2020
Line 161: Line 161:
8 11 11 8
8 11 11 8
</source>
</source>
But obviously, we can't let the circles touch, so we add 1. Finally, we prepend a 0 which is the offset of the first circle:
But obviously, we can't let the circles touch, so we add 1. This gives us all the centre-to-centre distances from the neighbours on the left (or above):
<source lang=apl>
      1+⌈⌿2+/sizes
9 12 12 9
</source>
We also need an "offset" of the left/top-most circles which don't have any neighbours, so we prepend a 0:
<source lang=apl>
      0,1+⌈⌿2+/sizes
0 9 21 33 42
</source>
Finally, we compute the total offset for each column/row by finding the running total of the offsets:
<source lang=apl>
<source lang=apl>
       ⊢offsets←0,+\1+⌈⌿2+/sizes
       ⊢offsets←0,+\1+⌈⌿2+/sizes
0 9 21 33 42
0 9 21 33 42
</source>
</source>
<source lang=apl inline>⊢</source> is the [[identity]] function, which is just used here get the pass-though value from the assignment, as it would otherwise be hidden. (We call assignment ''shy''.)
<source lang=apl inline>⊢</source> is the [[identity]] function, which is just used here get the pass-though value from the assignment, as it would otherwise be hidden. (We call assignment ''shy''.) <source lang=apl inline>\</source> is just like <source lang=apl inline>/</source> but gives us the intermediate values.
 
=== Generating indices in 2D ===
=== Generating indices in 2D ===
<source lang=apl inline>⍴r</source> is the [[shape]] of our array of radii. Now, you remember <source lang=apl inline>⍳</source>, [[#Generating_indices|right]]? As it turns out, it can actually generate of an array of any number of dimensions; two in our case:
<source lang=apl inline>⍴r</source> is the [[shape]] of our array of radii. Now, you remember <source lang=apl inline>⍳</source>, [[#Generating_indices|right]]? As it turns out, it can actually generate of an array of any number of dimensions; two in our case:

Navigation menu