def char_freq(str)
      freqs = Hash.new(0)
      (1..4).each do |i|
        str.chars.each_cons(i).inject(freqs) do |freq, ngram|
          ngram = ngram.join
          freq[ngram] = freq[ngram] + 1
          freq
        end
      end
      freqs
    end
def char_freq(str)
      freqs = Hash.new(0)
      (1..4).each do |i|
        str.chars.each_cons(i).inject(freqs) do |freq, ngram|
          ngram = ngram.join
          freq[ngram] = freq[ngram] + 1
          freq
        end
      end
      freqs
    end
Computes a hash of each character