Home
About
Resume
Projects
Links
Blog
Download notebook
{ "cells": [ { "cell_type": "markdown", "id": "a469358e-2f57-4bd6-9c8d-c59f3d77920b", "metadata": {}, "source": [ "### Q52\n", "Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits." ] }, { "cell_type": "code", "execution_count": 1, "id": "62ce1f5d-9a9e-4fca-9713-10e7c3085bbd", "metadata": {}, "outputs": [], "source": [ "def smallest_permuted_multiples(n):\n", " if n < 2:\n", " return 1\n", " for i in range(10**(n-1),10**9):\n", " base_i = sorted(str(i))\n", " for j in range(2,n+1):\n", " if sorted(str(i*j)) != base_i:\n", " break\n", " else:\n", " return i" ] }, { "cell_type": "code", "execution_count": 2, "id": "60a03530-995d-4e60-872e-ecc2f17520ca", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 35.3 ms, sys: 37 µs, total: 35.4 ms\n", "Wall time: 31.7 ms\n" ] }, { "data": { "text/plain": [ "142857" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%%time\n", "smallest_permuted_multiples(6)" ] }, { "cell_type": "code", "execution_count": null, "id": "bd7ddc2f-5964-49c3-a927-774399b0b0a9", "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 Q51
Next Notebook:
Project Euler Q53
Loading