S
SpringFlowers AutumnMoon
i found a description of Smalltalk in
http://www.engin.umd.umich.edu/CIS/course.des/cis400/smalltalk/freq.html
and then I tried it in Ruby:
h = Hash.new(0)
print "Enter line: "
gets.downcase.each_byte {|b| c = "%c" % b; h[c] += 1 if c =~ /[a-z]/}
p h.sort
C:\rails\depot>ruby count_alpha2.rb
Enter line: This is a test of the line count
[["a", 1], ["c", 1], ["e", 3], ["f", 1], ["h", 2], ["i", 3], ["l", 1],
["n", 2],
["o", 2], ["s", 3], ["t", 5], ["u", 1]]
I just wonder how would you write it? There is no each_char it seems,
unless with ActiveSupport.
http://www.engin.umd.umich.edu/CIS/course.des/cis400/smalltalk/freq.html
and then I tried it in Ruby:
h = Hash.new(0)
print "Enter line: "
gets.downcase.each_byte {|b| c = "%c" % b; h[c] += 1 if c =~ /[a-z]/}
p h.sort
C:\rails\depot>ruby count_alpha2.rb
Enter line: This is a test of the line count
[["a", 1], ["c", 1], ["e", 3], ["f", 1], ["h", 2], ["i", 3], ["l", 1],
["n", 2],
["o", 2], ["s", 3], ["t", 5], ["u", 1]]
I just wonder how would you write it? There is no each_char it seems,
unless with ActiveSupport.