mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-14 17:21:15 +00:00
first
This commit is contained in:
35
course/13-channels/exercises/6-range/code.go
Normal file
35
course/13-channels/exercises/6-range/code.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func concurrrentFib(n int) {
|
||||
// ?
|
||||
}
|
||||
|
||||
// TEST SUITE - Don't touch below this line
|
||||
|
||||
func test(n int) {
|
||||
fmt.Printf("Printing %v numbers...\n", n)
|
||||
concurrrentFib(n)
|
||||
fmt.Println("==============================")
|
||||
}
|
||||
|
||||
func main() {
|
||||
test(10)
|
||||
test(5)
|
||||
test(20)
|
||||
test(13)
|
||||
}
|
||||
|
||||
func fibonacci(n int, ch chan int) {
|
||||
x, y := 0, 1
|
||||
for i := 0; i < n; i++ {
|
||||
ch <- x
|
||||
x, y = y, x+y
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
}
|
||||
close(ch)
|
||||
}
|
||||
Reference in New Issue
Block a user