Browse Source

Solved part1

Piotr Czajkowski 3 years ago
parent
commit
6f7309cfcd
1 changed files with 25 additions and 3 deletions
  1. 25 3
      day24/day24.go

+ 25 - 3
day24/day24.go

@@ -76,6 +76,29 @@ func makeMove(path []string) position {
 	return currentPosition
 }
 
+func makeAllMoves(paths [][]string) map[position]int {
+	moves := make(map[position]int)
+
+	for _, path := range paths {
+		currentPosition := makeMove(path)
+		moves[currentPosition] += 1
+	}
+
+	return moves
+}
+
+func part1(moves map[position]int) int {
+	black := 0
+
+	for _, value := range moves {
+		if value%2 != 0 {
+			black++
+		}
+	}
+
+	return black
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")
@@ -93,7 +116,6 @@ func main() {
 		log.Fatalf("Failed to close file: %s", err)
 	}
 
-	for _, path := range paths {
-		fmt.Println(makeMove(path))
-	}
+	moves := makeAllMoves(paths)
+	fmt.Println("Part1:", part1(moves))
 }