QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Pete on September 22, 2020, 07:10:14 pm

Title: I can't decide which I like best...
Post by: Pete on September 22, 2020, 07:10:14 pm
I actually kept two ways of determining running accounts of instances of phone numbers in one of my database programs. I seldom if never do that, but I couldn't decide which one I liked the best, so I used each one in two separate parts of the program. Any thoughts of one being better than the other, or maybe another method?

Code: QB64: [Select]
  1. WIDTH 144, 25
  2.     READ mydata$
  3.     IF mydata$ = "EOF" THEN EXIT DO
  4.     j = 1: occ% = 0
  5.     dataconcat$ = mydata$ + "|" + dataconcat$
  6.     DO UNTIL j > LEN(dataconcat$)
  7.         IF INSTR(j, dataconcat$, mydata$ + "|") - j = 0 THEN occ% = occ% + 1
  8.         j = INSTR(j, dataconcat$, "|") + 1
  9.     LOOP
  10.     PRINT mydata$; "#"; LTRIM$(STR$(occ%)); ", ";
  11. dataconcat$ = ""
  12. PRINT "End Method #1."
  13.  
  14.  
  15.     READ mydata$
  16.     IF mydata$ = "EOF" THEN EXIT DO
  17.     j = 0: occ% = 0
  18.     dataconcat$ = mydata$ + "|" + dataconcat$
  19.     DO UNTIL j > LEN(dataconcat$)
  20.         k = INSTR(j, dataconcat$, "|") - j
  21.         IF MID$(dataconcat$, j, k) = mydata$ THEN occ% = occ% + 1
  22.         j = j + k + 1
  23.     LOOP
  24.     PRINT mydata$; "#"; LTRIM$(STR$(occ%)); ", ";
  25. dataconcat$ = ""
  26. PRINT "End Method #2."
  27.  
  28. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog

Pete
Title: Re: I can't decide which I like best...
Post by: bplus on September 22, 2020, 07:34:48 pm
Do you like alphabetic order?

loadsort demo:
Code: QB64: [Select]
  1. REDIM dat$(0)
  2.     READ insert$
  3.     IF insert$ <> "EOD" THEN loadSort insert$, dat$() ELSE EXIT DO
  4. FOR i = LBOUND(dat$) TO UBOUND(dat$)
  5.     IF dat$(i) <> "" THEN
  6.         PRINT dat$(i)
  7.         IF concat$ = "" THEN concat$ = dat$(i) ELSE concat$ = concat$ + ", " + dat$(i)
  8.     END IF
  9. PRINT: PRINT concat$
  10.  
  11. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog,EOD
  12.  
  13. SUB loadSort (insertN AS STRING, dynArr() AS STRING) '  version 2020-06-07
  14.     'note this leaves dynArr(0) empty! so ubound of array is also number of items in list
  15.     DIM ub, j, k
  16.     ub = UBOUND(dynArr) + 1
  17.     REDIM _PRESERVE dynArr(LBOUND(dynArr) TO ub) AS STRING
  18.     FOR j = 1 TO ub - 1
  19.         IF insertN < dynArr(j) THEN '  GT to LT according to descending or ascending sort
  20.             FOR k = ub TO j + 1 STEP -1
  21.                 dynArr(k) = dynArr(k - 1)
  22.             NEXT
  23.             EXIT FOR
  24.         END IF
  25.     NEXT
  26.     dynArr(j) = insertN
  27.  
  28.  

with animal counts:
Code: QB64: [Select]
  1. REDIM dat$(0)
  2.     READ insert$
  3.     IF insert$ <> "EOD" THEN loadSort insert$, dat$() ELSE EXIT DO
  4. FOR i = LBOUND(dat$) TO UBOUND(dat$)
  5.     IF dat$(i) <> "" THEN
  6.         PRINT dat$(i)
  7.         IF concat$ = "" THEN
  8.             lastWord$ = dat$(i)
  9.             cntWord = 1
  10.             concat$ = dat$(i) + "#" + _TRIM$(STR$(cntWord))
  11.         ELSE
  12.             IF dat$(i) = lastWord$ THEN cntWord = cntWord + 1 ELSE cntWord = 1: lastWord$ = dat$(i)
  13.             concat$ = concat$ + ", " + dat$(i) + "#" + _TRIM$(STR$(cntWord))
  14.         END IF
  15.     END IF
  16. PRINT: PRINT concat$
  17.  
  18. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog,EOD
  19.  
  20. SUB loadSort (insertN AS STRING, dynArr() AS STRING) '  version 2020-06-07
  21.     'note this leaves dynArr(0) empty! so ubound of array is also number of items in list
  22.     DIM ub, j, k
  23.     ub = UBOUND(dynArr) + 1
  24.     REDIM _PRESERVE dynArr(LBOUND(dynArr) TO ub) AS STRING
  25.     FOR j = 1 TO ub - 1
  26.         IF insertN < dynArr(j) THEN '  GT to LT according to descending or ascending sort
  27.             FOR k = ub TO j + 1 STEP -1
  28.                 dynArr(k) = dynArr(k - 1)
  29.             NEXT
  30.             EXIT FOR
  31.         END IF
  32.     NEXT
  33.     dynArr(j) = insertN
  34.  
  35.  
