From 7803120021beeb7a5cb29190b3230176ecc7f04d Mon Sep 17 00:00:00 2001 From: matsumatsu20 Date: Mon, 10 Sep 2018 01:11:22 +0900 Subject: [PATCH 1/4] Implement kadai3-1 --- kadai3-1/matsumatsu20/main.go | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 kadai3-1/matsumatsu20/main.go diff --git a/kadai3-1/matsumatsu20/main.go b/kadai3-1/matsumatsu20/main.go new file mode 100644 index 0000000..0171ff1 --- /dev/null +++ b/kadai3-1/matsumatsu20/main.go @@ -0,0 +1,58 @@ +package main + +import ( + "os" + "fmt" + "io" + "bufio" + "math/rand" + "time" +) + +func main() { + ch := input(os.Stdin) + var count int64 + + rand.Seed(time.Now().UnixNano()) + prefectures := []string{"hokkaido", "aomori", "iwate", "miyagi", "akita", "yamagata", "fukushima", "ibaraki", "tochigi", "gunma", "saitama", "chiba", "tokyo", "kanagawa", "niigata", "toyama", "ishikawa", "fukui", "yamanashi", "nagano", "gifu", "shizuoka", "aichi", "mie", "shiga", "kyoto", "osaka", "hyogo", "nara", "wakayama", "tottori", "shimane", "okayama", "hiroshima", "yamaguchi", "tokushima", "kagawa", "ehime", "kochi", "fukuoka", "saga", "nagasaki", "kumamoto", "oita", "miyazaki", "kagoshima", "okinawa"} + + go func() { + <-time.After(3 * time.Second) + + fmt.Println("終了しました") + fmt.Printf("あなたのスコア: %v\n", count) + os.Exit(0) + }() + + for { + str := prefectures[rand.Intn(len(prefectures))] + fmt.Print("> ") + fmt.Println(str) + + select { + case inputStr := <-ch: + if str == inputStr { + fmt.Println("ok!") + count += 1 + } else { + fmt.Println("miss!") + } + } + } + +} + +func input(r io.Reader) <-chan string { + ch := make(chan string) + + go func() { + defer close(ch) + + s := bufio.NewScanner(r) + + for s.Scan() { + ch <- s.Text() + } + }() + return ch +} From 66d400ea46c1f905c64c5c1e19ba4d11ce39dfbc Mon Sep 17 00:00:00 2001 From: matsumatsu20 Date: Mon, 10 Sep 2018 01:23:48 +0900 Subject: [PATCH 2/4] Add gitignore --- kadai3-1/matsumatsu20/.gitignore | 95 ++++++++++++++++++++++++++++++++ kadai3-1/matsumatsu20/Makefile | 0 kadai3-1/matsumatsu20/README.md | 0 3 files changed, 95 insertions(+) create mode 100644 kadai3-1/matsumatsu20/.gitignore create mode 100644 kadai3-1/matsumatsu20/Makefile create mode 100644 kadai3-1/matsumatsu20/README.md diff --git a/kadai3-1/matsumatsu20/.gitignore b/kadai3-1/matsumatsu20/.gitignore new file mode 100644 index 0000000..cecdcf0 --- /dev/null +++ b/kadai3-1/matsumatsu20/.gitignore @@ -0,0 +1,95 @@ +# Created by https://www.gitignore.io/api/go,intellij+all + +### Go ### +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +matsuda + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +### Go Patch ### +/vendor/ +/Godeps/ + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +### Intellij+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# End of https://www.gitignore.io/api/go,intellij+all \ No newline at end of file diff --git a/kadai3-1/matsumatsu20/Makefile b/kadai3-1/matsumatsu20/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/kadai3-1/matsumatsu20/README.md b/kadai3-1/matsumatsu20/README.md new file mode 100644 index 0000000..e69de29 From d30532c96293209e46c59989dad13b3e6ad94de8 Mon Sep 17 00:00:00 2001 From: matsumatsu20 Date: Mon, 10 Sep 2018 01:24:07 +0900 Subject: [PATCH 3/4] Add README and make file --- kadai3-1/matsumatsu20/Makefile | 15 +++++++++++++++ kadai3-1/matsumatsu20/README.md | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/kadai3-1/matsumatsu20/Makefile b/kadai3-1/matsumatsu20/Makefile index e69de29..7b06676 100644 --- a/kadai3-1/matsumatsu20/Makefile +++ b/kadai3-1/matsumatsu20/Makefile @@ -0,0 +1,15 @@ +# Go パラメータ +GOCMD=go +GOBUILD=$(GOCMD) build +GOCLEAN=$(GOCMD) clean +GOTEST=$(GOCMD) test +BINARY_NAME=matsuda + all: test build +build: + $(GOBUILD) -o $(BINARY_NAME) -v +test: + $(GOTEST) -v ./... +clean: + $(GOCLEAN) + rm -f $(BINARY_NAME) + rm -f $(BINARY_UNIX) diff --git a/kadai3-1/matsumatsu20/README.md b/kadai3-1/matsumatsu20/README.md index e69de29..389eb9d 100644 --- a/kadai3-1/matsumatsu20/README.md +++ b/kadai3-1/matsumatsu20/README.md @@ -0,0 +1,14 @@ +# タイピングゲームを作ろう +## 課題事項 +- [x] 標準出力に英単語を出す(出すものは自由) +- [x] 標準入力から1行受け取る +- [x] 制限時間内(30s)に何問解けたか表示する + ## Usage +### build +```bash +% make build +``` + ### run +```bash +% ./matsuda +``` \ No newline at end of file From eedde0cab874dc7ffde44aca9adceef0a1a56fb1 Mon Sep 17 00:00:00 2001 From: matsumatsu20 Date: Mon, 10 Sep 2018 01:24:29 +0900 Subject: [PATCH 4/4] Change limit time --- kadai3-1/matsumatsu20/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kadai3-1/matsumatsu20/main.go b/kadai3-1/matsumatsu20/main.go index 0171ff1..bd3193f 100644 --- a/kadai3-1/matsumatsu20/main.go +++ b/kadai3-1/matsumatsu20/main.go @@ -17,7 +17,7 @@ func main() { prefectures := []string{"hokkaido", "aomori", "iwate", "miyagi", "akita", "yamagata", "fukushima", "ibaraki", "tochigi", "gunma", "saitama", "chiba", "tokyo", "kanagawa", "niigata", "toyama", "ishikawa", "fukui", "yamanashi", "nagano", "gifu", "shizuoka", "aichi", "mie", "shiga", "kyoto", "osaka", "hyogo", "nara", "wakayama", "tottori", "shimane", "okayama", "hiroshima", "yamaguchi", "tokushima", "kagawa", "ehime", "kochi", "fukuoka", "saga", "nagasaki", "kumamoto", "oita", "miyazaki", "kagoshima", "okinawa"} go func() { - <-time.After(3 * time.Second) + <-time.After(30 * time.Second) fmt.Println("終了しました") fmt.Printf("あなたのスコア: %v\n", count)