Help, i am studying go language at university

hello i’m studying go language, i was doing this exercise: Definition: The compressed encoding of a character string is defined by a sequence of pairs of values ch n, where ch represents a character, while n> 0 is the number of times that the ch character is repeated.

Example: The string eeeaaaa corresponds to the sequence of values e 3 to 4, that is the character ‘e’, repeated 3 times, followed by the character ‘a’, repeated 4 times.

Write a program that reads the compressed encoding of a character string from the command line and prints the uncompressed string on the screen.

Assume that each character given in input belongs to the English alphabet and is therefore encoded within the US-ASCII standard (integrated into the Unicode standard).

Also assume that the sequence of values specified on the command line is in the correct format and includes at least one pair ch n.

but when i run the program using the values a3 b1, the result is: aaaabababababababababababababababababababababababababababababababababababababababababababababababababab

package main

import (


func main (){

  c := os.Args[1:]
  char := ""
  var n, j int

  for _, cazz := range c {

      r := []rune(cazz)

      for _, dio := range r{

        if unicode.IsLetter(dio){

          char += string(dio)

        } else if unicode.IsNumber(dio){

            n += int(dio)
            j = n - 48
            anubi := strings.Repeat(char, j)

           /*anubi := strings.Repeat(char, j)



i think it takes a for loop inside the else if unicode.IsNumber

You are not clearing variables “char” and “n” after print the sequence,

char = ""
n = 0
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.