automatically download inputs when making new folders
This commit is contained in:
parent
1385b0d957
commit
0ebc0e2a7e
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
*/inputs
|
||||
*/inputs
|
||||
.cookie
|
44
01/main.go
44
01/main.go
@ -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
10
new.sh
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user