|
@@ -80,6 +80,24 @@ func processFoods(foods []dish) map[string]ingredient {
|
|
return processedIngredients
|
|
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() {
|
|
func main() {
|
|
if len(os.Args) < 2 {
|
|
if len(os.Args) < 2 {
|
|
log.Fatal("You need to specify a file!")
|
|
log.Fatal("You need to specify a file!")
|
|
@@ -98,5 +116,5 @@ func main() {
|
|
}
|
|
}
|
|
|
|
|
|
processedIngredients := processFoods(foods)
|
|
processedIngredients := processFoods(foods)
|
|
- fmt.Println(processedIngredients)
|
|
|
|
|
|
+ fmt.Println("Part1:", part1(processedIngredients))
|
|
}
|
|
}
|