challenge.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. --- Day 21: Allergen Assessment ---
  2. You reach the train's last stop and the closest you can get to your vacation island without getting wet. There aren't even any boats here, but nothing can stop you now: you build a raft. You just need a few days' worth of food for your journey.
  3. You don't speak the local language, so you can't read any ingredients lists. However, sometimes, allergens are listed in a language you do understand. You should be able to use this information to determine which ingredient contains which allergen and work out which foods are safe to take with you on your trip.
  4. You start by compiling a list of foods (your puzzle input), one food per line. Each line includes that food's ingredients list followed by some or all of the allergens the food contains.
  5. Each allergen is found in exactly one ingredient. Each ingredient contains zero or one allergen. Allergens aren't always marked; when they're listed (as in (contains nuts, shellfish) after an ingredients list), the ingredient that contains each listed allergen will be somewhere in the corresponding ingredients list. However, even if an allergen isn't listed, the ingredient that contains that allergen could still be present: maybe they forgot to label it, or maybe it was labeled in a language you don't know.
  6. For example, consider the following list of foods:
  7. mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
  8. trh fvjkl sbzzf mxmxvkd (contains dairy)
  9. sqjhc fvjkl (contains soy)
  10. sqjhc mxmxvkd sbzzf (contains fish)
  11. The first food in the list has four ingredients (written in a language you don't understand): mxmxvkd, kfcds, sqjhc, and nhms. While the food might contain other allergens, a few allergens the food definitely contains are listed afterward: dairy and fish.
  12. The first step is to determine which ingredients can't possibly contain any of the allergens in any food in your list. In the above example, none of the ingredients kfcds, nhms, sbzzf, or trh can contain an allergen. Counting the number of times any of these ingredients appear in any ingredients list produces 5: they all appear once each except sbzzf, which appears twice.
  13. Determine which ingredients cannot possibly contain any of the allergens in your list. How many times do any of those ingredients appear?
  14. Your puzzle answer was 2170.
  15. --- Part Two ---
  16. Now that you've isolated the inert ingredients, you should have enough information to figure out which ingredient contains which allergen.
  17. In the above example:
  18. mxmxvkd contains dairy.
  19. sqjhc contains fish.
  20. fvjkl contains soy.
  21. Arrange the ingredients alphabetically by their allergen and separate them by commas to produce your canonical dangerous ingredient list. (There should not be any spaces in your canonical dangerous ingredient list.) In the above example, this would be mxmxvkd,sqjhc,fvjkl.
  22. Time to stock your raft with supplies. What is your canonical dangerous ingredient list?
  23. Your puzzle answer was nfnfk,nbgklf,clvr,fttbhdr,qjxxpr,hdsm,sjhds,xchzh.