Need custom sorting algorithm - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: Need custom sorting algorithm (/showthread.php?tid=2154) Pages:
1
2
|
RE: Need custom sorting algorithm - bplus - 11-14-2023 This is crazy to order the columns most simialr to all the other columns??? You can only compare all the other columns to one of the columns for a proper compare of matches. Otherwise a column thats all *'s will match perfectly any other column with random *'s if that's what you really want then order the columns by most *'s RE: Need custom sorting algorithm - SMcNeill - 11-14-2023 (11-14-2023, 09:54 AM)bplus Wrote: This is crazy to order the columns most simialr to all the other columns??? Not really, I don't think. Take a look at this example: x---- x---- x---- x---- -xxxx Now the first column has 4 stars, but it doesn't match any of the other columns. The other columns only have 1 star, but they all match in the same row. I'm thinking that it might be the 4 columns that we're looking for here, rather than the 1 column with all the stars? RE: Need custom sorting algorithm - RhoSigma - 11-14-2023 (11-14-2023, 10:35 AM)SMcNeill Wrote:(11-14-2023, 09:54 AM)bplus Wrote: This is crazy to order the columns most simialr to all the other columns??? I not really followed this, but it seems like a normal binary number sort to me, instead of *--**-**, think of it as 10011011. That's a number and can be perfectly sorted with other numbers (similar bit patterns). RE: Need custom sorting algorithm - SMcNeill - 11-14-2023 (11-14-2023, 01:34 PM)RhoSigma Wrote:(11-14-2023, 10:35 AM)SMcNeill Wrote:(11-14-2023, 09:54 AM)bplus Wrote: This is crazy to order the columns most simialr to all the other columns??? I don't think it's quite that simple either, Rho. Think of this set of data: x---- x---- x---- x---- -xxxx ---xx Now, if you just look at going down, column 1 has the most matches. If you just look going right, row 4 has the most matches. I think what he's looking for here is columns 4 and 5, which each have 2 stars matching between them. The only way I see to get this is basically just as bplus said: "You can only compare all the other columns to one of the columns for a proper compare of matches." The trick is you just have to do a loop to compare ALL of those columns 1 by 1, against all of the other columns, and then shuffle the results of those matches. RE: Need custom sorting algorithm - bplus - 11-14-2023 I tried Rho's idea of just sorting the columns as strings (same as sorting binary numbers) but that IS too simple. I suppose you could take each column and compare BOTH *'s and -"s to every other column and tally up the matched chars and I suppose it is possible that some will have higher matches than others. Come to think of it, when you compare two columns and count matches, you never have to compare those 2 columns again, nothing changes they both have same amount of matches. So for i= 1 to columns-1 for j = i +1 to columns 'compare 'tally matches for column i AND column j next next then sort by matches This would how I setup a random data set: Code: (Select All) Const columns = 65, rows = 21 I'd be more motivated to finish code if @random1 or anyone can reveal to me a practical purpose to this. It'd probably make it easier to code or find a better appraoches for the practical problem. RE: Need custom sorting algorithm - bplus - 11-15-2023 Finally got it, took forever to get the results printed out in columns on the default screen. I did that matches as I explained in previous reply, comparing each column to every other one and counting up the matches. Here is a screen shot of matching one column with another yellow is a match, blue is a miss: Here is code: Code: (Select All) Const columns = 65, rows = 21 ' this is based on OP's screen shot Here is the results with increasing matches going down and to the right. The big number on left the match count the number on right the column number: I even printed the results into a txt file just to make sure they were ordered correctly while I fiddled around trying to get the results listed right on the default screen: Code: (Select All) 629 37 |