At 13:43  -0500 2009/12/07, Richard Kubina wrote:
>..well the  >:  to i.1000 is silly... a slight fix:
>
>  >./(#~ (= (|.&.":)"0)) ,*/~i.1000
>
>Sorry for double post, this is exciting (:


I agree with Don that your use of &. is cute. Adding one more token ( 
~. ) to only work on unique values would speed up your algorithm by a 
factor of 4 -

   >./(#~ (= (|.&.":)"0)) ~. ,*/~i.1000

A little different and more explicit route would be -

   maxpal =: 3 : '>./(*./zd=|.zd)#z[zd=.''0123456789''i.|:":,.z=.~.,*/~i.y'

which is considerably faster. I think it is easier to parse the 
explicit verb than a generated tacit one:

   13 : '>./(*./zd=|.zd)#z[zd=.''0123456789''i.|:":,.z=.~.,*/~i.y'
([: ('0123456789' i. [: |: [: ": ,.) [: ~. [: , [: */~ i.) ([: >./ 
([: ([: *./ ] = |.) [) # ]) [: ~. [: , [: */~ i.

And the generated tacit one is a little slower than the explicit one, 
the (normalized) time comparisons are:

  Time   Expression
  ____   _______________________
  1      >./(#~ (= (|.&.":)"0)) ,*/~i.1000
  0.259  >./(#~ (= (|.&.":)"0)) ~. ,*/~i.1000
  0.026  >./(*./zd=|.zd)#z[zd=.'0123456789'i.|:":,.z=.~.,*/~i.1000

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

Reply via email to