tbl = [4, 3, 3, 3, 4, 3, 4, 3, 5, 4] tbl.map!(&:pred) p gets.chomp.chars.map{|c| tbl[c.to_i] }.inject(0,:+) + 1