Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need custom sorting algorithm
#9
(11-12-2023, 06:43 AM)SMcNeill Wrote:
Code: (Select All)
CONST columns = 20, rows = 10

DIM a(1 TO rows) AS STRING
FOR i = 1 TO rows
    FOR j = 1 TO columns
        IF INT(RND * 2) THEN a(i) = a(i) + "*" ELSE a(i) = a(i) + "-"
    NEXT
    PRINT a(i)
NEXT

DIM matches(columns)

FOR i = 1 TO rows
    FOR j = 1 TO columns
        IF MID$(a(i), j, 1) = "*" THEN matches(j) = matches(j) + 1
    NEXT
NEXT

FOR i = 1 TO columns '
    PRINT _TRIM$(STR$(matches(i)));
NEXT

PRINT
PRINT "SORTED BY MOST MATCHES:"
FOR count = columns TO 1 STEP -1
    print_label = 0
    FOR j = 1 TO columns
        IF matches(j) = count THEN
            IF print_label = 0 THEN PRINT count; " MATCHES:";: print_label = -1
            PRINT j;
        END IF
    NEXT
    IF print_label THEN PRINT
NEXT

As so.  (I decided to go in and finish the little routine here for you.)  Wink

Thanks, this fits the bill, missed it in my earlier post.
Reply


Messages In This Thread
Need custom sorting algorithm - by random1 - 11-12-2023, 05:07 AM
RE: Need custom sorting algorithm - by SMcNeill - 11-12-2023, 06:33 AM
RE: Need custom sorting algorithm - by random1 - 11-13-2023, 11:04 AM
RE: Need custom sorting algorithm - by SMcNeill - 11-12-2023, 06:43 AM
RE: Need custom sorting algorithm - by random1 - 11-13-2023, 12:59 PM
RE: Need custom sorting algorithm - by SMcNeill - 11-12-2023, 06:05 PM
RE: Need custom sorting algorithm - by RhoSigma - 11-12-2023, 06:11 PM
RE: Need custom sorting algorithm - by random1 - 11-14-2023, 08:59 AM
RE: Need custom sorting algorithm - by bplus - 11-14-2023, 09:54 AM
RE: Need custom sorting algorithm - by SMcNeill - 11-14-2023, 10:35 AM
RE: Need custom sorting algorithm - by RhoSigma - 11-14-2023, 01:34 PM
RE: Need custom sorting algorithm - by SMcNeill - 11-14-2023, 04:35 PM
RE: Need custom sorting algorithm - by bplus - 11-14-2023, 06:07 PM
RE: Need custom sorting algorithm - by bplus - 11-15-2023, 02:51 AM



Users browsing this thread: 1 Guest(s)