Initial commit with command and Day interface
This commit is contained in:
6
day.go
Normal file
6
day.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type Day interface {
|
||||||
|
Answer() string
|
||||||
|
FollowUp() string
|
||||||
|
}
|
45
main.go
Normal file
45
main.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"unsupervised.ca/aoc2021/one"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
args := os.Args
|
||||||
|
|
||||||
|
if len(args) != 2 {
|
||||||
|
help()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
flagParts := strings.Split(args[1], "--")
|
||||||
|
if len(flagParts) != 2 {
|
||||||
|
fmt.Println("Unable to read day from flag")
|
||||||
|
}
|
||||||
|
|
||||||
|
var day Day
|
||||||
|
switch flagParts[1] {
|
||||||
|
case "one":
|
||||||
|
day = one.Init("one/input.txt")
|
||||||
|
default:
|
||||||
|
fmt.Printf("%q does not have a solution.\n", flagParts[1])
|
||||||
|
help()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("The solution for %q is:\n", flagParts[1])
|
||||||
|
fmt.Println(day.Answer())
|
||||||
|
fmt.Println(day.FollowUp())
|
||||||
|
}
|
||||||
|
|
||||||
|
func help() {
|
||||||
|
fmt.Println("To execute thatguygriff's solutions for Advent of Code execute the command with the day as a flag")
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Printf("%s [--one|--two|--three]\n", os.Args[0])
|
||||||
|
fmt.Println("")
|
||||||
|
fmt.Println("If there is no solution for the flagged day this text will be printed.")
|
||||||
|
}
|
0
one/input.txt
Normal file
0
one/input.txt
Normal file
16
one/main.go
Normal file
16
one/main.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package one
|
||||||
|
|
||||||
|
type One struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func Init(filepath string) *One {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *One) Answer() string {
|
||||||
|
return "Hello"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *One) FollowUp() string {
|
||||||
|
return "World!"
|
||||||
|
}
|
Reference in New Issue
Block a user