Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "time"
- )
- func main() {
- intchan := make(chan int)
- floatchan := make(chan float64)
- var fibratio float64
- fiblength := 50
- go fib(intchan, floatchan, fiblength)
- go ratio(floatchan, fiblength)
- for i := 0; i < fiblength; i++ {
- fibnum := <-intchan
- if i > 0 {
- fibratio = <-floatchan
- }
- fmt.Println(fibnum, " - ", fibratio)
- time.Sleep(time.Millisecond * 250)
- }
- }
- func fib(intchan chan int, floatchan chan float64, length int) {
- var next, current, last int
- for i := 0; i < length; i++ {
- if current == 0 {
- next = 1
- } else {
- next = current + last
- }
- last = current
- current = next
- intchan <- next
- floatchan <- float64(next)
- }
- }
- func ratio(floatchan chan float64, length int) {
- var first bool = true
- var x, y, fibratio float64
- for i := 0; i < length; i++ {
- if first == true {
- y = <-floatchan
- x = <-floatchan
- } else {
- x = <-floatchan
- }
- fibratio = x / y
- y = x
- first = false
- floatchan <- fibratio
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement