public long GetTimeToFill() { //< Want to fill out from the where the Oxygen tank is FloodFill(this.Target); //< Each movement to an adjacent cell takes 1 minute //< Just need to find whichever cell took the longest to fill, and return the FillLevel there var maxLevel = FloodLevels.Cast <long>().Max(); return(maxLevel); }
/// <summary> /// Translates an array of extranonce, nonce pairs into list of block info. /// </summary> /// <returns>List of block info for hard coded blocks.</returns> private static List <BlockInfo> CreateBlockInfoList() { var blockInfoList = new List <BlockInfo>(); List <long> lst = blockinfoarr.Cast <long>().ToList(); for (int i = 0; i < lst.Count; i += 2) { blockInfoList.Add(new BlockInfo { extraNonce = (int)lst[i], nonce = (uint)lst[i + 1] }); } return(blockInfoList); }
public override string Part1() { for (var x = 0; x < 50; x++) { for (var y = 0; y < 50; y++) { vm.Reset(); vm.Run(x, y); grid[x, y] = vm.Result; } } return($"{grid.Cast<long>().Sum()}"); }
public string secondPuzzle(string input) { long[] intcode = input.Split(',').Select(long.Parse).ToArray(); ic = new IntComputer(intcode); Point og = new Point { X = 0, Y = 0 }; StartPoint = og; CheckAdjacentPoints(og); var minX = SeenPoints.Keys.Min(k => k.X); var maxX = SeenPoints.Keys.Max(k => k.X); var minY = SeenPoints.Keys.Min(k => k.Y); var maxY = SeenPoints.Keys.Max(k => k.Y); var offsetX = Math.Abs(minX); var offsetY = Math.Abs(minY); var sizeX = maxX + offsetX; var sizeY = maxY + offsetY; StartPoint = new Point { X = StartPoint.X + offsetX, Y = StartPoint.Y + offsetY }; TargetPoint = new Point { X = TargetPoint.X + offsetX, Y = TargetPoint.Y + offsetY }; Board = new long[sizeY + 1, sizeX + 1]; FloodLvls = new long[sizeY + 1, sizeX + 1]; Seen = new bool[sizeY + 1, sizeX + 1]; foreach (var p in SeenPoints) { Board[p.Key.Y + offsetY, p.Key.X + offsetX] = p.Value; } FloodFill(TargetPoint); long timeStepsToFlood = FloodLvls.Cast <long>().Max(); return(timeStepsToFlood.ToString()); }
private void CreateBitmapFromRawData() { // Create new bitmap recreatedImage.Dispose(); recreatedImage = new DirectBitmap(originalImageWidth, originalImageHeight); // Find the maximum value in the array long maxValue = rawData.Cast <long>().Concat(new long[] { 0 }).Max(); for (int y = 0; y < originalImageHeight; y++) { for (int x = 0; x < originalImageWidth; x++) { var color = (byte)Scale(0, maxValue, 0, 255, rawData[x, y]); recreatedImage.SetPixel(x, y, Color.FromArgb(color, color, color)); } } }
public static string convertFrac(long[,] lst) { var denominators = new List <long>(); for (int i = 0; i < lst.Length / 2; i++) { var denominator = lst[i, 1]; denominators.Add(denominator); } long gcd = 1; denominators.Distinct().ToList().ForEach(x => gcd *= x); long[,] newList = (long[, ])lst.Clone(); for (int i = 0; i < lst.Length / 2; i++) { var denominator = lst[i, 1]; var temp = gcd / denominator; var top = lst[i, 0]; newList[i, 0] = top * temp; newList[i, 1] = gcd; } long gcdReducer = 1; var allNumbersFlattened = newList.Cast <long>().ToArray().Distinct(); var seed = gcd; var found = false; var ii = 1; do { if (allNumbersFlattened.All(x => (x % seed) == 0)) { found = true; gcdReducer = seed; } else { seed = gcd / ++ii; } } while (!found && (seed > 0)); if (gcdReducer != 1) { for (int i = 0; i < newList.Length / 2; i++) { newList[i, 0] = newList[i, 0] / gcdReducer; newList[i, 1] = newList[i, 1] / gcdReducer; } } var output = string.Empty; for (int i = 0; i < newList.Length / 2; i++) { output += $"({newList[i, 0]},{newList[i, 1]})"; } return(output); }