2013-04-02から1日間の記事一覧

A Tour of Go 47 Advanced Exercise: Complex cube roots

演習:ニュートン法を使った複素数( complex )の立方根の計算を実装 package main import ( "fmt" "math/cmplx" ) func square(x complex128) complex128 { return x*x } func cube(x complex128) complex128 { return x*x*x } func enough(x,y complex128 )…

A Tour of Go 43 Exercise: Fibonacci closure

演習:fibonacci 関数を実装。 package main import "fmt" // fibonacci is a function that returns // a function that returns an int. func fibonacci() func() int { a,b := 1,1 return func() int { r := a a,b = b,a+b return r } } func main() { f …

A Tour of Go 40 Exercise: Maps

演習:WordCount 関数を実装して、文字列をカウント。 WordCountの仕様が最初問題読んでも良く解らんかった。 実行結果のテストから仕様理解したけどw; package main import ( "code.google.com/p/go-tour/wc" "strings" ) func WordCount(s string) map[s…

A Tour of Go 35 Exercise: Slices

演習:Pic 関数を実装して、生成画像を下に表示。 二次元のslice作るのに手間取った。 ってか良く解らんかったw; package main import "code.google.com/p/go-tour/pic" func Pic(dx, dy int) [][]uint8 { img := make([][]uint8, dy) for i := range img …