automatically download inputs when making new folders

This commit is contained in:
David 2021-11-30 20:10:44 -05:00
parent 1385b0d957
commit 0ebc0e2a7e
4 changed files with 11 additions and 49 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
*/inputs
*/inputs
.cookie

View File

@ -1,44 +0,0 @@
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()
}
}

10
new.sh
View File

@ -1,7 +1,11 @@
#!/bin/bash
__year=2021
if [ "${1}" != "" ]; then
mkdir -p ${1}/inputs
touch ${1}/inputs/{input,testinput}
cp -n main.go.tmpl ${1}/main.go
padded=$(printf "%02g" ${1})
mkdir -p ${padded}/inputs
touch ${padded}/inputs/{input,testinput}
curl -s -H "Cookie: session=`cat .cookie`" https://adventofcode.com/${__year}/day/${1##0}/input > "${padded}/inputs/input"
cp -n main.go.tmpl ${padded}/main.go
fi

3
run.sh
View File

@ -1,7 +1,8 @@
#!/bin/bash
if [ "${1}" != "" ]; then
cd ${1}
padded=$(printf "%02g" ${1})
cd ${padded}
go run *.go
cd - > /dev/null
fi