47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"advent_of_code_2024/helpers"
|
|
_ "embed"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type Solution struct {
|
|
function helpers.Function
|
|
input string
|
|
}
|
|
|
|
func main() {
|
|
selectedDay := selectSolutionRun()
|
|
|
|
if solution, present := solutions[selectedDay]; present {
|
|
start := time.Now()
|
|
result := solution.function(helpers.Format(solution.input))
|
|
elapsed := time.Since(start)
|
|
fmt.Printf("Solution for '%s': %d, took: %s", selectedDay, result, elapsed)
|
|
} else {
|
|
fmt.Printf("Cannot run '%s', invalid request", selectedDay)
|
|
}
|
|
}
|
|
|
|
func selectSolutionRun() string {
|
|
selectedDay := ""
|
|
if len(os.Args) == 2 {
|
|
// if command line arg passed use that
|
|
selectedDay = os.Args[1]
|
|
} else if len(os.Args) == 1 {
|
|
// otherwise ask user for the solution
|
|
fmt.Printf("Enter the solution to be run: e.g. 01-basic,21-complex...\n")
|
|
if _, err := fmt.Scan(&selectedDay); err != nil {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
// if too many arguments are passed return error message
|
|
fmt.Printf("Invalid number of arguments\nUsage: %s day-basic|day-complex\n e.g. %s 01-basic", os.Args[0], os.Args[0])
|
|
os.Exit(1)
|
|
}
|
|
return selectedDay
|
|
}
|