Skip to content

Instantly share code, notes, and snippets.

@cjb230
Last active August 16, 2020 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjb230/c9c378c8e9c5567c299203a9a5a26849 to your computer and use it in GitHub Desktop.
Save cjb230/c9c378c8e9c5567c299203a9a5a26849 to your computer and use it in GitHub Desktop.
Riddler Classic for 2020-08-14
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://fivethirtyeight.com/features/are-you-hip-enough-to-be-square/ :\n",
"\n",
"\"The Riddler Manufacturing Company makes all sorts of mathematical tools: compasses, protractors, slide rules — you name it!\n",
"\n",
"Recently, there was an issue with the production of foot-long rulers. It seems that each ruler was accidentally sliced at three random points along the ruler, resulting in four pieces. Looking on the bright side, that means there are now four times as many rulers — they just happen to have different lengths.\n",
"\n",
"On average, how long are the pieces that contain the 6-inch mark?\"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the rulers in two halves, 0 to <6 inches, and >= 6 inches to 12 inches.\n",
"\n",
"The lower half of the ruler can have 0, 1, 2, or 3 slices in it. The number of slices in the lower half determines the number of slices in the upper half.\n",
"\n",
"Each of the three slices can be in the upper half or lower half of the ruler, with equal probability. So there are 2^3 = 8 possible distributions of the slices over the two halves.\n",
"\n",
"Now forget about whether a half of the ruler is the \"bottom half\" or the \"top half\". One quarter of the possible slice distributions have three slices on one half and none on the other half. So three quarters of the distributions have one slice in one half, and two in the other."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the quarter of rulers with three breaks in one half and none in the other, the length of the section containing the six-inch mark is:\n",
" six inches (from one half of the ruler) plus one-quarter of six inches (one of the four sections of the other half of the ruler)\n",
" \n",
" = 6 + (0.25 * 6) inches\n",
" \n",
" = 7.5 inches"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the three-quarters of rulers with one break in one half and two in the other, the length of the section containing the six-inch mark is:\n",
" (one half of one half of the ruler) + (one half of one third of the ruler)\n",
" \n",
" = (12 * 0.5 * 0.5) + (12 * 0.5 * (1/3)) inches\n",
"\n",
" = 6 * (0.5 + (1/3)) inches\n",
"\n",
" = 6 * (5/6) inches\n",
" \n",
" = 5 inches"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Adding the two in the correct ratios, the average length is:\n",
" \n",
" (0.25 * 7.5) + (0.75 * 5) = 5.625 inches\n",
"\n",
"5.625 is five and five-eighths"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A quick check with brute force comes up with a similar answer. The variable in the first line can be altered to change the number of trials."
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average length of piece containing six-inch mark, from 100000 trials:\n",
"5.620855143798455 inches\n"
]
}
],
"source": [
"iters = 100000\n",
"results = list()\n",
"\n",
"for i in range(iters):\n",
" these_rands = [random.uniform(0,12) for i in range(3)]\n",
" min_rand = min(these_rands)\n",
" these_rands.remove(min_rand)\n",
" max_rand = max(these_rands)\n",
" these_rands.remove(max_rand)\n",
" mid_rand = these_rands.pop()\n",
" if min_rand > 6:\n",
" this_result = min_rand\n",
" elif max_rand < 6:\n",
" this_result = 12 - max_rand\n",
" elif mid_rand < 6:\n",
" this_result = max_rand - mid_rand\n",
" elif mid_rand > 6:\n",
" this_result = mid_rand - min_rand\n",
" results.append(this_result)\n",
"\n",
"res_len = len(results)\n",
"res_sum = sum(results)\n",
"\n",
"print(\"Average length of piece containing six-inch mark, from \" + str(iters) + \" trials:\")\n",
"print(str(res_sum / res_len) + \" inches\")\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(I found that 100 000 trials would give an answer correct to 2 s.f. and often 3 s.f. One million trials is normally correct to 3 s.f., but takes more than a second to run.)"
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment