Quoting Brian Schott <[EMAIL PROTECTED]>:

m132 =: ([:-.(1:,''"_=])#.1:)}.] NB. delete trailing blanks

The algorithm is correct, but there was a transcription error (probably). the '' should have been ' ' (a single space instead of an empty vector):

           m132 =: ([:-.(1:,' '"_=])#.1:)}.] NB. delete trailing blanks
           m132  'abc  def    '
        abc  def

FYI, the standard library has a lot of useful utilities pre-defined for you, so you needn't go to the phrases very often. In this case, for example:

           load 'strings'

           dtb
        #~ ([: +./\. ' '&~:)

           dtb 'abc  def    '
        abc  def

Perhaps JSoftware should change this definition to take advantage of the special code supporting the train i: = 0:. Using the framework provided by http://www.jsoftware.com/jwiki/DanBron/Snippets/VerbMetrics and the definitions:

         ...

           dtb0    =:  }.~ [: -. 1 #.~ 1 , ' ' = ]
           dtb1    =:  #~ [: +./\. ' ' ~: ]
           dtb2    =:  {.~ 1 + ' '&(= i: 0:)

         ...

           small   =:    50000 H b1           k =: 'abc def abc def abc        '
           medium  =:      500 H b1   1000 {. k
           large   =:        1 H b1    5e6 {. k

         ...

The verb dtb2 is a clear winner on large datasets:

                  set   alg  time   space
                 ------ ---- ----- --------

                        dtb0  2.01     2.17
                 small  dtb1  1.00     1.06
                        dtb2  1.03     1.00

                        dtb0  6.16    72.72
                 medium dtb1  3.04    29.28
                        dtb2  1.00     1.00

                        dtb0 18.26 36410.50
                 large  dtb1  9.74 14564.39
                        dtb2  1.00     1.00

-Dan

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

Reply via email to