At Wed, 16 Jun 2004 23:13:26 +0900, Ralf Mler wrote: > > ram@lilith:~/src/ruby$time ruby -e 'num=STDIN.gets; a=Array.new; (0..9).each > {|i| a[i] = 0}; (0..num.length).each {|i| a[num[i..i].to_i] += 1 }; > a.each_index {|i| print "#{i} #{a[i]}\n"} ' < pi.out # get the input num = STDIN.gets; # initialize array entries with 0 a = Array.new(255,0); # count the occurence of each byte in the input num.each_byte {|i| a[i] += 1}; # only interested in the byte/characters for 0-9 (?0..?9).each {|i| print "#{[i].pack("c")} #{a[i]}\n"}; I suspect the num[i..i].to_i is pretty expensive... and it's not really needed in this case. Cheers, Ruben