fold may not be the right approach

1 ( 3 2 $ 1 2 3 4 5 6)} 10 10 $ 0






On Saturday, April 23, 2022, 02:02:10 p.m. EDT, Pawel Jakubas 
<jakubas.pa...@gmail.com> wrote: 





Dear J enthusiast,

I try to play with fold functionality F...
and here solve more general cases, so when the accumulator structure is
different from the list structure that is iterated.

To be concrete let's say we have the array, A, and a list of 2-elem
vectors, vec,
which institute coordinates (x,y) which I want to update in A.
```
A=: 10 10 $ 0
]vec=: 3 2 $ 1 2 3 4 5 6
1 2
3 4
5 6
```
Now, I can of course solve this recursively, eg:
```
fold=: 4 : 0
'r c' =. ,"0 $ x
if. (r=1) do.
  'x0 y0'=. {. x
  1 (<(x0),(y0)) } y
else.
    'x0 y0'=. {. x
  y1=.1 (<(x0),(y0)) } y
  (}. x) fold y1
end.
)
  vec fold A
0 0 0 0 0 0 0 0 0 0
0 0 1 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 0 0 0 0 0 0 0
0 0 0 0 0 0 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 0 0 0 0 0 0 0 0
```

How to start with A, use vec as iterator list in one of folds F.. and end
up with updated A as above?
Thanks in advance!
Cheers,
Pawel Jakubas
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to