Skip to content

Instantly share code, notes, and snippets.

@zonoise
Last active August 29, 2015 14:16
Show Gist options
  • Save zonoise/daf73cdca1383af3a654 to your computer and use it in GitHub Desktop.
Save zonoise/daf73cdca1383af3a654 to your computer and use it in GitHub Desktop.
go-tour
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())
}
}
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))
}
@zonoise
Copy link
Author

zonoise commented Mar 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment