Skip to content

Instantly share code, notes, and snippets.

@arn-e
Created September 20, 2012 04:18
Show Gist options
  • Save arn-e/3753957 to your computer and use it in GitHub Desktop.
Save arn-e/3753957 to your computer and use it in GitHub Desktop.
character analysis 1
def freq_analysis(msg)
freq,msg_arr,sum = Hash.new(0),msg.split(''),0
msg_arr.each_with_index {|i,j| msg_arr.delete_at(j) if i == " "}.each {|i| freq[i],sum = freq[i] + 1,sum +1}
return freq.each {|a,b| 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