This commit is contained in:
2022-12-08 11:07:30 +01:00
parent accef506b5
commit c9a854978a
3 changed files with 146 additions and 0 deletions

60
day08/ex1/main.go Normal file
View File

@@ -0,0 +1,60 @@
package main
import (
"bufio"
"fmt"
"os"
"aoc2022/day08/common"
)
func main() {
forest := common.Parse(*bufio.NewScanner(os.Stdin))
nVisibleTrees := 0
for i := 0; i < len(forest); i++ {
for j := 0; j < len(forest[i]); j++ {
visible := true
for k := 0; k < i; k++ {
if forest[k][j] >= forest[i][j] {
visible = false
}
}
if visible {
nVisibleTrees++
continue
}
visible = true
for k := 0; k < j; k++ {
if forest[i][k] >= forest[i][j] {
visible = false
}
}
if visible {
nVisibleTrees++
continue
}
visible = true
for k := i + 1; k < len(forest); k++ {
if forest[k][j] >= forest[i][j] {
visible = false
}
}
if visible {
nVisibleTrees++
continue
}
visible = true
for k := j + 1; k < len(forest[i]); k++ {
if forest[i][k] >= forest[i][j] {
visible = false
}
}
if visible {
nVisibleTrees++
continue
}
}
}
fmt.Println(nVisibleTrees)
}