From 6b46ec79d7ed8e2664089e111108939cac5510fd Mon Sep 17 00:00:00 2001 From: David Ashby Date: Fri, 10 Dec 2021 16:46:09 -0500 Subject: [PATCH] spin up basic repo --- .gitignore | 2 ++ main.go.tmpl | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ new.sh | 15 +++++++++++++++ readme.md | 3 +++ run.sh | 8 ++++++++ 5 files changed, 78 insertions(+) create mode 100644 .gitignore create mode 100644 main.go.tmpl create mode 100755 new.sh create mode 100644 readme.md create mode 100755 run.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..32e5f8c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*/inputs +.cookie \ No newline at end of file diff --git a/main.go.tmpl b/main.go.tmpl new file mode 100644 index 0000000..191337d --- /dev/null +++ b/main.go.tmpl @@ -0,0 +1,50 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" + "time" +) + +func mustAtoi(line string) int { + i, _ := strconv.Atoi(line) + return i +} + +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() + } +} \ No newline at end of file diff --git a/new.sh b/new.sh new file mode 100755 index 0000000..8bb114b --- /dev/null +++ b/new.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +__year=2019 + +if [ "${1}" != "" ]; then + padded=$(printf "%02g" ${1}) + mkdir -p ${padded}/inputs + touch ${padded}/inputs/testinput + if [ ! -f "${padded}/inputs/input" ]; then + curl -s -H "Cookie: session=`cat .cookie`" https://adventofcode.com/${__year}/day/${1##0}/input > "${padded}/inputs/input" + fi + if [ ! -f "${padded}/main.go" ]; then + cp -n main.go.tmpl ${padded}/main.go + fi +fi diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..60c8412 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# AOC 2019 + + diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..2eeee27 --- /dev/null +++ b/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ "${1}" != "" ]; then + padded=$(printf "%02g" ${1}) + cd ${padded} + go run *.go + cd - > /dev/null +fi