Skip to content

Instantly share code, notes, and snippets.

@sugilog
sugilog / exercise.go
Created January 3, 2015 10:41
mapの演習
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
counts := map[string]int{}
@sugilog
sugilog / sample.go
Last active August 29, 2015 14:12
for-rangeループ
package main
import "fmt"
func main() {
sl := []int{ 10, 20, 30, 40, 50, 60, 70, 80, 90 }
fmt.Println( "rangeWith2Var" )
rangeWith2Var( sl )
fmt.Println( "rangeWith1VarForIndex" )
rangeWith1VarForIndex( sl )
@sugilog
sugilog / sample.go
Created January 1, 2015 00:35
スライス:スライシング
package main
import "fmt"
func main() {
sl1 := []int{ 10, 20, 30, 40, 50, 60, 70, 80, 90 }
sl2 := sl1[ 3:7 ]
sl3 := sl1[ 5: ]
sl4 := sl2[ :3 ]
@sugilog
sugilog / sample.go
Created December 29, 2014 01:52
ポインタと構造体
package main
import "fmt"
type Animal struct {
Name string
Age int
}
func main() {
@sugilog
sugilog / sample.go
Created December 28, 2014 15:48
構造体
package main
import (
"fmt"
)
type Space struct {
X int
Y int
Z int
@sugilog
sugilog / sample1.go
Last active August 29, 2015 14:12
ニュートン法を使った平方根の計算
package main
import (
"fmt"
)
func Sqrt(x float64) float64 {
var z float64 = 1
for i := 0; i < 10; i++ {
@sugilog
sugilog / sample.go
Created December 28, 2014 15:03
条件分岐:if
package main
import (
"fmt"
"time"
)
func main() {
patternA()
patternB()
@sugilog
sugilog / sample.go
Created December 28, 2014 09:46
forループ
package main
import "fmt"
func main() {
patternA()
patternB()
patternC()
patternD()
}
@sugilog
sugilog / sample.go
Created December 28, 2014 09:13
定数
package main
import "fmt"
func main() {
const APP_NAME = "Type"
const VERSION int = 1
fmt.Println( APP_NAME, VERSION )
@sugilog
sugilog / sample.go
Created December 28, 2014 08:39
変数:varステートメント、代入
package main
import (
"fmt"
"time"
)
var start, finish time.Time
var appName, severity, sleep = "SAMPLE", "INFO", 1000 * time.Millisecond