day 21
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
5b0f00f269
commit
94ad64a16f
|
@ -27,7 +27,7 @@ public class DayTests
|
|||
[DataRow(typeof(Day18), "12918250417632", "171259538712010")]
|
||||
[DataRow(typeof(Day19), "160", "357")]
|
||||
[DataRow(typeof(Day20), "21599955909991", "")]
|
||||
[DataRow(typeof(Day21), "", "")]
|
||||
[DataRow(typeof(Day21), "2436", "dhfng,pgblcd,xhkdc,ghlzj,dstct,nqbnmzx,ntggc,znrzgs")]
|
||||
[DataRow(typeof(Day22), "", "")]
|
||||
[DataRow(typeof(Day23), "", "")]
|
||||
[DataRow(typeof(Day24), "", "")]
|
||||
|
|
|
@ -5,17 +5,49 @@ namespace aoc2020;
|
|||
/// </summary>
|
||||
public sealed class Day21 : Day
|
||||
{
|
||||
private readonly IEnumerable<(string[] Allergens, string[] Ingredients)> _parsedFoods;
|
||||
private readonly IEnumerable<(string Allergen, string Ingredient)> _dangerousFoods;
|
||||
|
||||
public Day21() : base(21, "Allergen Assessment")
|
||||
{
|
||||
_parsedFoods = Input.Select(line => line.TrimEnd(')').Split(" (contains "))
|
||||
.Select(split => (Allergens: split[1].Split(", "), Ingredients: split[0].Split(' ')));
|
||||
|
||||
_dangerousFoods = _parsedFoods
|
||||
.SelectMany(i => i.Allergens.Select(Allergen => (Allergen, i.Ingredients)))
|
||||
.GroupBy(
|
||||
pair => pair.Allergen,
|
||||
pair => pair.Ingredients.Select(i => i),
|
||||
// group by intersection of ingredients
|
||||
(Allergen, collection) =>
|
||||
(Allergen, Ingredients: collection.Aggregate((acc, it) => acc.Intersect(it)))
|
||||
)
|
||||
.OrderBy(food => food.Ingredients.Count())
|
||||
.Aggregate(
|
||||
Enumerable.Empty<(string Allergen, string Ingredient)>(),
|
||||
(poisons, pair) =>
|
||||
poisons.Concat(new[] {(
|
||||
allergen: pair.Allergen,
|
||||
ingredient: pair.Ingredients.Except(poisons.Select(i => i.Ingredient)).First()
|
||||
)})
|
||||
);
|
||||
}
|
||||
|
||||
public override string Part1()
|
||||
{
|
||||
return "";
|
||||
var part1 = _parsedFoods
|
||||
.SelectMany(i => i.Ingredients)
|
||||
.Count(i => !_dangerousFoods.Select(t => t.Ingredient).Contains(i));
|
||||
|
||||
return $"{part1}";
|
||||
}
|
||||
|
||||
public override string Part2()
|
||||
{
|
||||
return "";
|
||||
var part2 = _dangerousFoods
|
||||
.OrderBy(i => i.Allergen)
|
||||
.Select(i => i.Ingredient);
|
||||
|
||||
return $"{string.Join(',', part2)}";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue