Created
September 20, 2012 04:52
-
-
Save arn-e/3754037 to your computer and use it in GitHub Desktop.
frequency analysis first char
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def freq_analysis_first(msg) | |
f_freq,msg_arr,sum = Hash.new(0),msg.split(' '),0 | |
msg_arr.each {|i| i.split('').each_with_index do |a,b| | |
f_freq[a], sum = f_freq[a] + 1, sum +1 if b == 0 | |
end} | |
return f_freq.each {|a,b| f_freq[a] = calc_perc(b,sum)}.sort_by {|i,j| j}.reverse | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment