>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Dictionary

22. Distance

The “street” distance between two points will be defined as the sum of the magnitudes of the difference of their coordinates along each axis. Thus:
d=: +/@:|@:-"1
p=: 3 5 1 [ q=: 7 4 0
p d q
6

table=: #: i. 2^3
(]; d/~) table             NB. Table and distances between each pair of points in it
+-----+---------------+
|0 0 0|0 1 1 2 1 2 2 3|
|0 0 1|1 0 2 1 2 1 3 2|
|0 1 0|1 2 0 1 2 3 1 2|
|0 1 1|2 1 1 0 3 2 2 1|
|1 0 0|1 2 2 3 0 1 1 2|
|1 0 1|2 1 3 2 1 0 2 1|
|1 1 0|2 3 1 2 1 2 0 1|
|1 1 1|3 2 2 1 2 1 1 0|
+-----+---------------+

g=: [ * [ = d/~@]
(];(d/~);(1&g);(2&g)) table
+-----+---------------+---------------+---------------+
|0 0 0|0 1 1 2 1 2 2 3|0 1 1 0 1 0 0 0|0 0 0 2 0 2 2 0|
|0 0 1|1 0 2 1 2 1 3 2|1 0 0 1 0 1 0 0|0 0 2 0 2 0 0 2|
|0 1 0|1 2 0 1 2 3 1 2|1 0 0 1 0 0 1 0|0 2 0 0 2 0 0 2|
|0 1 1|2 1 1 0 3 2 2 1|0 1 1 0 0 0 0 1|2 0 0 0 0 2 2 0|
|1 0 0|1 2 2 3 0 1 1 2|1 0 0 0 0 1 1 0|0 2 2 0 0 0 0 2|
|1 0 1|2 1 3 2 1 0 2 1|0 1 0 0 1 0 0 1|2 0 0 2 0 0 2 0|
|1 1 0|2 3 1 2 1 2 0 1|0 0 1 0 1 0 0 1|2 0 0 2 0 2 0 0|
|1 1 1|3 2 2 1 2 1 1 0|0 0 0 1 0 1 1 0|0 2 2 0 2 0 0 0|
+-----+---------------+---------------+---------------+

{&' .+*' &.> (];(d/~);(1&g);(2&g);(3&g)) table
+---+--------+--------+--------+--------+
|   | ..+.++*| .. .   |   + ++ |       *|
|  .|. +.+.*+|.  . .  |  + +  +|      * |
| . |.+ .+*.+|.  .  . | +  +  +|     *  |
| ..|+.. *++.| ..    .|+    ++ |    *   |
|.  |.++* ..+|.    .. | ++    +|   *    |
|. .|+.*+. +.| .  .  .|+  +  + |  *     |
|.. |+*.+.+ .|  . .  .|+  + +  | *      |
|...|*++.+.. |   . .. | ++ +   |*       |
+---+--------+--------+--------+--------+

>>  <<  Usr  Pri  JfC  LJ  Phr  Dic  Voc  !:  Help  Dictionary