Browse Source

Still lost, but works for example

Piotr Czajkowski 3 years ago
parent
commit
a233a01f57
1 changed files with 19 additions and 1 deletions
  1. 19 1
      day21/day21.go

+ 19 - 1
day21/day21.go

@@ -80,6 +80,24 @@ func processFoods(foods []dish) map[string]ingredient {
 	return processedIngredients
 }
 
+func part1(processedIngredients map[string]ingredient) int {
+	sum := 0
+
+	for _, item := range processedIngredients {
+		countPossibleAllergens := 0
+
+		for _, value := range item.possibleAllergens {
+			countPossibleAllergens += value
+		}
+
+		if countPossibleAllergens <= item.count {
+			sum += item.count
+		}
+	}
+
+	return sum
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")
@@ -98,5 +116,5 @@ func main() {
 	}
 
 	processedIngredients := processFoods(foods)
-	fmt.Println(processedIngredients)
+	fmt.Println("Part1:", part1(processedIngredients))
 }