You are viewing a single comment's thread. Return to all comments →
Yeah, it looks a lot nicer than mine. I did something similar with C# (via LINQ) and it just isn't as clean:
public static int equalStacks(params List<int>[] stacks) { int[] sums = stacks.Select(stack => Enumerable.Sum(stack)).ToArray(); while (!sums.All(sum => sum == sums.First())) { Console.WriteLine(sums); int minSum = Enumerable.Min(sums); for (int i=0; i<sums.Length; i++) { List<int> stack = stacks[i]; while (sums[i] > minSum) { sums[i] -= stack[0]; stack.RemoveAt(0); } } } return sums[0]; }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
Yeah, it looks a lot nicer than mine. I did something similar with C# (via LINQ) and it just isn't as clean: