-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (29 loc) · 794 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"encoding/csv"
"flag"
"fmt"
"log"
"os"
"time"
"github.com/nirav24/gophercises-quiz/quiz"
)
func main() {
filePath := flag.String("csv", "problems.csv", "A csv file containing problems in 'question,answer' format")
timeLimit := flag.Int("time", 30, "A time limit for quiz in seconds")
flag.Parse()
file, err := os.Open(*filePath)
if err != nil {
log.Fatalf("Failed to Read csv file. Msg: %s", err)
}
defer file.Close()
reader := csv.NewReader(file)
questions, err := reader.ReadAll()
if err != nil {
log.Fatal(err)
}
problems := quiz.ParseProblems(questions)
timer := time.NewTimer(time.Duration(*timeLimit) * time.Second)
result := quiz.PlayQuiz(problems, timer.C)
fmt.Printf("You scored %d out of %d.\n", result.Right, result.Total)
}