orignal=gets.chomp.split("") str = "" orignal.reverse.each_with_index do |c, index| str += c str += "," if ((index+1)%3==0) end str.reverse! puts str[0] == "," ? str[1...str.size] : str