I want to calculate a fifo problems to match in-qty to out-qty,
Assuming all qty are positive
in-qty 1000 2000 1500 1000
out-qty 500 3000 1000
then a verb fifo, such that
500 3000 1000 fifo 1000 2000 1500 1000
will give
0 0 500
1 0 500
1 1 2000
1 2 500
2 2 1000
where format in each row,
index-to-outqty index-to-inqty qty-allocated
I have written a simple scalar C algorithm below and want to learn how to do it
in vector J approach.
fifo=: 4 : 0
out=. x
in=. y
ox=. ix=. 0 [ z=. 0 3$0
while. (ox<#out) *. ix<#in do.
a=. ox{out
b=. ix{in
if. a=b do.
z=. z, ox, ix, a
out=. 0 ox}out
in=. 0 ix}in
ox=. >:ox [ ix=. >:ix
elseif. a<b do.
z=. z, ox, ix, a
out=. 0 ox}out
in=. (b-a) ix}in
ox=. >:ox
elseif. a>b do.
z=. z, ox, ix, b
out=. (a-b) ox}out
in=. 0 ix}in
ix=. >:ix
end.
end.
z
)
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm