diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ad0baf6 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module adventOfCode + +go 1.15 + +require github.com/fatih/color v1.10.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9ee68f3 --- /dev/null +++ b/go.sum @@ -0,0 +1,9 @@ +github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= +github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= +github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= +github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/template/go/challenge/common.go b/template/go/challenge/common.go new file mode 100644 index 0000000..8e7ab72 --- /dev/null +++ b/template/go/challenge/common.go @@ -0,0 +1,5 @@ +package challenge + +func parse(instr string) []string { + return []string{} +} \ No newline at end of file diff --git a/template/go/challenge/partOne.go b/template/go/challenge/partOne.go new file mode 100644 index 0000000..3d48d46 --- /dev/null +++ b/template/go/challenge/partOne.go @@ -0,0 +1,6 @@ +package challenge + +func PartOne(instr string) int { + // inputSlice := parse(instr) + return 0 +} \ No newline at end of file diff --git a/template/go/challenge/partTwo.go b/template/go/challenge/partTwo.go new file mode 100644 index 0000000..2b02e97 --- /dev/null +++ b/template/go/challenge/partTwo.go @@ -0,0 +1,6 @@ +package challenge + +func PartTwo(instr string) int { + // inputSlice := parse(instr) + return 0 +} \ No newline at end of file diff --git a/template/go/main.go b/template/go/main.go new file mode 100644 index 0000000..78456ae --- /dev/null +++ b/template/go/main.go @@ -0,0 +1,88 @@ +package main + +import ( + "adventOfCode/template/go/challenge" + "encoding/json" + "fmt" + "io/ioutil" + "os" + "runtime" + "strconv" + + "github.com/fatih/color" +) + +const ( + year = "2020" + day = "1" + title = "Report Repair" +) + +func main() { + fmt.Fprintf(color.Output, "%s: day %s - %s\n", color.YellowString("AoC "+year), color.BlueString(day), title) + fmt.Fprintf(color.Output, "Go %s\n\n", color.BlueString(runtime.Version())) + + var challengeInput string + { + inb, err := ioutil.ReadFile("input.txt") + if err != nil { + fmt.Println("Error: could not open input.txt") + os.Exit(-1) + } + challengeInput = string(inb) + } + + runTests() + + fmt.Println("Answers") + fmt.Fprintf(color.Output, "Part %s: %s\n", color.BlueString("1"), color.BlueString(strconv.Itoa(challenge.PartOne(challengeInput)))) + fmt.Fprintf(color.Output, "Part %s: %s\n", color.BlueString("2"), color.BlueString(strconv.Itoa(challenge.PartTwo(challengeInput)))) + +} + +type tc struct { + Input string `json:"input"` + Expected int `json:"expected"` +} + +func runTests() { + + testCases := struct { + One []tc `json:"one"` + Two []tc `json:"two"` + }{} + + { + inb, err := ioutil.ReadFile("testCases.json") + if err != nil { + fmt.Println("Error: could not open testCases.json. Skipping tests") + return + } + err = json.Unmarshal(inb, &testCases) + if err != nil { + fmt.Println("Error: could not parse testCases.json. Skipping tests") + return + } + } + + fmt.Println("Test cases") + + rt := func(tcs []tc, f func(string) int, n string) { + for i, tc := range tcs { + fmt.Fprintf(color.Output, "%s ", color.BlueString(n+"."+strconv.Itoa(i+1))) + result := f(tc.Input) + if result == tc.Expected { + fmt.Fprintf(color.Output, "%s", color.GreenString("pass")) + } else { + fmt.Fprintf(color.Output, "%s (got %s, expected %s)", color.RedString("fail"), color.BlueString(strconv.Itoa(result)), color.BlueString(strconv.Itoa(tc.Expected))) + } + fmt.Println() + } + } + + rt(testCases.One, challenge.PartOne, "1") + rt(testCases.Two, challenge.PartTwo, "2") + + fmt.Println() + +}