{ "cells": [ { "cell_type": "code", "execution_count": 34, "id": "afcfc049", "metadata": {}, "outputs": [], "source": [ "import re\n", "\n", "orbits = \"\"\"\n", "Mercury: 88 days.\n", "Venus: 225 days.\n", "Earth: 365 days.\n", "Mars: 687 days.\n", "Jupiter: 4333 days.\n", "Saturn: 10759 days.\n", "Uranus: 30687 days.\n", "Neptune: 60190 days.\n", "\"\"\".splitlines()" ] }, { "cell_type": "code", "execution_count": 36, "id": "c0665887", "metadata": {}, "outputs": [], "source": [ "ratios = [int((re.findall(r'\\d+', x)[0:1] or [0])[0])/88 for x in orbits][1:]" ] }, { "cell_type": "code", "execution_count": 39, "id": "56eb1e3f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1.0,\n", " 6.307132459970888,\n", " 15.660844250363901,\n", " 44.66812227074236,\n", " 87.61280931586609]" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[x / ratios[3] for x in ratios[3:]]" ] }, { "cell_type": "code", "execution_count": 41, "id": "8401b303", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1.0,\n", " 1.5990053726670783,\n", " 2.036596983383623,\n", " 2.794068392473273,\n", " 7.017024751533684,\n", " 11.0571860632063,\n", " 18.67393662543892,\n", " 26.152959158138735]" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import math\n", "[math.sqrt(x) for x in ratios]" ] }, { "cell_type": "code", "execution_count": 42, "id": "85f986fc", "metadata": {}, "outputs": [], "source": [ "dist = \"\"\"The distance from the Sun to Mercury is 0.39 AU, to Venus is 0.72 AU, to Earth is 1.00 AU, to Mars is 1.52 AU, to Jupiter is 5.20 AU, to Saturn is 9.54 AU, to Uranus is 19.22 AU, and to Neptune is 30.06 AU.\"\"\"" ] }, { "cell_type": "code", "execution_count": 56, "id": "7c321d05", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[5.875871902123325,\n", " 15.072438995419457,\n", " 20.0,\n", " 26.280655022872775,\n", " 44.729879383810726,\n", " 53.83240228190293,\n", " 64.3392710531322,\n", " 71.04793076487243]" ] }, "execution_count": 56, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[20 + 1.5 * math.log(float(x))*10 for x in re.findall(r'[0-9]+.\\d+', dist)]" ] }, { "cell_type": "code", "execution_count": 60, "id": "36ce6b46", "metadata": {}, "outputs": [], "source": [ "planets = [\n", " ('mercury', 1.0, 50),\n", " ('venus', 1.6, 130),\n", " ('earth', 2.0, 200),\n", " ('mars', 2.8, 270),\n", " ('jupiter', 7.0, 450),\n", " ('saturn', 11, 540),\n", " ('uranus', 18, 640),\n", " ('neptune', 26, 710),\n", "]" ] }, { "cell_type": "code", "execution_count": 64, "id": "6a36fcb8", "metadata": {}, "outputs": [], "source": [ "def b():\n", " prevp = 1.0\n", " for n, p, d in planets:\n", " yield p / prevp\n", " prevp = p\n", " \n", "ratios = list(b())" ] }, { "cell_type": "code", "execution_count": 89, "id": "5f6e6b6b", "metadata": {}, "outputs": [], "source": [ "scale = 5\n", "\n", "tooth_width = 0.8;\n", "tooth_crop = 0.5;\n", "tooth_thickness = 0.6;\n", "\n", "def gear_base_radius(n):\n", " perimeter = tooth_width * (1 + 0.8*(1-tooth_crop)) * n\n", " return perimeter / math.pi / 2;\n", "\n", "def gear_wheel_radius(n):\n", " return math.sqrt(gear_base_radius(n)**2 + (tooth_width/2)**2);\n", "\n", "def gear_radius(n):\n", " return scale * (gear_wheel_radius(n) + gear_base_radius(n) + tooth_crop)/2;\n", "\n", "def dcenter(n1, n2):\n", " return gear_radius(n1) + gear_radius(n2)\n", "\n", "def search():\n", " for n1 in range(11, 39):\n", " n2 = 50 - n1\n", " yield (n1, n2, n2 / n1, dcenter(n1, n2))\n", " \n", "rr = list(search())" ] }, { "cell_type": "code", "execution_count": 92, "id": "b64daa46", "metadata": {}, "outputs": [], "source": [ "def found():\n", " for r in ratios:\n", " for n1, n2, tr, _ in rr:\n", " if tr < r:\n", " yield (n1, n2, r, tr)\n", " break" ] }, { "cell_type": "code", "execution_count": 93, "id": "c587ff67", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(26, 24, 1.0, 0.9230769230769231),\n", " (20, 30, 1.6, 1.5),\n", " (23, 27, 1.25, 1.173913043478261),\n", " (21, 29, 1.4, 1.380952380952381),\n", " (15, 35, 2.5, 2.3333333333333335),\n", " (20, 30, 1.5714285714285714, 1.5),\n", " (19, 31, 1.6363636363636365, 1.631578947368421),\n", " (21, 29, 1.4444444444444444, 1.380952380952381)]" ] }, "execution_count": 93, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(found())" ] }, { "cell_type": "code", "execution_count": 81, "id": "2d7d6f8b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(11, 39, 3.5454545454545454, 47.19308954151068),\n", " (12, 38, 3.1666666666666665, 47.18558098978421),\n", " (13, 37, 2.8461538461538463, 47.179354476011646),\n", " (14, 36, 2.5714285714285716, 47.17415487784531),\n", " (15, 35, 2.3333333333333335, 47.16979419516311),\n", " (16, 34, 2.125, 47.166131477877656),\n", " (17, 33, 1.9411764705882353, 47.16305960247725),\n", " (18, 32, 1.7777777777777777, 47.16049634511566),\n", " (19, 31, 1.631578947368421, 47.158378230688704),\n", " (20, 30, 1.5, 47.15665622507779),\n", " (21, 29, 1.380952380952381, 47.15529268372393),\n", " (22, 28, 1.2727272727272727, 47.154259179645024),\n", " (23, 27, 1.173913043478261, 47.15353496521375),\n", " (24, 26, 1.0833333333333333, 47.15310590655676),\n", " (25, 25, 1.0, 47.15296378588499),\n", " (26, 24, 0.9230769230769231, 47.15310590655676),\n", " (27, 23, 0.8518518518518519, 47.15353496521375),\n", " (28, 22, 0.7857142857142857, 47.154259179645024),\n", " (29, 21, 0.7241379310344828, 47.15529268372393),\n", " (30, 20, 0.6666666666666666, 47.15665622507779),\n", " (31, 19, 0.6129032258064516, 47.158378230688704),\n", " (32, 18, 0.5625, 47.16049634511566),\n", " (33, 17, 0.5151515151515151, 47.16305960247725),\n", " (34, 16, 0.47058823529411764, 47.166131477877656),\n", " (35, 15, 0.42857142857142855, 47.16979419516311),\n", " (36, 14, 0.3888888888888889, 47.17415487784531),\n", " (37, 13, 0.35135135135135137, 47.179354476011646),\n", " (38, 12, 0.3157894736842105, 47.18558098978421)]" ] }, "execution_count": 81, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "8c2dca2a", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.8" } }, "nbformat": 4, "nbformat_minor": 5 }