Oops, last one should be

   >;<@,@:{"1 (<1 _1)(0([EMAIL PROTECTED] <@#: I.@,@:=) M)}<"0 M
 1 _1  1  1
 1 _1 _1  1
 1  1 _1  1
 1  1  1 _1
 1  1 _1 _1
_1  1  1 _1
_1  1 _1 _1


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED] [mailto:programming-
> [EMAIL PROTECTED] Namens R.E. Boss
> Verzonden: zondag 9 maart 2008 22:57
> Aan: 'Programming forum'
> Onderwerp: RE: [Jprogramming] Turning 0 into _1 1 in a list
> 
>    [M=:1 _1  0  1,1  1 _1  1,:0  1  0 _1
> 1 _1  0  1
> 1  1 _1  1
> 0  1  0 _1
> 
>    0([EMAIL PROTECTED] <@#: I.@,@:=) M
> +---+---+---+
> |0 2|2 0|2 2|
> +---+---+---+
>       NB. coordinates of zeroes
> 
>    (<1 _1)(0([EMAIL PROTECTED] <@#: I.@,@:=) M)}<"0 M
> +----+--+----+--+
> |1   |_1|1 _1|1 |
> +----+--+----+--+
> |1   |1 |_1  |1 |
> +----+--+----+--+
> |1 _1|1 |1 _1|_1|
> +----+--+----+--+
>       NB. replace boxed zeroes by 1 _1
> 
>    <@{"1 (<1 _1)(0([EMAIL PROTECTED] <@#: I.@,@:=) M)}<"0 M
> +--------------------+----------+----------------------+
> |+--------+---------+|+--------+|+---------+----------+|
> ||1 _1 1 1|1 _1 _1 1|||1 1 _1 1|||1 1 1 _1 |1 1 _1 _1 ||
> |+--------+---------+|+--------+|+---------+----------+|
> |                    |          ||_1 1 1 _1|_1 1 _1 _1||
> |                    |          |+---------+----------+|
> +--------------------+----------+----------------------+
>       NB. use catalogue to make all combinations
> 
>    >,;<@{"1 (<1 _1)(0([EMAIL PROTECTED] <@#: I.@,@:=) M)}<"0 M
>  1 _1  1  1
>  1 _1 _1  1
>  1  1 _1  1
>  1  1 _1  1
>  1  1  1 _1
>  1  1 _1 _1
> _1  1  1 _1
> _1  1 _1 _1
> 
> 
>    replaceZeroes M
> 1 _1 _1 1 1 _1 1 1 1 1 _1 1 _1 1 _1 _1 _1 1 1 _1 1 1 _1 _1 1 1 1 _1
> 
> 
> R.E. Boss
> 
> 
> > -----Oorspronkelijk bericht-----
> > Van: [EMAIL PROTECTED] [mailto:programming-
> > [EMAIL PROTECTED] Namens Geoff Canyon
> > Verzonden: zondag 9 maart 2008 21:59
> > Aan: Programming forum
> > Onderwerp: Re: [Jprogramming] Turning 0 into _1 1 in a list
> >
> > I think the eventual solution I came up with was somewhat similar to
> > this. Here's my solution:
> >
> > replaceZeroes =: (;@:;@:(_4([:<(((_1 1 (] i.&0)}"0 1 ])`])@.(# =
> > i.&0)))\]))^:_
> >
> > I spent some time trying to figure out how to apply the replacement
> > repeatedly before boxing and then unbox at the end, to minimize boxing/
> > unboxing, but I couldn't get that to work. So in the above, the boxing/
> > unboxing happens for each replacement. This isn't so bad in my
> > particular case since no list has more than three zeroes in it. If the
> > lists had many zeroes, the whole thing would come apart, since I'm
> > starting with 512 lists of 27 elements, so a bunch of zeroes would
> > quickly result in millions of lists. As it is, I end up with less than
> > a thousand.
> >
> > Still I wonder that there seems to be no way to avoid boxing/unboxing?
> > If I have a list and I want to transform that list, with the subsets I
> > take potentially changing in length, I can't do that without boxes?
> >
> > Say I have a list like this: 1 2 3 4 5 6 7 8
> >
> > And I want the result to be a list that a duplicate for each prime in
> > the list:
> >
> > 1 2 2 3 3 4 5 5 6 7 7 8
> >
> > Are boxes the only/best way?
> >
> > regards,
> >
> > Geoff
> >
> > On Mar 4, 2008, at 5:17 AM, Raul Miller wrote:
> >
> > > I have some comments in addition to R.E.Boss's comments
> > > (and using his M)
> > >   M=:1 _1  0  1,1  1 _1  1,:0  1  0 _1
> > >
> > > A simple approach to supressing fill uses box (<) followed
> > > by raze (;).  In other words:
> > >
> > >   <@(_1 1 (] i.&0)}"0 1 ])`<@.(# = i.&0)"1 M
> > ----------------------------------------------------------------------
> > 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