using System; using System.Collections; using System.Text; namespace D16._1 { class Program { static void Main(string[] args) { Console.WriteLine($"Part 1 : {FillHardDrive(args[0], 272)}"); Console.WriteLine($"Part 2 : {FillHardDrive(args[0], 35651584)}"); } private static string FillHardDrive(string input, int diskSize) { bool[] bs = new bool[input.Length]; for (int i = 0; i < input.Length; i++) bs[i] = input[i] == '1' ? true : false; var ba = new BitArray(bs); while (ba.Length < diskSize) { var bab = new BitArray(ba.Length * 2 + 1); var l = ba.Count; for (int i = 0; i < l; ++i) { bab.Set(i, ba.Get(i)); bab.Set(l + l - i, !ba.Get(i)); } ba = bab; } int le = diskSize; while (ba.Length > 17) { le /= 2; BitArray cs = new BitArray(le); for (int i = 0; i < le; ++i) { var p = ((ba.Get(i * 2) ? 1 : 0) << 1) + (ba.Get(i * 2 + 1) ? 1 : 0); cs.Set(i, p == 0b11 || p == 0b00); } ba = cs; } var sb = new StringBuilder(); foreach (bool b in ba) sb.Append(b ? "1" : "0"); return sb.ToString(); } } }