Glenn -

Joey's solution is fine but, for pedagogy, you might want to more deeply
analyze what you're
trying to do and work out what needs to be done.

The key insight is that you are generating four numbers - potentially as a
vector - from each
input item, i.e. each scalar.  Given this, I'd re-write "diagonals" this
way:

diagonals=: 3 : 0
t1 =. brds y
t2 =. y */ 0 2 4 6
t1 -"(0 1) t2
)

This also eliminates the "4$" which is covertly connected to the length of
"0 2 4 6".

Good luck,

Devon

On 6/19/07, Joey K Tuttle <[EMAIL PROTECTED]> wrote:

At 14:43  -0400 2007/06/19, Lewis, Glenn wrote:
>
>    diagonals 0
>
>1 1 1 1
>
>    diagonals 1
>
>9 7 5 3
>
>    diagonals 2
>
>25 21 17 13
>
>
>
>    But if I try to get all diagonals from the first 10 rings of the
>spiral, I get:
>
>
>
>    diagonals i. 10
>
>|length error: diagonals
>
>|   t2=.0 2 4 6    *y
>
>
>
>    I understand what the problem is (the length mismatch), but don't
>know how to fix it...  I need to take each scalar in y one-at-a-time...
>and I tried all sorts of combinations of " (double quote) to treat the
>right hand side like a rank 0 input, but couldn't get it to work.
>
>
>
>             Any ideas?


    diagonals "0 i. 10
   1   1   1   1
   9   7   5   3
  25  21  17  13
  49  43  37  31
  81  73  65  57
121 111 101  91
169 157 145 133
225 211 197 183
289 273 257 241
361 343 325 307

Seems to work well, that is making diagonals rank 0, you could
do that when defining it, thus -

    diagonals =: 3 : 0 "0
t1 =. 4 $ brds y
t2 =. 0 2 4 6 * y
t1 - t2
)
    diagonals i. 10
   1   1   1   1
   9   7   5   3
  25  21  17  13
  49  43  37  31
  81  73  65  57
121 111 101  91
169 157 145 133
225 211 197 183
289 273 257 241
361 343 325 307

- joey

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to