Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created September 20, 2012 04:52
Show Gist options
  • Save arn-e/3754037 to your computer and use it in GitHub Desktop.
Save arn-e/3754037 to your computer and use it in GitHub Desktop.
frequency analysis first char
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