Instruction.cs 591 B

123456789101112131415161718192021222324
  1. using System.Drawing;
  2. namespace Day18;
  3. public record Instruction(char Dir, int Num, byte[] Scramble)
  4. {
  5. private static readonly IDictionary<int, char> DirMap = new Dictionary<int, char>
  6. {
  7. [0] = 'R',
  8. [1] = 'D',
  9. [2] = 'L',
  10. [3] = 'U'
  11. };
  12. public Instruction Unscramble()
  13. {
  14. var code = BitConverter.ToInt32(Scramble.Reverse().Append((byte)0).ToArray());
  15. var dirIndex = code & 15;
  16. var num = code >> 4;
  17. return new Instruction(DirMap[dirIndex], num, new byte[] { });
  18. }
  19. }