finish day-one prep

This commit is contained in:
David 2021-11-30 19:14:48 -05:00
parent c6b57d6e8a
commit 1385b0d957
4 changed files with 60 additions and 8 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*/inputs

44
01/main.go Normal file
View File

@ -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()
}
}

View File

@ -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()

4
new.sh
View File

@ -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