To improve the timing of my |.@:|:@:}. ("peeling") solution, I decided to replace ^:a: ("until there's nothing left") with an explicit calculation of iterations ("N skins"):

           spiral     =.  1 : '| $ /:@:;@:u@:i. f.'

           bronion0   =.  [: ({.&.> #~ 0 ~: */@:$&>) |.@:|:@:}.&.>^:a: @: <
           bron0      =:  bronion0  spiral

           skins      =.  ((0 ~: *) * (2 * <.) - <: + 1 = [)/@:$&.>
           bronion1   =.  [: {.&.> |.@|:@:}.&.>^:skins @:<
           bron1      =:  bronion1  spiral

           (bron1 -: bron0) 4 5
        1

           10 (7!:2@:] , 6!:2) 'bron0 400 500'
        3.47534e8 2.01377
           10 (7!:2@:] , 6!:2) 'bron1 400 500'
        3.47471e8 1.97628

Unfortunately, the speed up is negligible. I have concluded the reason is since f^:a: y stops when y -: f y , then I was only saving N invocations of -: (where N =. skins y ) . In this case, -: is trivially false, because |.@:|:@:}. is a shape-changing operation, so no atoms need be compared.

Oh well.

-Dan

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to