Completed 1-2
This commit is contained in:
parent
048854eaf0
commit
665562976b
13
1-2/main.go
13
1-2/main.go
@ -10,18 +10,23 @@ import (
|
||||
func main() {
|
||||
input, err := readInput("input")
|
||||
if err != nil {
|
||||
fmt.Errorf(err.Error())
|
||||
fmt.Printf("%s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
counter := 0
|
||||
for i := 0; i < len(input)-1; i++ {
|
||||
if input[i+1] > input[i] {
|
||||
sums := make([]int, 0)
|
||||
for i := 0; i < len(input)-2; i++ {
|
||||
sums = append(sums, (input[i] + input[i+1] + input[i+2]))
|
||||
}
|
||||
|
||||
for i := 0; i < len(sums)-1; i++ {
|
||||
if sums[i+1] > sums[i] {
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("It increased %d times", counter)
|
||||
fmt.Printf("Number of times increased is: %d", counter)
|
||||
}
|
||||
|
||||
func readInput(filename string) ([]int, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user