Send/receive problem

Report a typo

Your friend Harry is already actively using channels in his programs. To support you, he decided to ask you a problem on the direction of the channels.

His program welcomes anyone who enters a name. Harry wrote all the code, but hid the type of channels accepted by the receiver() and sender() functions. Your task is to record the correct type of channels.

The difficulty is that you need to pass a receive-only channel to the receiver function, and send-only to the sender. Harry wrote additional functions isCommon() that will crash the program if you use a bidirectional channel.

You don't need to know how isCommon() function works inside. It simply checks if the channel is bidirectional or not.

Sample Input 1:

Marry

Sample Output 1:

Hello, Marry
Write a program in Go
package main

import (
"fmt"
"time"
)

const Hello = "Hello, "

// fix the function argument
func receiver(ch ?) {
if isCommon(ch) {
fmt.Println("cheating detected!")
return
}

for val := range ch {
fmt.Print(val)
}
}

// fix the function argument
func sender(name string, ch ?) {
if isCommon(ch) {
fmt.Println("cheating detected!")
return
}

ch <- Hello
ch <- name
close(ch)
}

// DO NOT change yhe code bellow
func main() {
var name string
___

Create a free account to access the full topic