part1 (2368B)
1--- Day 21: Allergen Assessment --- 2 3You reach the train's last stop and the closest you can get to your vacation island without getting 4wet. There aren't even any boats here, but nothing can stop you now: you build a raft. You just need 5a few days' worth of food for your journey. 6 7You don't speak the local language, so you can't read any ingredients lists. However, sometimes, 8allergens are listed in a language you [1m[37mdo[0m understand. You should be able to use this 9information to determine which ingredient contains which allergen and work out which foods are safe 10to take with you on your trip. 11 12You start by compiling a list of foods (your puzzle input), one food per line. Each line includes 13that food's [1m[37mingredients list[0m followed by some or all of the allergens the food 14contains. 15 16Each allergen is found in exactly one ingredient. Each ingredient contains zero or one allergen. 17[1m[37mAllergens aren't always marked[0m; when they're listed (as in (contains nuts, shellfish) 18after an ingredients list), the ingredient that contains each listed allergen will be 19[1m[37msomewhere in the corresponding ingredients list[0m. However, even if an allergen isn't 20listed, the ingredient that contains that allergen could still be present: maybe they forgot to 21label it, or maybe it was labeled in a language you don't know. 22 23For example, consider the following list of foods: 24 25mxmxvkd kfcds sqjhc nhms (contains dairy, fish) 26trh fvjkl sbzzf mxmxvkd (contains dairy) 27sqjhc fvjkl (contains soy) 28sqjhc mxmxvkd sbzzf (contains fish) 29 30The first food in the list has four ingredients (written in a language you don't understand): 31mxmxvkd, kfcds, sqjhc, and nhms. While the food might contain other allergens, a few allergens the 32food definitely contains are listed afterward: dairy and fish. 33 34The first step is to determine which ingredients [1m[37mcan't possibly[0m contain any of the 35allergens in any food in your list. In the above example, none of the ingredients kfcds, nhms, 36sbzzf, or trh can contain an allergen. Counting the number of times any of these ingredients appear 37in any ingredients list produces [1m[37m5[0m: they all appear once each except sbzzf, which 38appears twice. 39 40Determine which ingredients cannot possibly contain any of the allergens in your list. [1m[37mHow 41many times do any of those ingredients appear?[0m 42 43