I am trying to make a Ruby program that counts the number of times two letters appear together. This is what is written in the file I am reading:
hola chau
And here is what I am trying to get:
ho;ol;la;ch;ha;au; 1;1;1;1;1;1;
I can not get it to work correctly. This is my code:
file = File.read(gets.chomp) todo = file.scan(/[az][az]/).each_with_object(Hash.new(0)) { |a, b| b[a] += 1 } keys = '' values = '' todo.each_key { |key| keys += key + ';' } todo.each_value { |value| values += value.to_s + ';' } puts keys puts values
This is the result I get:
ho;la;ch;au; 1;1;1;1;
Why am I not getting every combination of characters? What should I advertise for my regular expression so that it takes into account each combination of characters?
source share