Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kadai3 matsumatsu20 #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions kadai3-1/matsumatsu20/.gitignore
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions kadai3-1/matsumatsu20/Makefile
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions kadai3-1/matsumatsu20/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# タイピングゲームを作ろう
## 課題事項
- [x] 標準出力に英単語を出す(出すものは自由)
- [x] 標準入力から1行受け取る
- [x] 制限時間内(30s)に何問解けたか表示する
## Usage
### build
```bash
% make build
```
### run
```bash
% ./matsuda
```
58 changes: 58 additions & 0 deletions kadai3-1/matsumatsu20/main.go
Original file line number Diff line number Diff line change
@@ -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(30 * 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
}