public object Part1(IParsedFile file) { file.NextLine(); file.NextLine(); file.NextLine(); var a = file.NextLine(); return(a); }
public object Part1(IParsedFile file) { var height = file.Count; var line = file.NextLine().ToSingleString(); var layout = new char[line.Length, height]; for (int y = 0; y < height; y++) { for (int x = 0; x < line.Length; x++) { layout[x, y] = line[x]; } if (!file.Empty) { line = file.NextLine().ToSingleString(); } } bool changed = true; while (changed) { changed = false; var newLayout = (char[, ])layout.Clone(); for (int y = 0; y < layout.GetLength(1); y++) { for (int x = 0; x < layout.GetLength(0); x++) { if (layout[x, y] == '.') { continue; } var adjSeats = CountAdjacent(layout, '#', x, y); if (layout[x, y] == 'L' && adjSeats == 0) { newLayout[x, y] = '#'; changed = true; } else if (layout[x, y] == '#' && adjSeats >= 4) { newLayout[x, y] = 'L'; changed = true; } } } layout = newLayout; } return(CountSeats(layout)); }
public object Part1(IParsedFile file) { // (bag, parent) var parentPairing = new HashSet <(string bag, string parent)>(); while (!file.Empty) { var line = file.NextLine().ToSingleString(); var containIndex = line.IndexOf(" contain ", StringComparison.Ordinal); var bag = line[..(containIndex - 1)];
private static IEnumerable <Operation> ParseBootloader(IParsedFile file) { while (!file.Empty) { var line = file.NextLine(); Op op = line.NextElement <string>() switch { "acc" => Op.Acc, "nop" => Op.Nop, "jmp" => Op.Jmp, _ => throw new Exception() }; yield return(new Operation(op, line.NextElement <int>())); } }
public object Part2(IParsedFile file) { var valid = 0; while (!file.Empty) { var line = file.NextLine(); var rule = line.NextElement <string>().Split('-').Select(int.Parse).ToArray(); var ch = line.NextElement <string>()[0]; var str = line.NextElement <string>(); if (rule.Count(x => ch == str[x - 1]) == 1) { valid++; } } return(valid); }
public object Part1(IParsedFile file) { var valid = 0; while (!file.Empty) { var line = file.NextLine(); var minmax = line.NextElement <string>().Split('-').Select(int.Parse).ToArray(); var ch = line.NextElement <string>()[0]; var str = line.NextElement <string>(); var cnt = str.Count(x => x == ch); if (cnt >= minmax[0] && cnt <= minmax[1]) { valid++; } } return(valid); }