-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (53 loc) · 1.06 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"errors"
"os"
"strconv"
)
var Solutions = map[int]func(){
// Set 1
3: MainSet1Challenge03,
4: MainSet1Challenge04,
6: MainSet1Challenge06,
7: MainSet1Challenge07,
8: MainSet1Challenge08,
// Set 2
10: MainSet2Challenge10,
11: MainSet2Challenge11,
12: MainSet2Challenge12,
13: MainSet2Challenge13,
14: MainSet2Challenge14,
}
func parseNumberArgument(parameter string) (int, error) {
if parameter == "last" {
lastKey := 0
for key := range Solutions {
if key > lastKey {
lastKey = key
}
}
return lastKey, nil
}
number, err := strconv.Atoi(parameter)
if err != nil {
return 0, err
}
_, exists := Solutions[number]
if exists {
return number, nil
}
return 0, errors.New("solution doesn't exist")
}
func main() {
if len(os.Args) != 2 {
println("Please provide the challane number as paramater to program")
return
}
number, err := parseNumberArgument(os.Args[1])
if err != nil {
println("Provided argument is not recognise or solution is not exist")
} else {
function := Solutions[number]
function()
}
}