clean up main
This commit is contained in:
parent
ee0ac427cf
commit
66a9f3f9e6
43
main.go
43
main.go
@ -12,6 +12,12 @@ func showUsage() {
|
||||
fmt.Printf("Usage: %s <day> <part> [input.txt]\n", os.Args[0])
|
||||
}
|
||||
|
||||
type DayPartSolver func([]string) error
|
||||
type DaySolver struct {
|
||||
day1 DayPartSolver
|
||||
day2 DayPartSolver
|
||||
}
|
||||
|
||||
func main() {
|
||||
if (len(os.Args) < 3) {
|
||||
showUsage()
|
||||
@ -35,29 +41,26 @@ func main() {
|
||||
|
||||
lines := strings.Split(strings.TrimRight(string(contents), "\n"), "\n")
|
||||
|
||||
if day == "1" {
|
||||
solvers := make(map[string]DaySolver)
|
||||
solvers["1"] = DaySolver{ day1: Day1Part1, day2: Day1Part2 }
|
||||
solvers["2"] = DaySolver{ day1: Day2Part1, day2: Day2Part2 }
|
||||
solvers["3"] = DaySolver{ day1: Day3Part1, day2: Day3Part2 }
|
||||
solvers["4"] = DaySolver{ day1: Day4Part1, day2: Day4Part2 }
|
||||
|
||||
solver, ok := solvers[day]
|
||||
|
||||
if ok {
|
||||
var err error
|
||||
if part == "1" {
|
||||
Day1Part1(lines)
|
||||
err = solver.day1(lines)
|
||||
} else if part == "2" {
|
||||
Day1Part2(lines)
|
||||
err = solver.day1(lines)
|
||||
}
|
||||
} else if day == "2" {
|
||||
if part == "1" {
|
||||
Day2Part1(lines)
|
||||
} else if part == "2" {
|
||||
Day2Part2(lines)
|
||||
}
|
||||
} else if day == "3" {
|
||||
if part == "1" {
|
||||
Day3Part1(lines)
|
||||
} else if part == "2" {
|
||||
Day3Part2(lines)
|
||||
}
|
||||
} else if day == "4" {
|
||||
if part == "1" {
|
||||
Day4Part1(lines)
|
||||
} else if part == "2" {
|
||||
Day4Part2(lines)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
log.Fatal("Day not found")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user