Browse Source

Not there yet

Piotr Czajkowski 1 week ago
parent
commit
f945c5ab2e
1 changed files with 29 additions and 1 deletions
  1. 29 1
      07/code.go

+ 29 - 1
07/code.go

@@ -33,6 +33,32 @@ func readInput(file *os.File) ([]string, int) {
 	return maze, start
 }
 
+func part1(maze []string, beams []int) int {
+	var count int
+
+	for row := 1; row < len(maze); row++ {
+		for i := range beams {
+			if beams[i] == 0 {
+				continue
+			}
+
+			if maze[row][i] == '^' {
+				if i > 0 {
+					beams[i-1]++
+				}
+
+				if i < len(beams)-1 {
+					beams[i+1]++
+				}
+
+				count++
+			}
+		}
+	}
+
+	return count
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")
@@ -45,5 +71,7 @@ func main() {
 	}
 
 	maze, start := readInput(file)
-	fmt.Println(maze, start)
+	beams := make([]int, len(maze[0]))
+	beams[start] = 1
+	fmt.Println("Part1:", part1(maze, beams))
 }