From 1385b0d95713b619ec442a8b7e2909e4c7cae6d3 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Tue, 30 Nov 2021 19:14:48 -0500 Subject: [PATCH] finish day-one prep --- .gitignore | 1 + 01/main.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ main.go.tmpl | 19 +++++++++++++------ new.sh | 4 ++-- 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 01/main.go 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