Unidirectional channel

Report a typo

Your friend Evan is exploring unidirectional channels with you. And he decided to ask you to solve a problem.

In one goroutine, data is sent to the channel, and in the other, data is received from the channel and displayed on the screen.

Evan has already prepared some functions which read the length of data from stdin and generate a data set. Also, he made templates for functions mysteryOne and mysteryTwo. One of them should send data and the other should receive data.

Complete these functions based on directions of arguments channels. In receiver function use fmt.Print() to output numbers without any spaces. In sender function, close the channel.

To make the task more difficult, Evan passes data as an argument to both functions. But this argument is needed only in the sender. Just leave it as it is.

Sample Input 1:

10

Sample Output 1:

4879849558
Write a program in Go
package main

import (
"fmt"
"math/rand"
"time"
)

// complete these functions
func mysteryOne(data []int, ch <-chan int) {
for ? := range ? {
?
}
}

func mysteryTwo(data []int, ch chan<- int) {
for ? := range ? {
?
}
}

// DO NOT modify the code below!
func main() {
_ = rand.Int() // DO NOT delete this `rand.Int()` line!

var length int
fmt.Scanln(&length)
numbers := randomizer(length)
ch := make(chan int)

go mysteryOne(numbers, ch)
go mysteryTwo(numbers, ch)

time.Sleep(time.Second)
}
___

Create a free account to access the full topic