Expand description
ยงThe Treachery of Whales
Part one is a disguised definition of the mathematical median. We can calculate the result immediately using the standard algorithm. Even though there are an even number of crabs, any integer between the 500th and 501st crab inclusive will work (the extra fuel spent by half the crabs perfectly cancels the fuel saved by the other half, when switching between integers in that range).
Part two is found by using the mean. However, since this could be a floating point value and we are using integers we need to check both the floor and the ceiling of that result to ensure the correct answer.