+ 2

Go downloader

Currently I'm confused on the "Downloader" project in the Go course. I'm not sure if the project is just generally hard, or if I'm misunderstanding it. But I'm confused with getting the value to return from the `download()` function.

14th May 2021, 12:00 PM
Payton Coats
Payton Coats - avatar
13 Respostas
+ 4
Get the sum of range 0-N (inclusive) with the call of download(N). The sum should send to the channel passed in download. After 3 download() complete, output the sum of them. Example: download(4, ch1) makes ch1 have the value 6.
14th May 2021, 12:20 PM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar
+ 15
package main import "fmt" //define the download() function func download(s int, c chan int) { var sum int sum = 0 for i:=0; i<=s; i++ { sum += i } c<-sum } func main() { ch1 := make(chan int) ch2 := make(chan int) ch3 := make(chan int) var s1, s2, s3 int fmt.Scanln(&s1) fmt.Scanln(&s2) fmt.Scanln(&s3) go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) //output the sum of all results fmt.Println(<-ch2 + <-ch1 + <-ch3) }
13th Jun 2021, 6:16 AM
Fakhredin Gholamizadeh
Fakhredin Gholamizadeh - avatar
+ 1
Match Results any help guys plz ? You are making a program to analyze sport match results and calculate the points of the given team. The match results are stored in an array called results. Each match has one of the following results: "w" - won "l" - lost "d" - draw A win adds three points, a draw adds one point, and a lost match does not add any points. Your program needs to take the last match result as input and append it to the results array. After that, calculate and output the total points the team gained from the results package main import "fmt" func main() { results := []string{"w", "l", "w", "d", "w", "l", "l", "l", "d", "d", "w", "l", "w", "d"} }
16th Sep 2021, 2:03 PM
Mostafa Alafif
Mostafa Alafif - avatar
+ 1
package main import "fmt" //define the download() function func download(file_size int, chanel chan int) { chanel <- (file_size * (file_size + 1)) / 2 } func main() { ch1 := make(chan int) ch2 := make(chan int) ch3 := make(chan int) var s1, s2, s3 int fmt.Scanln(&s1) fmt.Scanln(&s2) fmt.Scanln(&s3) go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) //output the sum of all results fmt.Println(<-ch1 + <-ch2 + <-ch3) }
11th Sep 2022, 1:34 PM
đŸ–„ïžCatana Raul Andrei đŸ’»đŸ€–
đŸ–„ïžCatana Raul Andrei đŸ’»đŸ€– - avatar
+ 1
package main import "fmt" //define the download() function func download(s int, ch chan int){ var som int for i:=0; i<=s; i++{ som+=i } ch<-som } func main() { ch1 := make(chan int) ch2 := make(chan int) ch3 := make(chan int) var s1, s2, s3 int fmt.Scanln(&s1) fmt.Scanln(&s2) fmt.Scanln(&s3) go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) //output the sum of all results fmt.Println(<-ch1 + <-ch2 + <-ch3) }
7th Dec 2022, 6:24 PM
Samba Sy
Samba Sy - avatar
0
CarrielForle : I still do not understand...
25th May 2021, 6:26 PM
VĂĄclav DostĂĄl
VĂĄclav DostĂĄl - avatar
0
Yo, I am also stuck here; Pls send the code and it's logic because if we don't no the logic we can't ever solve it.
26th May 2021, 2:55 PM
Krish Rathor
Krish Rathor - avatar
0
Thanks bro
27th May 2021, 2:00 AM
Krish Rathor
Krish Rathor - avatar
0
if u dont understant , that s gonna clarify things to you we wait for the ch1 and ch2 and ch3 to be completed so that printline can be executed
21st Jun 2021, 3:53 AM
Rgr Nacer
Rgr Nacer - avatar
0
there is no need to write a loop for the sum of all integers from 0 to "s", it a triangular number which means we can use its formula to calculate the value without a loop, like ``` package main import "fmt" //define the download() function func main() { ch1 := make(chan int) ch2 := make(chan int) ch3 := make(chan int) var s1, s2, s3 int fmt.Scanln(&s1) fmt.Scanln(&s2) fmt.Scanln(&s3) go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) //output the sum of all results fmt.Println(<-ch1 + <-ch2 + <-ch3) } func download(i int, ch chan int){ ch <- (i * (i + 1)) /2 } ```
6th Jan 2022, 5:09 PM
Otto
Otto  - avatar
0
package main import "fmt" //define the download() function func download(s int, c chan int) { var sum int sum = 0 for i:=0; i<=s; i++ { sum += i } c<-sum } func main() { ch1 := make(chan int) ch2 := make(chan int) ch3 := make(chan int) var s1, s2, s3 int fmt.Scanln(&s1) fmt.Scanln(&s2) fmt.Scanln(&s3) go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) //output the sum of all results fmt.Println(<-ch2 + <-ch1 + <-ch3) }
18th Sep 2022, 7:00 AM
Kanisak Shakya
Kanisak Shakya - avatar
- 1
package main import "fmt" //define the download() function func download(s int, c chan int) { var sum int for i:=0; i<=s; i++ { sum += i } c<-sum } func main() { ch1 := make(chan int) ch2 := make(chan int) ch3 := make(chan int) var s1, s2, s3 int fmt.Scanln(&s1) fmt.Scanln(&s2) fmt.Scanln(&s3) go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) //output the sum of all results fmt. Println(<-ch2 + <-ch1 + <-ch3) }
28th Jun 2021, 4:08 AM
Jorge RodrĂ­guez
Jorge RodrĂ­guez - avatar
- 2
package main import "fmt" //define the download() function func download(s int, c chan) { var sum int sum := 0 for i:=0; i<=s; i++ { sum += i } c<-sum } func main() { ch1 := make(chan int) ch2 := make(chan int) ch3 := make(chan int) var s1, s2, s3 int fmt.Scanln(&s1) fmt.Scanln(&s2) fmt.Scanln(&s3) go download(s1, ch1) go download(s2, ch2) go download(s3, ch3) //output the sum of all results fmt.Println(<-download) }
26th May 2021, 6:57 PM
VĂĄclav DostĂĄl
VĂĄclav DostĂĄl - avatar