Probably slower but equivalent with your e is

e1a=: 4 : 0"0 1
 z=. x(|{.)y
 select. z
  case. 0 do. <+/y
  case. 1 do. <*/y
  case. 2 do. <>./y
  case.   do. a:
 end.
)

   (5 ?...@$ 4) ;@:e1a 5 4 ?...@$ 20
52 19 38 30


R.E. Boss



> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens R.E. Boss
> Verzonden: dinsdag 2 februari 2010 11:21
> Aan: 'Programming forum'
> Onderwerp: Re: [Jprogramming] loopless programming question
> 
> What e does in the while loop is matching the items of x with those of y.
> For this we have the rank conjunction, which in this case is "0 1 .
> Only ravel the result.
> 
> 
> e1=: 4 : 0"0 1
>  w=. i. 0
>  z=. x(|{.)y
>  select. z
>   case. 0 do. w=. w,+/y
>   case. 1 do. w=. w,*/y
>   case. 2 do. w=. w,>./y
>   case.   do. w=. w
>  end.
>  w
> )
> 
>    (5 ?...@$ 4) ,@:e1 5 4 ?...@$ 20
> 52 19 38 0 30
> 
> 
> R.E Boss
> 
> 
> > -----Oorspronkelijk bericht-----
> > Van: [email protected] [mailto:programming-
> > [email protected]] Namens Brian Schott
> > Verzonden: dinsdag 2 februari 2010 4:42
> > Aan: [email protected]
> > Onderwerp: [Jprogramming] loopless programming question
> >
> >
> >     I am working on revising an Einstein puzzle solving
> > program which currently is written as long while. loops, so
> > that the looping is minimized in the revision. I think the
> > answer to my question has been discussed in these forums as
> > a way to more efficiently calculate a result when the number
> > of different calculations is small relative to the length of
> > the list of data that is being operated upon. But I cannot
> > imagine how to search for that thread, so I have tried to
> > create a verb that shows the while. loop process in my
> > current program but does not resemble the real problem which
> > is more complex. I hope that with help on revising this
> > simplified problem to eliminate the while. loop, I can
> > master my real one.
> >
> > Thank you,
> >
> >    e =: dyad define"1 2
> > assert. x -:&{.&$ y
> > w=. i. 0
> > while. #y do.
> > b=. {. y
> > z=. x|&{.b
> > select. z
> > case. 0 do. w=. w,+/b
> > case. 1 do. w=. w,*/b
> > case. 2 do. w=. w,>./b
> > case.  do. w=. w
> > end.
> > x=.}.x
> > y=.}.y
> > end.
> > w
> > )
> >
> > NB. more realistically the 5's below would be 300's.
> > NB. but this example is adequate, I hope
> >    (5 ?...@$ 4) e 5 4 ?...@$ 20
> > 52 19 38 30
> >    (5 ?...@$ 4) ; 5 4 ?...@$ 20
> > +---------+-----------+
> > |2 3 3 0 2| 6 15 19 12|
> > |         |14 19  0 17|
> > |         | 0 14  6 18|
> > |         |13 18 11 12|
> > |         |18  0 10  2|
> > +---------+-----------+
> >    2 3 3 0 2|6 14 0 13 18
> > 0 2 0 13 0
> >
> > --
> >
> > (B=) <----------my "sig"
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> 
> ----------------------------------------------------------------------
> 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