Title: Re: I can't decide which I like best...
Post by: Pete on September 22, 2020, 08:16:27 pm
Nice, Mark.

My way to add an array and place the results in alphabetical order would be as follows...

Code: QB64: [Select]
  1. WIDTH 144, 25
  2. j = 0
  3.     READ mydata$
  4.     IF mydata$ = "EOF" THEN EXIT DO
  5.     j = j + 1
  6. DIM myarray$(j)
  7.  
  8.     READ mydata$
  9.     IF mydata$ = "EOF" THEN EXIT DO
  10.     j = 1: occ% = 0: h = h + 1
  11.     dataconcat$ = mydata$ + "|" + dataconcat$
  12.     DO UNTIL j > LEN(dataconcat$)
  13.         IF INSTR(j, dataconcat$, mydata$ + "|") - j = 0 THEN occ% = occ% + 1
  14.         j = INSTR(j, dataconcat$, "|") + 1
  15.     LOOP
  16.     myarray$(h) = mydata$ + "#" + LTRIM$(STR$(occ%))
  17. dataconcat$ = ""
  18. FOR i = 1 TO h
  19.     FOR j = 1 TO h
  20.         IF i <> j THEN
  21.             IF myarray$(i) < myarray$(j) THEN SWAP myarray$(i), myarray$(j)
  22.         END IF
  23. NEXT j, i
  24. FOR i = 1 TO h
  25.     PRINT myarray$(i); ", ";
  26. PRINT "End Method #1."
  27.  
  28. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog
  29.  

Pete
Title: Re: I can't decide which I like best...
Post by: SpriggsySpriggs on September 22, 2020, 08:18:14 pm
I'd use PowerShell to sort the data :)
https://stackoverflow.com/questions/32385611/sort-very-large-text-file-in-powershell (https://stackoverflow.com/questions/32385611/sort-very-large-text-file-in-powershell)
Title: Re: I can't decide which I like best...
Post by: bplus on September 22, 2020, 08:23:34 pm
Hi Pete,

Line 5 is out of data even when I add the data line?

Never mind, you are looking for EOF, my End Of Data is EOD
Title: Re: I can't decide which I like best...
Post by: bplus on September 22, 2020, 08:24:17 pm
I'd use PowerShell to sort the data :)
https://stackoverflow.com/questions/32385611/sort-very-large-text-file-in-powershell (https://stackoverflow.com/questions/32385611/sort-very-large-text-file-in-powershell)

But powershell can't load the data from a bas file.


I'd use qsort for a more serious array size, something more than Pete's Ark.
Title: Re: I can't decide which I like best...
Post by: Pete on September 22, 2020, 08:27:04 pm
PowerShell? Where's the fun in that? You'd probably use a rifle to hunt deer, too. Sigh. Just do what I do. Run them down and tear them apart with your bare hands. So you take a few hoof kicks to the head, so what? So you take a few hoof kicks to the head, so what? So you take a few hoof kicks to the head, so what?

Pete
Title: Re: I can't decide which I like best...
Post by: STxAxTIC on September 22, 2020, 08:32:06 pm
This response made me genuinely LOL.
Title: Re: I can't decide which I like best...
Post by: Pete on September 22, 2020, 08:33:38 pm
Hi Pete,

Line 5 is out of data even when I add the data line?

Never mind, you are looking for EOF, my End Of Data is EOD

I've always used EOF from 20 years back, as: "End of File"  I like EOD, though. Anyway, you must have cut and pasted my code just before I edited in the data!


@Bill: Glad you liked it. Glad you liked it. Glad you liked it.

Pete
Title: Re: I can't decide which I like best...
Post by: bplus on September 22, 2020, 08:49:18 pm
It's difficult to see a great difference between Method#1 and Method#2 but it's interesting you chose Method#1 for the sort demo.
Title: Re: I can't decide which I like best...
Post by: Pete on September 22, 2020, 09:03:59 pm
I chose #1, because I thought it was a bit cleaner of an approach, but I also liked #2, because it used MID$() to chop away at the concatenated string. My guess is with any code, it all comes down to which would perform the fastest in a speed test, maybe matched with the elegance of the code, itself. Still, if there was a bathing suit contest, I'd be more prone to watch.

Pete
Title: Re: I can't decide which I like best...
Post by: bplus on September 22, 2020, 10:03:30 pm
I kinda like #1 because no extra variable k.

Are you going to try a speed test?
Title: Re: I can't decide which I like best...
Post by: Pete on September 22, 2020, 10:19:41 pm
Not on my computers. Long gone are the days where I used to have state of the art systems. Right now, it mostly depends on what the OS is up to, how my programs respond. I've noticed with some of the speed tests we did around here in the past, my results were way to inconsistent to be of any use. Since I'm not a gamer, it doesn't bother me in the least but I do get a kick out of the responsiveness in high end systems. I mean from my days of coding with a tape recorder as a drive, and 4K of memory, we've come a long way.

Yeah, I liked being rid of that "k" as well.

Pete
Title: Re: I can't decide which I like best...
Post by: bplus on September 22, 2020, 10:22:23 pm
Make sure I am around when you try the swimsuit contest :)
Title: Re: I can't decide which I like best...
Post by: Pete on September 22, 2020, 11:16:22 pm
'K.
Title: Re: I can't decide which I like best...
Post by: bplus on September 23, 2020, 12:10:39 am
From reply #2
Code: QB64: [Select]
  1. WIDTH 144, 25
  2. j = 0
  3.     READ mydata$
  4.     IF mydata$ = "EOF" THEN EXIT DO
  5.     j = j + 1
  6. DIM myarray$(j)
  7.  
  8.     READ mydata$
  9.     IF mydata$ = "EOF" THEN EXIT DO
  10.     j = 1: occ% = 0: h = h + 1
  11.     dataconcat$ = mydata$ + "|" + dataconcat$
  12.     DO UNTIL j > LEN(dataconcat$)
  13.         IF INSTR(j, dataconcat$, mydata$ + "|") - j = 0 THEN occ% = occ% + 1
  14.         j = INSTR(j, dataconcat$, "|") + 1
  15.     LOOP
  16.     myarray$(h) = mydata$ + "#" + LTRIM$(STR$(occ%))
  17. dataconcat$ = ""
  18. FOR i = 1 TO h
  19.     FOR j = 1 TO h
  20.         IF i <> j THEN
  21.             IF myarray$(i) < myarray$(j) THEN SWAP myarray$(i), myarray$(j)
  22.         END IF
  23. NEXT j, i
  24. FOR i = 1 TO h
  25.     PRINT myarray$(i); ", ";
  26. PRINT "End Method #1."
  27.  
  28. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog
  29.  

Trimmed reply #2 down a bit:
Code: QB64: [Select]
  1. DIM myarray$(1 TO 1000) ' some over the top number to avoid counting and then DIM
  2.     READ mydata$
  3.     IF mydata$ = "EOF" THEN EXIT DO
  4.     nItems = nItems + 1: myarray$(nItems) = mydata$
  5. FOR i = 1 TO nItems - 1 'nice sort routine, does this always work?
  6.     FOR j = i + 1 TO nItems
  7.         IF myarray$(i) > myarray$(j) THEN SWAP myarray$(i), myarray$(j)
  8. NEXT j, i
  9. FOR i = 1 TO nItems ' if we really must number the animals
  10.     IF i = 1 THEN
  11.         lastWord$ = myarray$(i): cnt = 1
  12.     ELSE
  13.         IF myarray$(i) = lastWord$ THEN cnt = cnt + 1 ELSE cnt = 1: lastWord$ = myarray$(i)
  14.     END IF
  15.     myarray$(i) = lastWord$ + "#" + _TRIM$(STR$(cnt))
  16.     IF i = nItems THEN PRINT myarray$(i) ELSE PRINT myarray$(i); ", ";
  17. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog,EOF
  18.  

I modified your sort routine, man that is short and sweet! Does it always work?
Title: Re: I can't decide which I like best...
Post by: bplus on September 23, 2020, 12:31:31 am
Looks cute:
Code: QB64: [Select]
  1. DIM b(1 TO 480) 'lilSort test b+ 2020-09-23
  2.     nItems = INT(RND * (480)) + 1
  3.     FOR i = 1 TO nItems
  4.         b(i) = INT(RND * 100)
  5.     NEXT
  6.     lilSort b(), nItems
  7.     FOR i = 1 TO nItems
  8.         PRINT b(i);
  9.     NEXT
  10.     SLEEP
  11.     CLS
  12.  
  13. SUB lilSort (arr(), topItem)
  14.     DIM i AS INTEGER, j AS INTEGER
  15.     FOR i = 1 TO topItem - 1
  16.         FOR j = i + 1 TO topItem
  17.             IF arr(i) > arr(j) THEN SWAP arr(i), arr(j)
  18.     NEXT j, i
  19.  
  20.  

In action, I suppose it is about the worst in efficiency:
Code: QB64: [Select]
  1. DIM b(1 TO 480) 'lilSort test b+ 2020-09-23
  2.     nItems = INT(RND * (480)) + 1
  3.     FOR i = 1 TO nItems
  4.         b(i) = INT(RND * 100)
  5.     NEXT
  6.     lilSort b(), nItems
  7.     CLS
  8.     FOR i = 1 TO nItems
  9.         PRINT b(i);
  10.     NEXT
  11.     _DISPLAY
  12.     SLEEP
  13.     CLS
  14.  
  15. SUB lilSort (arr(), topItem)
  16.     DIM i AS INTEGER, j AS INTEGER
  17.     FOR i = 1 TO topItem - 1
  18.         FOR j = i + 1 TO topItem
  19.             IF arr(i) > arr(j) THEN SWAP arr(i), arr(j)
  20.             GOSUB show
  21.             _LIMIT 800
  22.     NEXT j, i
  23.     EXIT SUB
  24.     show:
  25.     CLS
  26.     FOR k = 1 TO topItem
  27.         PRINT arr(k);
  28.     NEXT
  29.     _DISPLAY
  30.     RETURN
  31.  
  32.  
Title: Re: I can't decide which I like best...
Post by: SMcNeill on September 23, 2020, 01:46:59 am
Nice, Mark.

My way to add an array and place the results in alphabetical order would be as follows...

Code: QB64: [Select]
  1. WIDTH 144, 25
  2. j = 0
  3.     READ mydata$
  4.     IF mydata$ = "EOF" THEN EXIT DO
  5.     j = j + 1
  6. DIM myarray$(j)
  7.  
  8.     READ mydata$
  9.     IF mydata$ = "EOF" THEN EXIT DO
  10.     j = 1: occ% = 0: h = h + 1
  11.     dataconcat$ = mydata$ + "|" + dataconcat$
  12.     DO UNTIL j > LEN(dataconcat$)
  13.         IF INSTR(j, dataconcat$, mydata$ + "|") - j = 0 THEN occ% = occ% + 1
  14.         j = INSTR(j, dataconcat$, "|") + 1
  15.     LOOP
  16.     myarray$(h) = mydata$ + "#" + LTRIM$(STR$(occ%))
  17. dataconcat$ = ""
  18. FOR i = 1 TO h
  19.     FOR j = 1 TO h
  20.         IF i <> j THEN
  21.             IF myarray$(i) < myarray$(j) THEN SWAP myarray$(i), myarray$(j)
  22.         END IF
  23. NEXT j, i
  24. FOR i = 1 TO h
  25.     PRINT myarray$(i); ", ";
  26. PRINT "End Method #1."
  27.  
  28. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog
  29.  

Pete


Bubblesort??    AAAAARRRRRGGGHHHHHH!!!  My poor eyes!  My poor programmer’s sensibilities!!  Bubble sort is even worse coding practice than GOTO!!!

And the ABSOLUTE worst version of Bubblesort!  You didn’t even make the inner loop FOR j = i + 1 TO h...

I...  I feel faint!  Sorry guys...  I gotta go barf.  Somebody please teach Pete a decent sort algorithm!  CODEGUY, WE NEED YOU, QUICK!!!

