Tuesday, June 26, 2018

Implementing a Thanos process

Avengers Infinity War was an interesting movie. Pretty well done. You think about it a bit afterwards. Which is a bit unusual for superhero movies. I've seen a number of superhero movies over the years and there is a kind of sameness and forgetability about them afterwards. Some are more memorable like the original spider man trilogy, the dark night batman trilogy.

The villain in Avengers was Thanos. Now Thanos had an interesting plan to deal with human caused problems such as overpopulation, resource depletion, and environmental degradation. The Thanos process is that in one swoop half of the population of a planet is eliminated. Also the choosing of which half is done totally by random chance. Thanos makes it clear that everyone is subject to the "coin flip" that decides each persons fate. There are no exemptions or appeals afterward. On his own planet when he came up with the plan Thanos made it very clear that he too would be subject to the risk of the coin flip.

After the choice of the coin flip is made the implementation of the elimination is actually pretty clean. The unlucky just turn to dust simultaneously on the spot. No messiness, no pain, no ruined landscape from war, it just happens, it's done, it's over. Everyone else gets to continue on for 25, 50, 100, however many years until the next Thanos process is necessary to apply again.

twice times a half

If you think about it a bit you will realize there is a problem with the Thanos process. The issue is about the "half the population" requirement. Everyone faces the coin flip, the half risk, which is guaranteed to be random. However in aggregate it is unknown and not guaranteed that the total unlucky coin flips will turn out to be half the population. A simple example with a population of 4 will demonstrate, with tails as the unlucky coin flip result.


Number of TailsPercent Chance this could happen
06.25
125
237.5
325
46.25

So while 2 tails is the most likely outcome (37.5% of the time), Thanos is going to have a problem 62.5% of the time, since the total tails is something other than half the population. When the population gets larger such as millions or billions this problem gets even worse, so although half tails is the most likely total, on its own it is not a likely result.

So what to do? How to make the total also come out to half the population.

I thought about it a bit and figured two possible solutions for Thanos. One not too interesting and one a bit more interesting. The more interesting one involves creating new guiding principles and allows Thanos to be a bit lenient in the process due to those principles.

I will get the less interesting one out of the way first. In the less interesting one, Thanos checks the total of the coin flips. If the total tails is not exactly half the population, the process is discarded. The coin flip process runs repeatedly until the overall total of tails is exactly half the population. So in the population=4 above, if the total tails is not 2, then the whole process resets and repeats until the result is total tails=2. For a large population such as Earth at over 7 billion, the process may have to run a large number of times (like in the thousands or millions) to get the desired aggregate result.

The first solution isn't bad I guess. It does meet the requirement that everyone face the coin flip. It also meets the second requirement that the total number eliminated is half the population. Somehow though the idea of running trails repeatedly isn't quite to the spirit of one time coin flip. I tried to think of an approach that would better meet the requirement to eliminate half overall. Adding a new principle may help. This one might help.
if you survive a coin flip you are safe
That does seem fair to the individual. A one-off coin flip and if you draw heads you're safe, that's it. no further risk. so in that case a Thanos process would actually only eliminate half the population in one case. any overall result of half, or fewer than half, would have to be accepted by the "heads you are safe" principle. so in the example of 4 above, of the total tails comes up 0,1,2 then that's it. in 31.25% of the cases fewer than half were eliminated.

So then Thanos after applying the initial coin flips only has a problem if the total tails is more than half. Here I think there is a way to respect the two principles and get the result down to a (now) maximum of half eliminated in total.

Basically take the group of tails, draw a new random number to adjust down the unlucky to a maximum of half the population. For example suppose the population is 100. After the coin flips there are 56 tails. Take the 56 tails, and for each draw a new random number between 1 and 56. Anyone who draws 51-56 is now safe.

So after the second iteration there should be pretty close to half still unlucky even after the second draw. Check the number remaining at risk. If it is more than half continue the process until the result is half or less. For example suppose in the 100 example, of the 56, 8 of them draw 51-56 and are now safe. That means the final result will be 48 still unlucky who are eliminated.

Or suppose only 4 drew 51-56 (remember it is random, it is not known in advance what the result of a fair random draw will be). In that case 4 are now safe, and the process continues now with 52 at risk, everyone getting a new number 1-52. Eventually and it wouldn't take too long to get a final group who was unlucky repeatedly who are then eliminated and vaporized.

It wasn't directly stated, but there is another principle here
everyone in the at risk group faces the same chance of elimination

At the beginning the at risk group is everyone and the chance of elimination is the coin flip. At it progresses the principle (which is the original Thanos rule that the coin flip applies to everyone) remains in place. Everyone at risk faces the same risk.

I like the second approach. It allows Thanos to be a bit lenient in that usually the overall amount eliminated is less than half. And I think it is the fairest in that the process runs just once overall, and once anyone survives any iteration they are safe and face no further risk.

I think it's an interesting problem. How to both expose everyone to a separate individual coin flip, and also achieve a desired aggregate result that the number eliminated is half the population. I will call it the Thanos problem.

I think it could be a high school applied math problem. My niece said she had a math assignment a few weeks ago to find a situation where they could apply math to solve a problem. I think the Thanos problem would have made a good submission for her high school assignment. It's also useful because it shows how the use of principles can simplify a problem, guide the solution to a problem, and allow a defensible solution to emerge.

--

Update I realized I was overthinking this. This is not at all a difficult problem. The problem can be greatly simplified by posing it this way

how would you implement a Thanos process on a deck of cards?

Well that's pretty easy. Shuffle the deck. Select the top 26 cards as the victims. Done.

So on a larger data set, such as a city or planet. You have access to computing resources and a random number generator. A Thanos process could be implemented as follows:

write the population into some kind of a list. use the random number generator to select one person from the list. the selected person is removed from the list and vaporized. repeat this process until half of the original population has been selected.

so it meets the requirements of a Thanos process. it's fair, the random number generator assures that everyone faces the same equal risk of being selected on each iteration. the total number selected is half of the original population. from start to finish as a whole, each person in the original group faced a coin flip on being selected.

No comments: