Sobes.tech
Junior — Senior

Competitive ordered output of numbers with synchronization

livecode

Task condition

It is necessary to modify the provided code so that:

  • numbers from 1 to 10 are output in parallel using goroutines;
  • while maintaining strict output order (1, 2, 3, ..., 10);
  • a pause of one second is made between each number output (implemented by the showNumber function).
import (
        "fmt"
        "time"
        )

func main () {
    for cur := 1; cur < 11; cur++ {
        // TODO: launch a goroutine that calls showNumber(cur)
    }
}

func showNumber(val int) {
        time.Sleep(time.Second)
        fmt.Println(val)        
    }