common numbers

Started by
3 comments, last by redneckCoder 21 years, 10 months ago
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
C:DOSC:DOSRUNRUNDOSRUN-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
Advertisement
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?)
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
C:DOSC:DOSRUNRUNDOSRUN-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
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.  
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
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...
Don't Temp Fate..

This topic is closed to new replies.

Advertisement