Home
About
Resume
Projects
Links
Blog
Download notebook
{ "cells": [ { "cell_type": "markdown", "id": "a469358e-2f57-4bd6-9c8d-c59f3d77920b", "metadata": {}, "source": [ "### Q57\n", "In the first one-thousand expansions, how many fractions contain a numerator with more digits than denominator?" ] }, { "cell_type": "code", "execution_count": 1, "id": "bd7ddc2f-5964-49c3-a927-774399b0b0a9", "metadata": {}, "outputs": [], "source": [ "def longer_numerator_than_denominator_in_range_n(n):\n", " numerator, denominator = 1, 1\n", " result = 0\n", " for _ in range(n):\n", " numerator,denominator = numerator+2*denominator, numerator+denominator\n", " if len(str(numerator)) > len(str(denominator)):\n", " result += 1\n", " return result" ] }, { "cell_type": "code", "execution_count": 2, "id": "3e78fa42-856e-4722-a279-245d9b8516a5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 1.12 ms, sys: 321 µs, total: 1.45 ms\n", "Wall time: 1.45 ms\n" ] }, { "data": { "text/plain": [ "153" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%%time\n", "longer_numerator_than_denominator_in_range_n(1000)" ] }, { "cell_type": "code", "execution_count": null, "id": "b869eac9-8c59-4a32-a226-a1308dec4e4c", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }
Previous Notebook:
Project Euler Q56
Next Notebook:
Project Euler Q58
Loading