Created
December 1, 2021 10:38
-
-
Save victorgs/b4ab2b6aba71ad7cac8864b267bf18ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"math" | |
"strconv" | |
"strings" | |
) | |
func getList(filename string) []string { | |
content, err := ioutil.ReadFile(filename) | |
if err != nil { | |
log.Fatalf("%s", err) | |
} | |
lines := strings.Split(string(content), "\n") | |
return lines | |
} | |
func main() { | |
lines := getList("input") | |
var increases int = 0 | |
var prev int = math.MaxInt64 | |
for _, line := range lines { | |
current, _ := strconv.Atoi(line) | |
if current > prev { | |
increases++ | |
} | |
prev = current | |
} | |
fmt.Println(increases) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment