{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Price a dice game\n", "\n", "Simulate the reroll game and check that its fair price is 4.25." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "import sys\n", "\n", "if \"google.colab\" in sys.modules:\n", " %pip install -q numpy" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "rng = np.random.default_rng(2026)\n", "first = rng.integers(1, 7, size=100_000)\n", "second = rng.integers(1, 7, size=100_000)\n", "payout = np.where(first <= 3, second, first)\n", "print(f\"simulated {payout.mean():.3f}, exact 4.250\")\n", "print(f\"variance {payout.var():.3f}\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }