Day 8
This commit is contained in:
60
day08/ex1/main.go
Normal file
60
day08/ex1/main.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user