Given the popularity of game of thrones, a friend of mine came up with a riddle based on the events of episode 3.



Fun riddle inspired by the upcoming battle in Game of Thrones:

– H humans vs W white walkers(simplifying)

– We pick a creature at random and let it kill an opponent: if a walker, it disappears; if human,it turns into walker. Repeat.

How many humans does it take to beat W walkers? — Ferran Alet (@FerranAlet) April 27, 2019

The riddle itself

Because of twitter restrictions the problem isn’t properly formulated so here is a more concise version:

The army of white walkers is made up of W white walkers.

The human army is made up of H soldiers.

Every time step, we pick someone at random and he kills someone from the opposite army, i.e if we pick a white walker it kills a human and vice-versa.

When a white walker kills a human the human transforms into a white walker.

When a human kills a white walker, the white walker disappears.

Given this rules, and a number of white walkers, what is the minimum number of humans you need to have an even outcome. That is that the probability of each side winning is approximately 50%.

The tree approach

One approach to this solution is to to use recursion. While it is not computationally efficient is a valid and simple solution.







Here we are declaring all the possible outcomes with any leaf nodes the final outcome of the battle (+1 if the humans win and -1 if the white walkers win).

By multiplying the odds of each individual event (death) that lead to an outcome we can find out if the events are balanced.

If we imagine only being 1 human and 1 white walker then the here we will wee that being a balanced battle as both sides have (almost) the same odds of winning.

If we implement this in Python using recursion with memorization (because the order of deaths does not affect the final outcome) making this much easier to compute, as we are not repeating states now we go from complexity to :

import sys sys.setrecursionlimit(5001) W = int(sys.argv[1]) __CACHED = dict() def f(h, w): if h == 0: return -1 if w == 0: return 1 if (h,w) in __CACHED: return __CACHED[(h,w)] a = (float(h)/(h+w))*f(h, w-1) b = (float(w)/(w+h))*f(h-1, w+1) __CACHED[(h,w)] = a+b return __CACHED[(h,w)] for i in range(sys.argv[2]): print("{},{}".format(i, f(i, W))) """If we wanted the actual number we could have if f(i,W) > 0: print('Needed humans for even fight against {} white walkers: {}'.format(W, i)) """

When running the above code for 10, 100 and 1000 white walkers with 0-2000 humans we get the following plots:

This plot shows the output of function f(h,w) for 10, 100 and 1000 white walkers.

To understand this graph “-1” means 100% of scenarios the white walkers win, “+1” mean 100% of scenarios humans win. Therefore, an even battle is when . In these cases it is 16, 161 and 1619 respectively.

Funny enough the proportion of humans needed for an even battle is about 1.618 which is converging to the golden ratio.

Another way we came up to solve this problem is using expected values, which my friend posted about here.

Can you came up with a better solution?