From ac81a63d83710f7451143d3856aa3a33ef8f8abe Mon Sep 17 00:00:00 2001 From: filifa Date: Mon, 21 Apr 2025 20:36:50 -0400 Subject: [PATCH] add problem 38 --- notebooks/problem0038.ipynb | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 notebooks/problem0038.ipynb diff --git a/notebooks/problem0038.ipynb b/notebooks/problem0038.ipynb new file mode 100644 index 0000000..79757ab --- /dev/null +++ b/notebooks/problem0038.ipynb @@ -0,0 +1,74 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d5ba1893", + "metadata": {}, + "source": [ + "# [Pandigital Multiples](https://projecteuler.net/problem=38)\n", + "\n", + "Any number with five or more digits will have a concatenated product with more than 9 digits. Therefore we only need to check numbers with less than five digits." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ffea7112", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "932718654" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from itertools import count\n", + "\n", + "def is_pandigital(s):\n", + " return ''.join(sorted(s)) == \"123456789\"\n", + "\n", + "\n", + "pandigitals = set()\n", + "for k in range(1, 10000):\n", + " s = \"\"\n", + " for n in count(1):\n", + " s += str(k * n)\n", + " if len(s) >= 9:\n", + " break\n", + " \n", + " if is_pandigital(s):\n", + " pandigitals.add(int(s))\n", + "\n", + " \n", + "max(pandigitals)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SageMath 9.5", + "language": "sage", + "name": "sagemath" + }, + "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.11.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}