This commit is contained in:
David 2021-12-01 09:28:43 -05:00
parent 0ebc0e2a7e
commit 0b9bdf682d
1 changed files with 61 additions and 0 deletions

61
01/main.go Normal file
View File

@ -0,0 +1,61 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"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)
p := 0
c := 0
for scanner.Scan() {
line := scanner.Text()
n, _ := strconv.Atoi(line)
if p != 0 && n > p {
c++
}
p = n
}
fmt.Println("part 1:", c)
}
func partTwo() {
scanner := makeScanner(false)
one, two, three := 0, 0, 0
c := 0
for scanner.Scan() {
line := scanner.Text()
n, _ := strconv.Atoi(line)
if one != 0 && two != 0 && three != 0 && one+two+three < two+three+n {
c++
}
one, two, three = two, three, n
}
fmt.Println("part 2:", c)
}