Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] Finding Minimum Value in Array

Expand Messages
  • flo.gehrke
    ... Harvey, I agree with you. ^$StrTrim is another solution though it s geared towards removing blank spaces. From... ^!Set
    Message 1 of 15 , Nov 1, 2009
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, hsavage <hsavage@...> wrote:
      >
      > Flo,
      >
      > Small command line utilities are very handy. To get rid of the
      > crlf try this line.
      >
      > ^!Set %Min%=^$StrTrim("^$GetDosOutput(EVAL MIN(^%Array%))$")$

      Harvey,

      I agree with you. ^$StrTrim is another solution though it's geared towards removing blank spaces.

      From...

      ^!Set %Array%=3,8,329,1,1.25,7,10.34,4,9,6,2,5,11
      ^!Toolbar New Document
      ^$GetDosOutput(EVAL MIN(^%Array%))$


      I got the impression that EVAL.EXE is adding one or more CRNL to the output.

      Flo
    • Hugo Paulissen
      Hi Flo, You can do this without evaluation. In the past I have used something along these lines: ^!SetListDelimiter , ^!SetArray
      Message 2 of 15 , Nov 2, 2009
      • 0 Attachment
        Hi Flo,

        You can do this without evaluation. In the past I have used something along these lines:

        ^!SetListDelimiter ,
        ^!SetArray %Array%=3,8,329,1,1.25,7,10.34,4,9,6,2,5,11
        ^!SetListDelimiter ^%NL%
        ^!SetArray %Array%=^$StrSort("^$StrReplace(",";"^%NL%";"^%Array%";0;0)$";False;True;False)$
        ^!Info ^%Array1%

        Regards,

        Hugo




        ________________________________
        From: flo.gehrke <flo.gehrke@...>
        To: ntb-clips@yahoogroups.com
        Sent: Mon, November 2, 2009 7:57:18 AM
        Subject: Re: [Clip] Finding Minimum Value in Array

         
        --- In ntb-clips@yahoogrou ps.com, hsavage <hsavage@... > wrote:
        >
        > Flo,
        >
        > Small command line utilities are very handy. To get rid of the
        > crlf try this line.
        >
        > ^!Set %Min%=^$StrTrim( "^$GetDosOutput( EVAL MIN(^%Array% ))$")$

        Harvey,

        I agree with you. ^$StrTrim is another solution though it's geared towards removing blank spaces.

        From...

        ^!Set %Array%=3,8, 329,1,1.25, 7,10.34,4, 9,6,2,5,11
        ^!Toolbar New Document
        ^$GetDosOutput( EVAL MIN(^%Array% ))$

        I got the impression that EVAL.EXE is adding one or more CRNL to the output.

        Flo







        [Non-text portions of this message have been removed]
      • Don - HtmlFixIt.com
        Doesn t work Hugo, ^!SetListDelimiter , ^!SetArray %Array%=3,8,329,7,10.34,4,9,6,2,5,11 ^!SetListDelimiter ^%NL% ^!SetArray
        Message 3 of 15 , Nov 2, 2009
        • 0 Attachment
          Doesn't work Hugo,

          ^!SetListDelimiter ,
          ^!SetArray %Array%=3,8,329,7,10.34,4,9,6,2,5,11
          ^!SetListDelimiter ^%NL%
          ^!SetArray
          %Array%=^$StrSort("^$StrReplace(",";"^%NL%";"^%Array%";0;0)$";False;True;False)$
          ^!Info ^%Array1% ^%NL% ^%Array%

          You just got lucky :-)

          We always zero pad because I use your method to zero pad. We need a
          numeric sort I think in addition to ANSI and false_ANSI

          Hugo Paulissen wrote:
          > Hi Flo,
          >
          > You can do this without evaluation. In the past I have used something along these lines:
          >
          > ^!SetListDelimiter ,
          > ^!SetArray %Array%=3,8,329,1,1.25,7,10.34,4,9,6,2,5,11
          > ^!SetListDelimiter ^%NL%
          > ^!SetArray %Array%=^$StrSort("^$StrReplace(",";"^%NL%";"^%Array%";0;0)$";False;True;False)$
          > ^!Info ^%Array1% ^%NL% ^%Array%

          >
          > Regards,
          >
          > Hugo
          >
        • Hugo Paulissen
            Hi Don,   Quite possible that I just got lucky ;-), but I m not so sure we need a numeric sort for this. I do not recall the reason for the zero-padding,
          Message 4 of 15 , Nov 2, 2009
          • 0 Attachment
             
            Hi Don,
             
            Quite possible that I just got lucky ;-), but I'm not so sure we need a numeric sort for this. I do not recall the reason for the zero-padding, but it doesn't seem necessary in this case.
             
            In any case: if I add some other values to the array, it appears that the lowest value is returned every single time.
             
            ^!SetArray %Array%=03,8,329,1,1.25,7,10.34,4,9,6,2,5,11,0.25,0.1,10000,20,0.0119,10,0.012
             
            Hugo
             
             
            >>> 
            Doesn't work Hugo,

            ^!SetListDelimiter ,
            ^!SetArray %Array%=3,8, 329,7,10. 34,4,9,6, 2,5,11
            ^!SetListDelimiter ^%NL%
            ^!SetArray
            %Array%=^$StrSort( "^$StrReplace( ",";"^%NL% ";"^%Array% ";0;0)$"; False;True; False)$
            ^!Info ^%Array1% ^%NL% ^%Array%

            You just got lucky :-)

            We always zero pad because I use your method to zero pad. We need a
            numeric sort




            [Non-text portions of this message have been removed]
          • Hugo Paulissen
            OK Don, Sorry Flo, Forget my last post; I see what you mean... Now I *do* remember the padding zero issue! It s getting rusty inside... Hugo
            Message 5 of 15 , Nov 2, 2009
            • 0 Attachment
              OK Don, Sorry Flo,

              Forget my last post; I see what you mean... Now I *do* remember the padding zero issue! It's getting rusty inside...

              Hugo




              ________________________________
              From: Hugo Paulissen <hugopaulissen@...>
              To: ntb-clips@yahoogroups.com
              Sent: Mon, November 2, 2009 4:28:06 PM
              Subject: Re: [Clip] Finding Minimum Value in Array

               
               
              Hi Don,
               
              Quite possible that I just got lucky ;-), but I'm not so sure we need a numeric sort for this. I do not recall the reason for the zero-padding, but it doesn't seem necessary in this case.
               
              In any case: if I add some other values to the array, it appears that the lowest value is returned every single time.
               
              ^!SetArray %Array%=03,8, 329,1,1.25, 7,10.34,4, 9,6,2,5,11, 0.25,0.1, 10000,20, 0.0119,10, 0.012
               
              Hugo
               
               
              >>> 
              Doesn't work Hugo,

              ^!SetListDelimiter ,
              ^!SetArray %Array%=3,8, 329,7,10. 34,4,9,6, 2,5,11
              ^!SetListDelimiter ^%NL%
              ^!SetArray
              %Array%=^$StrSort( "^$StrReplace( ",";"^%NL% ";"^%Array% ";0;0)$"; False;True; False)$
              ^!Info ^%Array1% ^%NL% ^%Array%

              You just got lucky :-)

              We always zero pad because I use your method to zero pad. We need a
              numeric sort

              [Non-text portions of this message have been removed]







              [Non-text portions of this message have been removed]
            • flo.gehrke
              ... Hugo, Don, I don t think that Hugo was wrong. There has always been some confusion about this issue (cf message #19038 ff). The trick is the ^%NL% as
              Message 6 of 15 , Nov 2, 2009
              • 0 Attachment
                --- In ntb-clips@yahoogroups.com, Hugo Paulissen <hugopaulissen@...> wrote:
                >
                > OK Don, Sorry Flo,
                >
                > Forget my last post; I see what you mean... Now I *do* remember the padding zero issue! It's getting rusty inside...
                >
                > Hugo

                Hugo, Don,

                I don't think that Hugo was wrong. There has always been some confusion about this issue (cf message #19038 ff).

                The trick is the ^%NL% as delimiter. With the semicolon as the default delimiter the array won't get sorted:

                ^!SetArray %Array%=9;8;7;6;5
                ^!Info Array unsorted:^P^%Array%
                ^!SetArray %Array%=^$StrSort("^%Array%";0;1;0)$
                ^!Info Sorting failed: ^%Array%
                ^!Info Wrong minimum value: ^%Array1%

                The clip outputs '9' which doesn't meet our intentions. With ^P as delimiter it doesn't work either.

                With ^%NL% (which replaces the comma in Hugo's solution)...

                ^!SetListDelimiter ^%NL%
                ^!SetArray %Array%=9^%NL%8^%NL%7^%NL%6^%NL%5
                ^!Info Array unsorted:^P^%Array%
                ^!SetArray %Array%=^$StrSort("^%Array%";0;1;0)$
                ^!Info Array correctly sorted:^P^%Array%
                ^!Info Minimum value: ^%Array1%

                the array gets sorted and the clip outputs the minimum value in the array. Nevertheless, it's still a normal ANSI sorting of digits and no numeric sorting.

                Regards,
                Flo
              • Don - HtmlFixIt.com
                I am pretty sure you are just picking lucky numbers to use and thus getting lucky :-) I agree that you need the line breaks as delimiter because we are sorting
                Message 7 of 15 , Nov 2, 2009
                • 0 Attachment
                  I am pretty sure you are just picking lucky numbers to use and thus
                  getting lucky :-)

                  I agree that you need the line breaks as delimiter because we are
                  sorting lines, not data elements. But it will not do what you wanted,
                  give the minimum unless you zero pad. You can however add zero padding,
                  sort, strip and output if you wish.

                  I mistakenly did not include the correct numbers in my prior example.

                  :Mine
                  ^!SetListDelimiter ,
                  ^!SetArray %Array%=8,329,7,4,9,6,5
                  ^!SetListDelimiter ^%NL%
                  ^!SetArray
                  %Array%=^$StrSort("^$StrReplace(",";"^%NL%";"^%Array%";0;0)$";False;True;False)$
                  ^!Info ^%Array1% ^%NL% ^%Array%


                  :Flo
                  ^!SetListDelimiter ^%NL%
                  ^!SetArray %Array%=8^%NL%329^%NL%7^%NL%4^%NL%9^%NL%6^%NL%5
                  ^!Info Array unsorted:^P^%Array%
                  ^!SetArray %Array%=^$StrSort("^%Array%";0;1;0)$
                  ^!Info Array correctly sorted:^P^%Array%
                  ^!Info Minimum value: ^%Array1%

                  Notice I also used NL in my example because we figured that one out many
                  years ago -- look up my username and zero padding ....

                  329 comes out on top in the above examples because 3 is the lowest
                  number. Hugo and I have done the zero padding bit many times over the
                  years as I use his method for it.

                  flo.gehrke wrote:
                  > --- In ntb-clips@yahoogroups.com, Hugo Paulissen <hugopaulissen@...> wrote:
                  >> OK Don, Sorry Flo,
                  >>
                  >> Forget my last post; I see what you mean... Now I *do* remember the padding zero issue! It's getting rusty inside...
                  >>
                  >> Hugo
                  >
                  > Hugo, Don,
                  >
                  > I don't think that Hugo was wrong. There has always been some confusion about this issue (cf message #19038 ff).
                  >
                  > The trick is the ^%NL% as delimiter. With the semicolon as the default delimiter the array won't get sorted:
                • flo.gehrke
                  ... Don, ... Yes, Don, you are absolutely right. Now it was getting rusty inside for me ;-) I should have known better since I already said: Nevertheless,
                  Message 8 of 15 , Nov 2, 2009
                  • 0 Attachment
                    --- In ntb-clips@yahoogroups.com, "Don - HtmlFixIt.com" <don@...> wrote:
                    >
                    > I am pretty sure you are just picking lucky numbers to use and thus
                    > getting lucky :-)

                    Don,

                    > 329 comes out on top in the above examples because 3 is the
                    > lowest number.

                    Yes, Don, you are absolutely right. Now it was "getting rusty inside" for me ;-)

                    I should have known better since I already said: "Nevertheless, it's still a normal ANSI sorting of digits and no numeric sorting."

                    So a better numeric sorting remains on the wish list. Something like...

                    ^$StrSort("Str";Numeric;Ascending;RemoveDuplicates)$

                    (as you had in mind before). I hope Eric Fookes will read this...

                    Regards,
                    Flo
                  • Art Kocsis
                    I agree that NoteTab needs a numeric sort period, not just in the clip functions but in the editor itself. Under the assumption that the clip sort is a mirror
                    Message 9 of 15 , Nov 3, 2009
                    • 0 Attachment
                      I agree that NoteTab needs a numeric sort period, not just in the clip
                      functions but in the editor itself. Under the assumption that the clip sort
                      is a mirror of the editor sort you can easily see the results (and
                      fallacies), of all the arrays in this thread. Even zero padding is not an
                      answer:

                      Copy Hugo's last array to NTB, change all the commas to ^P and sort:
                      ^!SetArray %Array%=03,8,329,1,1.25,7,10.34,4,9,6,
                      2,5,11,0.25,0.1,10000,20,0.0119,10,0.012
                      Notice the "03" is less than "1", "11" is less than 2", and so on.

                      And while we're at it, NoteTab also sorely needs a major/minor column sort.
                      Jody's clip has never worked for me so I am left with going to Ultra Edit
                      for anything other than trivial column one sorts. The lack of column sorts
                      is a PITA and an unnecessary waste of time.

                      BTW, UE not only does the numeric sorts but preserved the leading zero
                      padding characters while correctly sorting the numeric values.

                      Art


                      At 02-11-2009 12:29, you wrote:
                      >--- In <mailto:ntb-clips%40yahoogroups.com>ntb-clips@yahoogroups.com, "Don
                      >- HtmlFixIt.com" <don@...> wrote:
                      > >
                      > > I am pretty sure you are just picking lucky numbers to use and thus
                      > > getting lucky :-)
                      >
                      >Don,
                      >
                      > > 329 comes out on top in the above examples because 3 is the
                      > > lowest number.
                      >
                      >Yes, Don, you are absolutely right. Now it was "getting rusty inside" for
                      >me ;-)
                      >
                      >I should have known better since I already said: "Nevertheless, it's still
                      >a normal ANSI sorting of digits and no numeric sorting."
                      >
                      >So a better numeric sorting remains on the wish list. Something like...
                      >
                      >^$StrSort("Str";Numeric;Ascending;RemoveDuplicates)$
                      >
                      >(as you had in mind before). I hope Eric Fookes will read this...
                      >
                      >Regards,
                      >Flo

                      ----------


                      No virus found in this outgoing message.
                      Checked by AVG - www.avg.com
                      Version: 8.5.424 / Virus Database: 270.14.47/2478 - Release Date: 11/03/09 07:36:00


                      [Non-text portions of this message have been removed]
                    Your message has been successfully submitted and would be delivered to recipients shortly.