Skip to content

Optimal Strategy in a Number Guessing Game

You play a number guessing game in which you must pick a real number x, between 0 and 924. At the same time, the number y is uniformly and randomly selected from the same range. If x is greater than y, then you have to pay the square of the difference between the two numbers. If y is greater than or equal to x, you pay double the difference.

What number should you choose initially?

Solution:

When faced with a number guessing game, you should start by looking at the cost function and the changes that happen when you vary your choice of x. For a fixed value of x, the expected cost is proportional to the sum of areas under the two curves.

Just as we expect, the quadratic side is increasing much faster than the linear one when the value of x increases.

Let f(a)=a^2, g(a)=2\cdot a, (\forall a\in\mathbb{R}) and let Z be the cost of this game.
We want to minimize E[Z] = \displaystyle\int_0^x f(x-y) \frac{1}{924} dy + \displaystyle\int_x^{924} g(y-x) \frac{1}{924} dy

To simplify the above formula of the expectation we use a change of variable, which leads us to the simplified problem of minimizing:

h(x) =- F(0) - G(0) + F(x) + G(924-x)

Where F and G are the primitives of f and g respectively

Derivating the above formula we find a suitable candidate for a minimum: x_0=42, and check that indeed it minimizes our expected loss:

One other solution would be to find the optimal solution using python:

 import scipy.integrate as integrate
 from scipy.optimize import minimize 
 
 ub = 924

 def cost(x,y):
     if y<x:
         return (x-y)**2
     else :
         return (y-x)*2
 
 def f(x):
     return integrate.quad(lambda y: cost(x,y), 0, ub)[0]

 minimize(f, 1).x[0]

Check the video to find out a fast and easy solution to the generalised number-guessing game!

Feel free to share your thoughts and ideas in the Latex-enabled comment section below!

1 thought on “Optimal Strategy in a Number Guessing Game”

  1. Здравствуйте. Помогу решить проблемы с вашим сайтом. С моей помощью ваш сайт может стать значительно более посещаемым и приносящим больший доход. Умею привлекать на сайт целевых посетителей и повышать конверсию. Занимаюсь созданием, доработкой и продвижением сайтов с 2004 года. Работаю как с коммерческими, так и с информационными проектами. Умеренные расценки.

    Занимаюсь я следующим:

    1. Продвижение сайтов в поисковых системах. Помогу вывести ваш сайт на первые места по представляющим для вас интерес запросам.

    2. Исправление ошибок и доработка сайтов. Помогу сделать ваш сайт максимально качественным и соответствующим требованиям поисковых систем. Работаю над выявлением и устранением ошибок, повышением конверсии, ускорении загрузки сайта и т. п. Занимаюсь самыми различными вопросами, от кода и до дизайна.

    3. Создание сайтов. Занимаюсь созданием сайтов различных типов.

    4. Создание, наполнение и продвижение групп и каналов в социальных сетях (youtube, вконтакт, фейсбук и т. д.).

    5. Работа с отзывами. Создание и продвижение хороших отзывов в интернете, удаление и уменьшение видимости плохих.

    6. Различные виды рассылок по выборке из моих баз данных под ваш бизнес. Занимаюсь следующими рассылками: e-mail рассылки, рассылки по формам обратной связи, рассылки по чатам на сайтах, рассылки по профилям социальных сетей.

    7. Существует и многое иное в чем я мог бы вам оказаться полезным.

    Для связи со мной пишите на эту почту: progmikhail85@gmail.com

Leave a Reply

Your email address will not be published. Required fields are marked *