Last active
August 29, 2015 14:16
-
-
Save zonoise/daf73cdca1383af3a654 to your computer and use it in GitHub Desktop.
go-tour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
// fibonacci is a function that returns | |
// a function that returns an int. | |
func fibonacci() func() int { | |
before := 0 | |
before_before := 0 | |
n := 0 | |
return func() int{ | |
var current int | |
if n == 0{ | |
current = 0 | |
} else if n == 1 { | |
current = 1 | |
}else{ | |
current = before_before + before | |
} | |
before_before=before | |
before=current | |
n++ | |
return current | |
} | |
} | |
func main() { | |
f := fibonacci() | |
for i := 0; i < 10; i++ { | |
fmt.Println(f()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "math/cmplx" | |
func Cbrt(x complex128) complex128 { | |
start := complex128(5) | |
tmp:= start | |
hoge := func(z complex128) complex128 { | |
z = z - ( ( (z*z*z) - x ) / ( 3*z*z ) ) | |
return z | |
} | |
for i:=0;i<10;i++{ | |
tmp = hoge(tmp) | |
} | |
return tmp | |
} | |
func main() { | |
var x complex128 = 7 | |
z := Cbrt(x) | |
fmt.Println(x) | |
fmt.Println(cmplx.Pow(z,3)) | |
fmt.Println(Cbrt(x)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://go-tour-jp.appspot.com やってる