aoc/cmd/main.go

78 lines
1.2 KiB
Go

package main
import (
"aoc/aoc2015"
"aoc/aoc2016"
"aoc/aoc2017"
"aoc/aoc2018"
"aoc/aoc2019"
"aoc/aoc2020"
"aoc/aoc2021"
"aoc/aoc2022"
"aoc/aoc2023"
"aoc/internal/global"
"errors"
"fmt"
"strconv"
)
func main() {
var (
adv global.AdventRunner
input string
)
fmt.Print("Enter year (15-23): ")
_, err := fmt.Scanln(&input)
global.E(err)
year, err := strconv.Atoi(input)
global.E(err)
if year >= 2015 && year <= 2023 {
year -= 2000
}
if year < 15 || year > 23 {
global.E(errors.New("year out of range"))
}
fmt.Print("Enter day (1-25): ")
_, err = fmt.Scanln(&input)
global.E(err)
day, err := strconv.Atoi(input)
global.E(err)
if day < 1 || day > 25 {
global.E(errors.New("day out of range"))
}
switch year {
case 15:
adv = aoc2015.Runner{}
case 16:
adv = aoc2016.Runner{}
case 17:
adv = aoc2017.Runner{}
case 18:
adv = aoc2018.Runner{}
case 19:
adv = aoc2019.Runner{}
case 20:
adv = aoc2020.Runner{}
case 21:
adv = aoc2021.Runner{}
case 22:
adv = aoc2022.Runner{}
case 23:
adv = aoc2023.Runner{}
default:
global.E(errors.New("unknown year in switch, should never hit this"))
}
if adv != nil {
adv.Run(day)
}
}