Skip to content

Commit b09f555

Browse files
Emre Kaplanjoncalhoun
authored andcommitted
Added solution (#34)
* Solution for part 1 * Solution for part 2 * Translated questions to English
1 parent 97ea734 commit b09f555

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

students/emrekp/problems.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
5+5,10
2+
7+3,10
3+
1+1,2
4+
8+3,11
5+
1+2,3
6+
"Surname of 9th President of Turkey","Demirel"
7+
3+1,4
8+
1+4,5
9+
5+1,6
10+
"First name of first woman PM of UK","Margaret"
11+
3+3,6
12+
2+4,6
13+
5+2,7

students/emrekp/quiz.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"encoding/csv"
5+
"flag"
6+
"fmt"
7+
"io/ioutil"
8+
"log"
9+
"path/filepath"
10+
"strings"
11+
"time"
12+
)
13+
14+
func startTime(timer time.Timer, duration time.Duration) {
15+
<-timer.C
16+
fmt.Println(duration, "doldu")
17+
}
18+
19+
func main() {
20+
filename := flag.String("file", "problems.csv", "Questions file")
21+
timelimit := flag.Int("time", 30, "Time limit of quiz in seconds")
22+
flag.Parse()
23+
24+
filePath, pathErr := filepath.Abs(*filename)
25+
if pathErr != nil {
26+
log.Fatal("file not found. check if it exists again.")
27+
}
28+
29+
remainTime := time.Duration(*timelimit) * time.Second
30+
fmt.Println("Press return to start time (", remainTime, ")")
31+
fmt.Scanln() //and time starts
32+
33+
timer := time.NewTimer(remainTime)
34+
go startTime(*timer, remainTime)
35+
36+
csvF, csvErr := ioutil.ReadFile(filePath)
37+
if csvErr != nil {
38+
log.Fatal("error reading file: " + csvErr.Error())
39+
}
40+
41+
probs, probErr := csv.NewReader(strings.NewReader(string(csvF))).ReadAll()
42+
if probErr != nil {
43+
log.Fatal("error on CSV format: " + probErr.Error())
44+
}
45+
46+
var answer string
47+
var trues, total int
48+
49+
for i, soru := range probs {
50+
fmt.Printf("%d. soru: %s = ", i+1, soru[0])
51+
fmt.Scan(&answer)
52+
if answer == soru[1] {
53+
trues++
54+
}
55+
total++
56+
}
57+
58+
fmt.Printf("True answers: %d\n", trues)
59+
fmt.Printf("Total questions: %d\n", total)
60+
}

0 commit comments

Comments
 (0)