public override void PartOne() { const int size = 256; var nums = Enumerable.Range(0, size).Repeat(2).ToArray(); var current = 0; var skip = 0; foreach (var length in InputLine.Csv().Ints()) { new Span <int>(nums, current, length).Reverse(); if (current + length > size) { Array.Copy(nums, size, nums, 0, current + length - size); Array.Copy(nums, current, nums, current + size, size - current); } else { Array.Copy(nums, current, nums, current + size, length); } current = (current + length + skip) % size; skip++; } var result = nums[0] * nums[1]; WriteLn(result); }
public void Dance(CircularBuffer <int> buf) { var offset = 0; foreach (var cmd in InputLine.Csv()) { if (cmd[0] == 's') { offset -= int.Parse(cmd[1..]);
public override void PartOne() { var target = InputLine.Csv() .Select(Pos3D.ParseHexDir) .Aggregate(Pos3D.Add); var result = target.HexDistance(Pos3D.Origin); WriteLn(result); }
public override void PartTwo() { var result = InputLine.Csv() .Select(Pos3D.ParseHexDir) .Scan(Pos3D.Add) .Select(p => p.HexDistance(Pos3D.Origin)) .Max(); WriteLn(result); }
public override void PartTwo() { var pos = InputLine.Csv().Ints().ToList(); var min = pos.Min(); var max = pos.Max() + 1; Interval range = min..max; var target = range.Min(i => pos.Select(p => Math.Abs(p - i)).Select(Algorithms.Sum1ToN).Sum()); WriteLn(target); }
public IEnumerable <Pos> GetPoints() { var dir = Pos.Up; var pos = Pos.Origin; yield return(pos); foreach (var move in InputLine.Csv(true)) { dir = move[0] == 'L' ? dir.CounterClockwise() : dir.Clockwise(); pos += dir * move[1..].AsInt();
public long Steps(int count) { var counts = InputLine.Csv().Ints().Frequencies() .ToArrayByIndex(9, pair => pair.Key, pair => (long)pair.Value); var timers = new CircularBuffer <long>(counts); for (var i = 0; i < count; i++) { timers.Offset++; timers[6] += timers[8]; } return(timers.Unordered().Sum()); }
public override void PartTwo() { var program = InputLine.Csv().Longs().ToArray(); foreach (var sequence in Algorithms.Sequences(2, 100, true)) { var noun = sequence[0]; var verb = sequence[1]; var c = new Computer(program.ToArray()) { [1] = noun, [2] = verb }; c.Execute(); if (c[0] == 19690720) { WriteLn(100 * noun + verb); return; } } WriteLn("None"); }