diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb4b176 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*/inputs \ No newline at end of file diff --git a/01/main.go b/01/main.go new file mode 100644 index 0000000..196f5ca --- /dev/null +++ b/01/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "time" +) + +func main() { + start := time.Now() + partOne() + duration := time.Since(start) + partTwo() + duration2 := time.Since(start) + fmt.Printf("p1: %s, p2: %s\n", duration, duration2-duration) +} + +func makeScanner(test bool) *bufio.Scanner { + var f *os.File + if test { + f, _ = os.Open("inputs/testinput") + } else { + f, _ = os.Open("inputs/input") + } + reader := bufio.NewReader(f) + return bufio.NewScanner(reader) +} + +func partOne() { + scanner := makeScanner(false) + + for scanner.Scan() { + // line := scanner.Text() + } +} + +func partTwo() { + scanner := makeScanner(false) + + for scanner.Scan() { + // line := scanner.Text() + } +} diff --git a/main.go.tmpl b/main.go.tmpl index 56b5788..5173fd4 100644 --- a/main.go.tmpl +++ b/main.go.tmpl @@ -16,10 +16,19 @@ func main() { fmt.Printf("p1: %s, p2: %s\n", duration, duration2-duration) } -func partOne() { - f, _ := os.Open("input") +func makeScanner(test bool) *bufio.Scanner { + var f *os.File + if test { + f, _ = os.Open("inputs/testinput") + } else { + f, _ = os.Open("inputs/input") + } reader := bufio.NewReader(f) - scanner := bufio.NewScanner(reader) + return bufio.NewScanner(reader) +} + +func partOne() { + scanner := makeScanner(false) for scanner.Scan() { // line := scanner.Text() @@ -27,9 +36,7 @@ func partOne() { } func partTwo() { - f, _ := os.Open("input") - reader := bufio.NewReader(f) - scanner := bufio.NewScanner(reader) + scanner := makeScanner(false) for scanner.Scan() { // line := scanner.Text() diff --git a/new.sh b/new.sh index b1afc57..2776ede 100755 --- a/new.sh +++ b/new.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ "${1}" != "" ]; then - mkdir -p ${1} - touch ${1}/{input,testinput} + mkdir -p ${1}/inputs + touch ${1}/inputs/{input,testinput} cp -n main.go.tmpl ${1}/main.go fi