advent_of_code_2024/main.go

47 lines
1.1 KiB
Go
Raw Permalink Normal View History

2024-12-01 09:55:43 +00:00
package main
import (
2024-12-12 21:12:54 +00:00
"advent_of_code_2024/helpers"
2024-12-01 09:55:43 +00:00
_ "embed"
"fmt"
"os"
2024-12-12 18:44:27 +00:00
"time"
2024-12-01 09:55:43 +00:00
)
2024-12-12 21:12:54 +00:00
type Solution struct {
function helpers.Function
input string
}
2024-12-01 09:55:43 +00:00
func main() {
selectedDay := selectSolutionRun()
2024-12-12 21:12:54 +00:00
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)
2024-12-01 09:55:43 +00:00
}
}
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
}