Faster and leaner and prettier:

(4$15) ((-:"1 +/"1)*(-:"1 +/"2)) q{0,2^i.4



----- Original Message -----
From: Marshall Lochbaum <[email protected]>
Date: Tuesday, October 5, 2010 15:47
Subject: Re: [Jprogramming] Distinct Numbers in Rows and Columns
To: 'Programming forum' <[email protected]>

> Small timesaving addition:
> ([:*./@, [:~:"1 (,: |:))"2 q
> 
> However, the Hui version can be formatted to be superior if 
> space is a
> limiting factor:
>    q=.100000 10 1...@$10
>    ts '([:*./@, [:~:"1 (,: |:))"2 q'
> 0.513206 143616
>    ts '((8$15) -: (+/"1 , +/)@:({&(0,2^i.10)))"2 q'
> 0.160701 141824
> 
> In fact, virtually all of the space used was in selection, and 
> the solution
> does not use significantly more space than q does:
>    7!:5 <'q'
> 1.34218e8
>    ts '(8$15) -:"1 (+/"1 ,. +/"2) q{0,2^i.10'
> 0.16598 1.6778e8
>    ts 'q{0,2^i.10'
> 0.0981654 1.3422e8
> 
> Marshall
> 
> 
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of R.E. Boss
> Sent: Tuesday, October 05, 2010 5:44 AM
> To: 'Programming forum'
> Subject: Re: [Jprogramming] Distinct Numbers in Rows and Columns
> 
> 
>    q #~ ([:*./^:3 [:~:"1 (,: |:))"2 q
> 1 2 4 3
> 4 3 2 1
> 2 1 3 4
> 3 4 1 2
> 
>    ts'q#~([:*./^:3[:~:"1(,:|:))"2 q'
> 0.030079443 12352
>    ts'q #~ (8$15) -:"1 (+/"1 ,. +/"2) q{0,2^i.4'
> 0.0026829032 2100864
> 
> Slower but leaner:
> 
>    rank 'q #~ (8$15) -:"1 (+/"1 ,. +/"2) q{0,2^i.4';
> 'q#~([:*./^:3[:~:"1(,:|:))"2 q'
> +----+-----+-----+------+
> |rank|tm*sz|time |size  |
> +----+-----+-----+------+
> | 1  |15.85| 1.00|170.08|
> +----+-----+-----+------+
> | 0  | 1.00|10.73|  1.00|
> +----+-----+-----+------+
> 
> 
> R.E. Boss
> 
> 
> > -----Oorspronkelijk bericht-----
> > Van: [email protected] [mailto:programming- 
> > [email protected]] Namens Roger Hui
> > Verzonden: dinsdag 5 oktober 2010 1:37
> > Aan: Programming forum
> > Onderwerp: Re: [Jprogramming] Distinct Numbers in Rows and Columns
> > 
> > Great minds think alike, eh?  (But I think you need to 
> test your 
> > expressions ;-)  Go to 
> http://www.jsoftware.com/jwiki/Essays/KenKen> and look about a 
> third of the way down,
> > 
> > q #~ (8$15) -:"1 (+/"1 ,. +/"2) q{0,2^i.4
> > 
> > The initial effort in your previous msg is also similar to my 
> initial 
> > effort.
> > 
> > 
> > 
> > ----- Original Message -----
> > From: Marshall Lochbaum <[email protected]>
> > Date: Monday, October 4, 2010 16:28
> > Subject: Re: [Jprogramming] Distinct Numbers in Rows and Columns
> > To: 'Programming forum' <[email protected]>
> > 
> > > Here's a funny--and much faster--one:
> > > p=.p:i.n
> > > *./"1 (*/p) = (*/"2 ,. */"1) q{p
> > >
> > > Actually, I suppose it is better to do it with addition, so 
> p=.2^i.n> > *./"1 (+/p) = (+/"2 ,. +/"1) q{p
> > >
> > > Marshall
> > >
> > > -----Original Message-----
> > > From: [email protected] 
> > > [mailto:[email protected]] On Behalf Of 
> Roger Hui
> > > Sent: Monday, October 04, 2010 6:41 PM
> > > To: Programming forum
> > > Subject: [Jprogramming] Distinct Numbers in Rows and Columns
> > >
> > > An interesting puzzle arising from the KenKen solver:
> > > q is an array with shape (m,n,n) and  (,q) e. 1+i.n .
> > > Which items of q have 1+i.n in each row and in each column?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to