#### Archived

This topic is now archived and is closed to further replies.

# common numbers

This topic is 6018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How would I search a file to find the numbers that most commonly appear in said file? Thanks. -AJ C:\DOS C:\DOS\RUN RUN\DOS\RUN -Comic Book Store Guy''s t-shirt that I saw on the Simpsons, although it didn''t actually come from the Simpsons. http://vdsoft.netfirms.com/home.html

##### Share on other sites
How complex do you want to get, do you simply want to find the top 1/2/3 most frequent numbers in the file, or are you looking for statistical functions that will consider common ranges (for instance [1,2,3,4,5] will return 3 as the most common number). What size are the numbers (8bit, 16bit, 32bit, floating point?)

##### Share on other sites
You''re actually right on the nose, I want to be able to find the top 3 numbers found in a given file. And the numbers are just regular ints, I forgot what size those are though. Thanks.

-AJ

C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

-Comic Book Store Guy''s t-shirt that I saw on the Simpsons, although it didn''t actually come from the Simpsons.

http://vdsoft.netfirms.com/home.html

##### Share on other sites
I''m working on something similiar at the moment. Perhaps something along the lines of the Distribution counting sort will work to solve your problem.

  Distribution Counting Sort - lends itself well to radix sortfor (j = 0; j <  M; j++) count[j] = 0;              // initialize the count arrayfor (i = 1; i <= N; i++) count[a[i]]++;             // tally frequencies for each value in the target arrayfor (j = 1; j <  M; j++) count[j] += count[j-1];    // accumulate the frequenciesfor (i = N; i >= 1; i--) b[count[a[i]]--] = a[i];   // transfer values to temp arrayfor (i = 1; i <= N; i++) a[i] = b[i];               // transfer values back to the target arraywhere b is a temporary array of N elementswhere M is a limit on the range of the values stored in athat is - the values stored in a range from 0 to M - 1in the fourth loop the accumulated freqency is used as an index into the temp arraybecause the accumulated value indicates the number of values less than the current valuethe accumulated value is decremented, because following the transfer, there is one lessvalue less than the current value. The loop descends in order to keep the sort stable.

##### Share on other sites
quote:
Original post by Michalson
for instance [1,2,3,4,5] will return 3 as the most common number

No it wont....
3 is the average, and the median....
the most common number(s) is/are 1, 2, 3, 4 and 5...

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013628
×