using System; using System.Collections.Generic; using System.Linq; namespace AdventOfCode { public static class Utility { public static Array DeepClone(this Array arr) { Array temp = Array.CreateInstance(arr.GetValue(0).GetType(), arr.Length); arr.CopyTo(temp, 0); return temp; } public static int ManhattenDistance(int x, int y) { return Math.Abs(x) + Math.Abs(y); } public static int[] ToDigitArray(int n) { var result = new int[NumberOfDigits(n)]; for (int i = result.Length - 1; i >= 0; i--) { result[i] = n % 10; n /= 10; } return result; } private static int NumberOfDigits(int n) { if (n < 0) { n = (n == int.MinValue) ? int.MaxValue : -n; } return n switch { < 10 => 1, < 100 => 2, < 1000 => 3, < 10000 => 4, < 100000 => 5, < 1000000 => 6, < 10000000 => 7, < 100000000 => 8, < 1000000000 => 9, _ => 10 }; } public static int[] GetOpcodes(string[] input) => input.First() .Split(',') .Select(x => int.Parse(x)) .ToArray(); } }