A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Was that page serious? Did someone really publish that algorithm? I didn't want to pull up the PDF and read the sordid history of its publication, but if you know, please do tell.Originally posted by Stan James:
BTW: For graduate level CS work, there is an algorithm that will find the number with the most occurrences in one pass. Don't turn THIS in as homework!
Was that page serious? Did someone really publish that algorithm? I didn't want to pull up the PDF and read the sordid history of its publication, but if you know, please do tell.
Ohhhh, okay. Yes, I wasn't paying close enough attention and assumed it was about the one with the largest number of occurances. Thanks for clarifying.Originally posted by Horatio Westock:
I think the confusion is that it doesn't find the item with the highest number of occurances, it finds the majority item.
Note that this code assumes that getFaceNumber() returns a value in [0,5] instead of [1,6]. I haven't read the rest of the code, so it may do that, but just make sure you match them up correctly.Originally posted by Horatio Westock:
Originally posted by David Harkness:
<hr></blockquote>Note that this code assumes that getFaceNumber() returns a value in [0,5] instead of [1,6]. I haven't read the rest of the code, so it may do that, but just make sure you match them up correctly.
Originally posted by Andy Rayner:
tempDice.getFaceNumber() returns 1-6 and the variable dices is an array, when i dice is created this is what happens
i put in the code you said and got quite an unusual result, it only looked at the first 5 dice not all 6 of them and i got this result
There were 7 0s
There were 4 1s
There were 2 2s
There were 4 3s
on a line which had 6 3 1 3 2 3
I think the confusion is that it doesn't find the item with the highest number of occurances, it finds the majority
Note that if you replaced the first C with an A, above, the algorithm would still end with C being chosen, but in fact C would not be the majority element: there is no majority in the modified list.
In some situations you know, or assume, there is a majority element.
But if you must confirm that the chosen element is indeed the majority element, you must take one more linear pass through the data to do it.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|