Перейти к содержимому

Uzum - 1

func main() {
s:="test "
println(s[0])
s[0] = 'A'
println(s)
}
func main() {
a := make(chan int, 1)
for i := 0; i < 5; i++ {
select {
case <-a:
fmt.Println(i)
case a <- i:
fmt.Println(i)
}
}
}
func main() {
var arr = []int{1, 2, 3, 4, 5}
for i := range arr {
defer fmt.Printf("%d ", arr[i])
}
}

And this way?

Explain why and why the output differs before and after Go v1.22. How to fix it if Go <v1.22.

func main() {
slice := []string{"A ", "B ", "C "}
addElem(slice[1:2], "X ")
fmt.Println(slice)
}
func addElem(slice []string, elem string) {
slice = append(slice, elem)
}
func main() {
m := map[string]int{
"a ": 1,
"b ": 2,
"c ": 3,
"d ": 4,
}
for k, v := range m {
fmt.Printf("Key: %s, Value: %d\n ", k, v)
}
for k, v := range m {
fmt.Printf("Key: %s, Value: %d\n ", k, v)
}
}
  • Live coding task: Implement a function that multiplexes channels and returns a result channel without waiting for them to merge. go/channels
// fan in / channel multiplexer / channel merge
// takes all values from all input channels and writes them to the result channel
// the pointer to the result channel must be obtained immediately
// after all input channels close - the result channel must also be closed
func merge(chans ...chan int) chan int {
// write here
}

System design: design the architecture of a population census system for China.