Production Level Knowledge & Tips

  1. 未分類
  2. 5 view

[Go]Output Fibonacci Series

Output Fibonaaci Series with Go.
package main

var ch = make(chan int)
var array [10]int

func fib(init int) {
    switch {
        case init == 0 || init == 1 :
            array[init] = 1
            ch <- array[init];
            return
        case init >= 2 :
            array[init] = array[init-2] + array[init-1]
            ch <- array[init]
            return
    }
}

func main() {
    for i := 0; i <= 0; i++ {
        array[i] = 0
    }

    for num := 0; num < 10; num++ {
        go fib(num);
        println(<- ch);
    }
}
Run.
$pwd
-> $GOPATH
$go install example/fib
$fib/fib
1
1
2
3
5
8
13
21
34
55

未分類 recent post

  1. Install sbt 1.0.0 and run sample template

  2. Visualization of Neural Network and its Train…

  3. [Machine Learning]Created docker image includ…

  4. [Node.js]How to write batch script with Node.…

  5. [Hive]Get top n items for each category

関連記事

PAGE TOP