Blaaaarrrrrggggghhhhhh...
Title: Re: I can't decide which I like best...
Post by: SpriggsySpriggs on September 23, 2020, 02:06:30 am
Here is my contribution which works quite nicely. When timed on my machine for sorting and rebuilding the array it took 0.31 seconds.

Code: QB64: [Select]
  1. _TITLE "Sort da list"
  2.     READ mydata$
  3.     IF mydata$ = "EOF" THEN EXIT DO
  4.     nItems = nItems + 1
  5.     REDIM _PRESERVE myarray$(nItems)
  6.     myarray$(nItems) = mydata$
  7.  
  8. OPEN "datatosort.txt" FOR OUTPUT AS #1
  9. FOR x = 1 TO UBOUND(myarray$)
  10.     PRINT #1, myarray$(x)
  11.  
  12. SHELL _HIDE "PowerShell Get-Content datatosort.txt | sort | Out-File sorteddata.txt -Encoding ASCII" 'regular sort
  13. 'SHELL _HIDE "PowerShell Get-Content datatosort.txt | sort | Get-Unique | Out-File sorteddata.txt -Encoding ASCII" 'sort with duplicates omitted
  14.  
  15. OPEN "sorteddata.txt" FOR BINARY AS #1
  16. FOR x = 1 TO UBOUND(myarray$)
  17.     IF NOT EOF(1) THEN
  18.         LINE INPUT #1, myarray$(x)
  19.         PRINT myarray$(x)
  20.     END IF
  21.  
  22. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog,EOF

  [ This attachment cannot be displayed inline in 'Print Page' view ]    [ This attachment cannot be displayed inline in 'Print Page' view ]  

Code: QB64: [Select]
  1. _TITLE "Sort da list"
  2. x# = TIMER(0.01)
  3. SHELL _HIDE "PowerShell Get-Content 9999words.txt | sort | Out-File sorteddata.txt -Encoding ASCII"
  4. 'SHELL _HIDE "PowerShell Get-Content 9999words.txt | sort | Get-Unique | Out-File sorteddata.txt -Encoding ASCII"
  5.  
  6. OPEN "sorteddata.txt" FOR BINARY AS #1
  7.     IF EOF(1) = 0 THEN
  8.         x = x + 1
  9.         REDIM _PRESERVE myarray$(x)
  10.         LINE INPUT #1, myarray$(x)
  11.     END IF
  12. y# = TIMER(0.01)
  13. PRINT y# - x#
The above code along with my attachment "9999words.txt" can be sorted in 0.77 seconds on my machine and if you want only unique you can get it in 0.56 seconds.
Title: Re: I can't decide which I like best...
Post by: Pete on September 23, 2020, 05:00:03 am
Bad salsa on Taco Tuesday again, Steve? I hope you recover in time for Pon Farr Friday, but in case you don't, check out my fruit sort at QBF sometime. Ah, the good ol' days. Anyway, the speed test isn't for the alphabetizing part, it is for determining which of the two methods of using MID$() or INSTR() work faster for determining duplicates during the concatenation process.

Oh dammit, I think I stepped in some...

Pete
Title: Re: I can't decide which I like best...
Post by: STxAxTIC on September 23, 2020, 09:12:55 am
I lolled at Steve's reaction to bubble sort. I felt myself being channeled from somewhere so I had to check the forums for flames, and sure enough... Haha
Title: Re: I can't decide which I like best...
Post by: bplus on September 23, 2020, 11:21:10 am
Come on guys, as Pete says you don't need a ballistic missile to kill a deer specially if you want to eat it after.

Remember this is for Pete's phone calls, you don't need the heavy artillery for a couple dozen items to sort.

.31 secs!!! Ha!

Check this out
Code: QB64: [Select]
  1. start = TIMER(.001)
  2. WIDTH 144, 25
  3. '_SCREENMOVE 0, 0  '<<< try the time commented and not commented out
  4. j = 0
  5.     READ mydata$
  6.     IF mydata$ = "EOF" THEN EXIT DO
  7.     j = j + 1
  8. DIM myarray$(j)
  9.  
  10.     READ mydata$
  11.     IF mydata$ = "EOF" THEN EXIT DO
  12.     j = 1: occ% = 0: h = h + 1
  13.     dataconcat$ = mydata$ + "|" + dataconcat$
  14.     DO UNTIL j > LEN(dataconcat$)
  15.         IF INSTR(j, dataconcat$, mydata$ + "|") - j = 0 THEN occ% = occ% + 1
  16.         j = INSTR(j, dataconcat$, "|") + 1
  17.     LOOP
  18.     myarray$(h) = mydata$ + "#" + LTRIM$(STR$(occ%))
  19. dataconcat$ = ""
  20. FOR i = 1 TO h
  21.     FOR j = 1 TO h
  22.         IF i <> j THEN
  23.             IF myarray$(i) < myarray$(j) THEN SWAP myarray$(i), myarray$(j)
  24.         END IF
  25. NEXT j, i
  26. FOR i = 1 TO h
  27.     PRINT myarray$(i); ", ";
  28. PRINT "End Method #1."
  29. PRINT "Time:"; TIMER(.001) - start
  30. DATA dog,cat,rabbit,frog,horse,dog,mouse,pig,cat,bat,cat,dog,bird,fish,cat,pig,dog
  31.  
  32.  
  33.  

Discovery: the line that takes the most time by far in this program is the _SCREENMOVE !!!

I don't think Pete even cares about the sorting, I brought in the subject because I thought it easier to # the animals after a sort.

BTW I have a version of fruit sort, cool!
Code: QB64: [Select]
  1. DEFINT A-Z
  2. numberOfFruits = 25
  3. DIM Basket$(10)
  4. FOR i = 1 TO numberOfFruits 'create fruits
  5.     Fruit = INT(RND * 9) + 1: f$ = RIGHT$(STR$(Fruit), LEN(STR$(Fruit)) - 1)
  6.     IF i <> numberOfFruits THEN PRINT f$; ", "; ELSE PRINT f$;
  7.     Basket$(Fruit) = Basket$(Fruit) + f$ + ", "
  8. FOR Nut = 1 TO 9
  9.     IF LEN(Basket$(Nut)) THEN
  10.         IF Nut <> 9 THEN PRINT Basket$(Nut); ELSE PRINT LEFT$(Basket$(Nut), LEN(Basket$(Nut)) - 2)
  11.     END IF
  12.  
  13.  
Title: Re: I can't decide which I like best...
Post by: SpriggsySpriggs on September 23, 2020, 12:00:17 pm
.31 secs!!! Ha!
@bplus That is because on smaller data sets, PowerShell will be slower. However, if you look at my updated reply, I can sort 9999 words in 0.77 seconds or 0.56 seconds if I omit duplicates. Try using my list of 9999 words and see how your algorithm does.
Title: Re: I can't decide which I like best...
Post by: bplus on September 23, 2020, 12:14:52 pm
@bplus That is because on smaller data sets, PowerShell will be slower. However, if you look at my updated reply, I can sort 9999 words in 0.77 seconds or 0.56 seconds if I omit duplicates. Try using my list of 9999 words and see how your algorithm does.

Sure 9999 words but then I would pull out Qsort and blow that time away and then you will say, "Wait let's try 999,999,999 words then Powershell will win! :-))

I am saying for a couple hundred words even the worst sort is better than jobbing out to Powereshell or whatever Hydrogen Bomb of the sorting world you want to bring in.
Title: Re: I can't decide which I like best...
Post by: Pete on September 23, 2020, 04:37:23 pm
That's why I stick with my patented Stupid Sort. It's the quickest, easiest sort code to remember and type into the IDE. I can place it in a program in under 30 seconds. It works plenty fast for most jobs where the lists to sort are 1000 items or less, but you guys probably thought I posted it just to make Steve puke. Nah, that's just a bonus!

Pete

 - If you're out of your mind, see a psychiatrist. If you're just out of sorts, see CodeGuy.
Title: Re: I can't decide which I like best...
Post by: SMcNeill on September 23, 2020, 06:38:04 pm
That's why I stick with my patented Stupid Sort. It's the quickest, easiest sort code to remember and type into the IDE. I can place it in a program in under 30 seconds. It works plenty fast for most jobs where the lists to sort are 1000 items or less, but you guys probably thought I posted it just to make Steve puke. Nah, that's just a bonus!

Pete

 - If you're out of your mind, see a psychiatrist. If you're just out of sorts, see CodeGuy.

That’s why I keep several sorts in my folder, and all I need do is either $INCLUDE them, or copy/paste them into my program.  It’s efficient program-wise, and even faster coding than typing a puke-sort is.  ;D