For lack of anything to do on a lazy Sunday, I thought I would benchmark the
different kr's.
Using slightly larger matrices,
A=: ? 10 10 $ 100
B=: ? 6 6 $ 100
kr1=:*&$ $ ,@:>@:,@:(|:"2)@:(<"1)@:(*"0 _) NB. Mine
kr2=: [: ,./^:2 *"0 2 NB. Roger's
kr3=: ,/@:(_2 ,./\ ,/@:(*/)) NB. Pascal's
40 timespacex 'A kr1 B'
0.000137875 160896
40 timespacex 'A kr2 B'
8.0325e_5 100608
40 timespacex 'A kr3 B'
0.000149175 192512
Clearly, Roger's is fastest and uses less memory (for this test).
Using larger floating point matrices:
C=: ? 100 100 $ 0
D=: ? 20 20 $ 0
timespacex 'C kr1 D'
0.064277 1.22505e8
timespacex 'C kr2 D'
0.018471 1.00666e8
timespacex 'C kr3 D'
0.037089 1.75952e8
--------------------------------------------
On Sun, 10/15/17, 'Pascal Jasmin' via Programming <[email protected]>
wrote:
Subject: Re: [Jprogramming] reminded of an old puzzle
To: "[email protected]" <[email protected]>
Date: Sunday, October 15, 2017, 2:00 AM
not as nice, but it is mine :P
a ,/@:(_2 ,./\
,/@:(*/)) b
________________________________
From: robert therriault <[email protected]>
To: [email protected]
Sent: Saturday, October 14, 2017 12:31
PM
Subject: Re: [Jprogramming] reminded of
an old puzzle
Slight variation to Roger
(talk about standing on the shoulders of giants!)
kr=: [: ,./^:2 */
a kr b
2 2 2 3 3 3
2 4 2 3 6 3
2 2 2 3 3
3
5 5 5 7 7 7
5 10 5 7
14 7
5 5 5 7 7 7
Cheers, bob
> On Oct 14, 2017, at 9:10 AM, Roger Hui
<[email protected]>
wrote:
>
> kr=: [:
,./^:2 *"0 2
>
> a kr b
> 2 2 2 3
3 3
> 2 4 2 3 6 3
> 2 2 2 3 3 3
> 5 5
5 7 7 7
> 5 10 5 7 14 7
> 5 5 5 7 7 7
----------------------------------------------------------------------
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