Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
probability_questions.ipynb
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"colab": {
"name": "probability_questions.ipynb",
"provenance": [],
"include_colab_link": true
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/wyseow/594c6c54d073f910ac22e4ca76a23891/probability_questions.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "-DYQtb58O0KF"
},
"source": [
"# Questions to test your Conditional Probability and Bayes Thereom knowledge"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0CW_aBH_O0KK"
},
"source": [
"## N Die"
]
},
{
"cell_type": "code",
"metadata": {
"id": "gMXz0FZAO0KK"
},
"source": [
"# Let's say you're playing a dice game. You have 2 die.\n",
"# 1. What's the probability of rolling at least one 3?\n",
"# 2. What's the probability of rolling at least one 3 given N die?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "qThEJZ8dO0KR"
},
"source": [
"# Answer #1:\n",
"# complementary approach\n",
"# 1 - P(no 3)\n",
"# p(no 3) = 5/6 * 5/6\n",
"# 1 - (5/6 * 5/6)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "dq0SeeriO0KS"
},
"source": [
"$$\n",
"1-(\\frac{5}{6})^2\n",
"= \\frac{11}{36}\n",
"$$"
]
},
{
"cell_type": "code",
"metadata": {
"id": "TAUHuzOwO0KS"
},
"source": [
"# Answer #2: \n",
"# We would need to multiple 5/6 for N times for N dice\n",
"# 1 - (5/6 * 5/6 * ... N)\n",
"# 1- (5/6)^N"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "kJwqE5BSO0KT"
},
"source": [
"$$\n",
"1-(\\frac{5}{6})^N\n",
"$$"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "EGHRmjsqO0KT"
},
"source": [
"## Ad Raters"
]
},
{
"cell_type": "code",
"metadata": {
"id": "LOsXLTx4O0KT"
},
"source": [
"# Let's say we use people to rate ads.\n",
"\n",
"# There are two types of raters. Random and independent from our point of view:\n",
"\n",
"# 80% of raters are careful and they rate an ad as good (60% chance) or bad (40% chance). \n",
"# 20% of raters are lazy and they rate every ad as good (100% chance).\n",
"\n",
"# 1. Suppose we have 100 raters each rating one ad independently. What's the expected number of good ads?\n",
"# 2. Now suppose we have 1 rater rating 100 ads. What's the expected number of good ads?\n",
"# 3. Suppose we have 1 ad, rated as bad. What's the probability the rater was lazy?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "9AutkV2_O0KT"
},
"source": [
"# Answer #1:\n",
"# 2 branches (careful and lazy), combined 100 raters\n",
"# careful: 60% of 80 raters = 6/10 * 80 = 48 raters\n",
"# lazy: 100% of 20 raters = 20 raters\n",
"# exp number of good ads = 48+20 = 68 "
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "V-XNNjHBO0KU"
},
"source": [
"# Answer #2:\n",
"# actually same answer as question 1: 100 raters with 1 ad = 1 rater with 100 ads"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "xp4Yqc_4O0KU"
},
"source": [
"# Answer #3:\n",
"# 0 because all lazy raters rate all ads as good"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "TJ6EfP2xO0KU"
},
"source": [
"## Second Ace"
]
},
{
"cell_type": "code",
"metadata": {
"id": "NTj1EgoOO0KW"
},
"source": [
"# Let's say you have to draw two cards from a shuffled deck, one at a time.\n",
"# What's the probability that the second card is not an Ace?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "aPSTC9BAO0KX"
},
"source": [
"# assumption: card is drawn without replacement\n",
"# we have to consider whether first card is ace or not, therefore we have 2 scenarios(branches):\n",
"# 1. Drawing an ace on the first card and an ace on the second card\n",
"# 2. Drawing not an ace on the first card and an ace on the second card\n",
"# Answer:"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "h1sE6wpUO0KY"
},
"source": [
"<img src='http://datageeko.com/imgs/sec_ace_diagram.jpg?_t=1609298009'/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6kipNcibO0Kd"
},
"source": [
"## Profit-Maximizing Dice Game"
]
},
{
"cell_type": "code",
"metadata": {
"id": "EU81ktPHO0Ke"
},
"source": [
"\n",
"# You're playing casino dice game. You roll a die once. If you reroll, you earn the amount equal to the \n",
"# number on your second roll otherwise, you earn the amount equal to the number on your first roll.\n",
"\n",
"# Assuming you adopt a profit-maximizing strategy, what would be the expected amount of money you would win?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "0aJGPFs4O0Ke"
},
"source": [
"# assumption the die has 6 faces\n",
"# If the first roll already yields a 4, 5 or 6, then its risky to roll again. otherwise, re-roll.\n",
"# 2 scenarios: 1) first roll is 1,2,3 then reroll\n",
"# 2) first roll is 4,5,6 then stop.\n",
"# exp money for 1st die(avg $ if we roll 100x) = exp value for 1 die = (1+2+3+4+5+6)/6 = 3.5\n",
"# exp money for 2nd die = $3.5, but if we get 4,5,6 then E = $5\n",
"# in a 2 roll scenario: 50% chance of getting 1,2,3 in 1st dice(0.5*3.5) + \n",
"# 50% chance of getting 4,5,6 in 2nd dice(0.5*5) = $4.25"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "GslbjoVrO0Kf"
},
"source": [
"# Further reference:\n",
"# https://math.stackexchange.com/questions/179534/the-expected-payoff-of-a-dice-game\n",
"# https://www.youtube.com/watch?v=yRWpNRrHtuU"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"scrolled": true,
"id": "8cR0paTXO0Kf",
"outputId": "cd3e5a57-c8ce-4b89-e0f3-256686c9408d"
},
"source": [
"# simulation\n",
"import numpy as np\n",
"for threshold in range(1, 6):\n",
" #print('threshold:',threshold)\n",
" rolls = np.random.randint(1, 7, size=10000)\n",
" #print('rolls:',rolls)\n",
" rerolls = np.random.randint(1, 7, size=10000)\n",
" #print('rerolls:',rerolls)\n",
" #print(np.where(rolls <= threshold, rerolls, rolls))\n",
" avg_roll = np.mean(np.where(rolls <= threshold, rerolls, rolls))\n",
" print(f'Rerolling all {threshold}s and below yields and average roll of {avg_roll}.')\n",
" "
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Rerolling all 1s and below yields and average roll of 3.9128.\n",
"Rerolling all 2s and below yields and average roll of 4.1491.\n",
"Rerolling all 3s and below yields and average roll of 4.2595.\n",
"Rerolling all 4s and below yields and average roll of 4.139.\n",
"Rerolling all 5s and below yields and average roll of 3.9086.\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "FcbVaWXpO0LK"
},
"source": [
"## Marble Bucket"
]
},
{
"cell_type": "code",
"metadata": {
"id": "0H7sx-8SO0LL"
},
"source": [
"# We have two buckets full of marbles. There are 30 red marbles and 10 black marbles in Bucket #1 and 20 red and \n",
"# 20 Black marbles in Bucket #2. Your friend secretly pulls a marble from one of the two buckets and \n",
"# shows you that the marble is red.\n",
"\n",
"# 1. What is the probability that it was pulled from Bucket #1?\n",
"# 2. Let's say your friend picks two marbles instead and they both happen to be red. \n",
"# What is the probability that they both came from Bucket #1?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "cGgVX7KlO0LL",
"outputId": "6da15b8b-ed33-4395-9f67-fad68e6edb26"
},
"source": [
"# Answer #1:\n",
"# we assume that probability of choosing each bucket is fair\n",
"# we could use bayes thereom\n",
"# P(B1|R) = P(R|B1)*P(B1)/P(R)\n",
"((30/40) * 0.5)/(5/8)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.6"
]
},
"metadata": {
"tags": []
},
"execution_count": 42
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "32xW3Xm9O0LM",
"outputId": "a9a530cd-3fac-4754-fb04-7e0327e42dbf"
},
"source": [
"# or we could just use simple logic\n",
"# number of red marbles in bucket1/number of red marbles in ALL buckets\n",
"30/50"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.6"
]
},
"metadata": {
"tags": []
},
"execution_count": 43
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "7JERwGwLO0LM",
"outputId": "a823596e-c016-4ee5-a0a1-bdace30a8034"
},
"source": [
"# Answer #2:\n",
"# we assume draw WITHOUT replacement\n",
"# P(draw red marble in bucket1) * P(draw red marble in bucket1)\n",
"(30/50) * (29/50)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0.348"
]
},
"metadata": {
"tags": []
},
"execution_count": 44
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "RHgcU_RzO0LN"
},
"source": [
"## Lazy Raters"
]
},
{
"cell_type": "code",
"metadata": {
"id": "EVJbNVT2O0LN"
},
"source": [
"\n",
"# Netflix has hired people to rate movies.\n",
"# Out of all of the raters, 80% of the raters carefully rate movies and rate 60% of the movies as good and 40% as bad. \n",
"# The other 20% are lazy raters and rate 100% of the movies as good.\n",
"\n",
"# Assumming all raters rate the same amount of movies, what is the probability that a movie is rated good?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "OQnx4ZUHO0LN"
},
"source": [
"<img src='http://datageeko.com/imgs/raters_diagram.jpg?_t=1609315617'/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Os2-mIyPO0LN"
},
"source": [
"## Three Zebras"
]
},
{
"cell_type": "code",
"metadata": {
"id": "aiQftSk6O0LO"
},
"source": [
"\n",
"# Three zebras are chilling in the desert. Suddenly a lion attacks.\n",
"# Each zebra is sitting on a corner of an equally length triangle. \n",
"# Each zebra randomly picks a direction and only runs along the outline of the triangle to either edge of the triangle.\n",
"\n",
"# What is the probability that none of the zebras collide?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "SfTOg7z-O0LO"
},
"source": [
"<img src='http://datageeko.com/imgs/zebra_diagram.jpg?_t=1609320002'/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "wCzJPPmtO0LO"
},
"source": [
"## Coin Flip Probability"
]
},
{
"cell_type": "code",
"metadata": {
"id": "eoStQ9Q7O0LO"
},
"source": [
"\n",
"# Let's say you are playing a coin flip game. You start with $30. If you flip heads, you win $1, \n",
"# but if you get tails, you lose $1. You keep playing until you run out of money (have $0) or until you win $100. \n",
"\n",
"# What is the probability that you win $100?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "ghRZp6H5O0LP"
},
"source": [
"# win = get 70 heads out of N flips= +$70\n",
"# solution unknown ;("
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "5baOBx-BO0LP"
},
"source": [
"## Poker Pair\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "-T5iYLiwO0LP"
},
"source": [
"\n",
"# Imagine a poker game. Let's say that you're drawing N cards from a deck of 52 cards.\n",
"# Compute the probability that you will get a pair from your hand of N cards."
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "wTXy4SqoO0LP"
},
"source": [
"# Answer:\n",
"# assume that the definition of a pair = 2 cards of the same rank\n",
"# pair of same rank: 4/52 * 3/51\n",
"# "
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "MGk8F866O0LP"
},
"source": [
"## Same Side Probability"
]
},
{
"cell_type": "code",
"metadata": {
"id": "aAERF6geO0LQ"
},
"source": [
"\n",
"# Suppose we have two coins. One is fair and the other biased where the probability of it coming up heads is 3/4.\n",
"\n",
"# Let's say we select a coin at random and flip it two times. What is the probability that both flips \n",
"# result in the same side?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "56ViTgnOO0LQ"
},
"source": [
"<img src='http://datageeko.com/imgs/same_side_diagram.jpg?t=1243' width=500/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CNhNyIF6O0LQ"
},
"source": [
"## Biased five out of six"
]
},
{
"cell_type": "code",
"metadata": {
"id": "0j_IRChXO0LQ"
},
"source": [
"\n",
"# Let's say we're given a biased coin that comes up heads 30% of the time when tossed.\n",
"\n",
"# What is the probability of the coin landing as heads exactly 5 times out of 6 tosses?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "E3GOWG-wO0LQ"
},
"source": [
"<img src='http://datageeko.com/imgs/five_six_binomial.jpg?_t=1609396499' width=500/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "mKTz-k17O0LR"
},
"source": [
"## Four Person Elevator"
]
},
{
"cell_type": "code",
"metadata": {
"id": "TpjgSnVTO0LR"
},
"source": [
"\n",
"# There are four people on the ground floor of a building that has five levels not including the ground floor. \n",
"# They all get into the same elevator.\n",
"\n",
"# If each person is equally likely to get on any floor and they leave independently of each other, \n",
"# what is the probability that no two passengers will get off at the same floor?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "f_PGc9zGO0LR"
},
"source": [
"# Answer: \n",
"# no two persons get off at same floor = everyone get off at their own floor\n",
"# proba = everyone get off at their own floor/all possible get off combinations\n",
"\n",
"# demo; all possible get off permutations = 5*5*5*5 (diff order counted=permutations), \n",
"# because: 1st per. can have 5 floors to get off, 2nd person. can have 5 floors to get off...\n",
"\n",
"# numer; everyone go off at their own floor = 5*4*3*2\n",
"# b'cos: 1st per. choose 5 floors to get off, then 2nd can only choose from 4 floors, 3rd person only choose from 3 floors...\n",
"\n",
"# therefore: 5*4*3*2/5*5*5*5 = 120/625 = 0.192\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "mwUJ_narO0LR"
},
"source": [
"## Random Feed Function"
]
},
{
"cell_type": "code",
"metadata": {
"id": "ZQwWcYItO0LR"
},
"source": [
" \n",
"# Let's say you have a function that outputs a random integer between a minimum value, N, and maximum value, M. \n",
"# Now let's say we take the output from the random integer function and place it into another random \n",
"# function as the max value with the same min value N. \n",
"\n",
"# 1. What would the distribution of the samples look like?\n",
"# 2. What would be the expected value?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"scrolled": true,
"id": "D5ooQfUMO0LR"
},
"source": [
"N = 1\n",
"M = 10\n",
"original = np.zeros(100)\n",
"res = np.zeros(100)\n",
"for _ in range(100):\n",
" x = np.random.randint(low = N ,high = M)\n",
" original[_] = x\n",
" y = np.random.randint(low = N, high = x+1)\n",
" res[_] = y"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "vzuZFRAVO0LS"
},
"source": [
"import matplotlib.pyplot as plt"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "XJc0_39JO0LS",
"outputId": "6426d5d3-272f-462f-a874-29ed9c4b1879"
},
"source": [
"# Answer #1\n",
"plt.hist(res)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(array([41., 22., 13., 0., 12., 4., 0., 4., 3., 1.]),\n",
" array([1. , 1.7, 2.4, 3.1, 3.8, 4.5, 5.2, 5.9, 6.6, 7.3, 8. ]),\n",
" <a list of 10 Patch objects>)"
]
},
"metadata": {
"tags": []
},
"execution_count": 67
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8li6FKAAAPbUlEQVR4nO3db4xldX3H8fenu2tB1ILllmxZ7BA1GGLiYqarFmMsiEEwiolpJK3hAcnaRBuopnb1STVpG0hU7IPGZGWRbUpR5E8wYK0bXENJLHQWF1hYjIir7nZlxyiFbRot8O2DezaOw8zcuzP3zp0fvF/JzZ5z7rn3fJiwnz3zO/9SVUiS2vNbkw4gSVoeC1ySGmWBS1KjLHBJapQFLkmNWr+aGzv11FNrampqNTcpSc3bs2fPz6qqN3/5qhb41NQUMzMzq7lJSWpekh8ttNwhFElqlAUuSY2ywCWpURa4JDXKApekRlngktQoC1ySGmWBS1KjLHBJatSqXom5ElPb7pzYtg9cdfHEti1Ji3EPXJIaNXSBJ1mX5LtJ7ujmz0xyb5LHknwlyUvGF1OSNN/x7IFfAeyfM381cE1VvQb4BXD5KINJkpY2VIEn2QRcDFzbzQc4D7i5W2UncMk4AkqSFjbsHvjngY8Dz3Xzvws8WVXPdPMHgdMX+mCSrUlmkszMzs6uKKwk6dcGFniSdwNHqmrPcjZQVdurarqqpnu9592PXJK0TMOcRngu8J4kFwEnAK8A/gE4Ocn6bi98E3BofDElSfMN3AOvqk9U1aaqmgI+AHyrqv4U2A28v1vtMuD2saWUJD3PSs4D/2vgo0keoz8mvmM0kSRJwziuKzGr6tvAt7vpx4Eto48kSRqGV2JKUqMscElqlAUuSY2ywCWpURa4JDXKApekRlngktQoC1ySGmWBS1KjLHBJapQFLkmNssAlqVEWuCQ1ygKXpEZZ4JLUKAtck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cC3yQ/t7hsVOcLpp0qCVsBHYneZD+vW12VdWaPz2vEacB9yR5ALgPuLOqvjHhTEv5C+CG7v+FzcDfTzjPkrp/FC+gv0e7ZnW/1dwM3A88RL9zR3ZJ/Zo/jVCStLA1vwcuSVqYBS5JjbLAJalRFrgkNcoCl6RGWeCS1CgLXJIa9f+aLvRea/ATxAAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "w148-g6SO0LS",
"outputId": "fa589452-437a-41f7-cdaf-84f02eddf74c"
},
"source": [
"# Answer #2\n",
"np.mean(res)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"3.42"
]
},
"metadata": {
"tags": []
},
"execution_count": 71
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_I5Btth9O0LT"
},
"source": [
"## Fake Algorithm Reviews"
]
},
{
"cell_type": "code",
"metadata": {
"id": "ghyKnMs4O0LT"
},
"source": [
"# Let's say we're trying to determine fake reviews on our products. \n",
"\n",
"# Based on past data, 98% reviews are legitimate and 2% are fake. \n",
"# If a review is fake, there is 95% chance that the machine learning algorithm identifies it as fake. \n",
"# If a review is legitimate, there is a 90% chance that the machine learning algorithm identifies it as legitimate.\n",
"\n",
"# What is the percentage chance the review is actually fake when the algorithm detects it as fake?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "v_fq3z89O0LT"
},
"source": [
"<img src='http://datageeko.com/imgs/fake_algo.jpg?_t=1609674526' width=500/>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "eYUWwey1O0LT"
},
"source": [
"#https://stackoverflow.com/questions/61262145/conditional-probability-for-fake-reviews"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "nWyHdWdpO0LU"
},
"source": [
"## Impression Reach"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Px1qmipxO0LU"
},
"source": [
"# Let's say we have a very naive advertising platform. Given an audience of size A and an impression size of B, \n",
"# each user in the audience is given the same random chance of seeing an impression. \n",
"\n",
"# 1. Compute the probability that a user sees exactly 0 impressions. \n",
"\n",
"# 2. What's the expected value of each person receiving at least 1 impression?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "6e2ZHqq6O0LU"
},
"source": [
"<img src='http://datageeko.com/imgs/impr_binomial.jpg?_t=1609724844'/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "BrslB7VQO0LU"
},
"source": [
"# Questions that test your Permutations and Combinations knowledge"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "WjKNIoJVO0LU"
},
"source": [
"## Phone Number"
]
},
{
"cell_type": "code",
"metadata": {
"id": "LhMyAUdeO0LU"
},
"source": [
"# https://gpuzzles.com/questions/interview/list/permutation-combination-puzzles-answers/\n",
"\n",
"# How many six digit phone numbers can you frame using the digits from 0 to 9 if a condition restricts \n",
"# you to start the number with 35 and another condition restricts you from using any digit more than once?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "NA2GhXXvO0LV"
},
"source": [
"<img src='http://datageeko.com/imgs/phone_number.jpg?_t=1609674526' width=500/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "kfiD0XJzO0LV"
},
"source": [
"## Distributing Chocolates"
]
},
{
"cell_type": "code",
"metadata": {
"id": "B6H39XzOO0LV"
},
"source": [
"# https://gpuzzles.com/interview/aptitude/distributing-chocolates-interview-puzzle/\n",
"\n",
"# It is Nicole Kidman's birthday today and she wants to distribute chocolates among her friends. \n",
"# She has 56 chocolates and she has to distribute it to A, B, C, D and E.\n",
"\n",
"# Calculate the number of distinct ways in which she can distribute in a manner that no person \n",
"# receives less than 10 chocolates?"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "dO-gEtA7O0LW"
},
"source": [
"<img src='http://datageeko.com/imgs/choco5.jpg?_t=1609674526'/>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "EoUchLRtO0LW"
},
"source": [
"More questions @\n",
" http://www.allindiaexams.in/aptitude-questions-and-answers/permutations-and-combinations/2"
]
},
{
"cell_type": "code",
"metadata": {
"id": "gjf7sRaBO0LX"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment