aboutsummaryrefslogtreecommitdiff
path: root/2021/01/first.go
blob: 59b958c09432e25fb3e9448d0435e55083f92995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	f, err := os.Open("input")
	if err != nil {
		log.Fatalf("%+v", err)
	}
	defer f.Close()

	scanner := bufio.NewScanner(f)
	scanner.Split(bufio.ScanLines)

	scanner.Scan()
	prev, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatalf("%+v", err)
	}
	result := 0

	for scanner.Scan() {
		i, err := strconv.Atoi(scanner.Text())
		if err != nil {
			log.Fatalf("%+v", err)
		}
		if i > prev {
			result++
		}
		prev = i
	}
	fmt.Println(result)
}