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