samedi 6 février 2016

Finding the most common pair, trio, etc. in a list of 20 random numbers, played 100 times

So I have a CSV with 100 rows, 20 numbers on each row separated with a comma as such:

23, 52, 63, 76, 23, 45, ...
39, 52, 83, 33, 35, 23, ...
etc.

I would like to write an algorithm that finds all the different combinations of a pair, and list the amount of times it has occurred, and do the same for a trio, for a quad, etc.

Obviously for each line there would be a lot of combinations (since order wouldn't matter)

This would be the answer for every line

enter image description here

So 15 combinations per line.. now I can only imagine how many there would be if it were 20 instead of 6, but let's not worry about that for now.

Since there are 15, I wouldn't want the program to show me every single combination, only those whose "count" is higher than 1, "count" being the number of times they have occurred.

So if I ran the program for just those two lines above, for 6 numbers instead of 20, the program would return

23, 52: 2

See how only the pair that occurred more than once is shown, that's what I'd like to do, but that would be easy, just not show if the count is equal to 1.

Anyway, how would I get started on creating this algorithm? I don't know where to start, I guess I would begin by scraping every line, and getting every pair, but how would I do this?

Thank you in advance, and no doubt I will keep hacking at this problem, if I find the solution I will post it (as well as the code). Thank you again.




Aucun commentaire:

Enregistrer un commentaire