{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# [Project Euler](https://ProjectEuler.net)\n", "[This Python 3 notebook](Project%20Euler%20%28Python%203%29.ipynb) contains *some* solutions for the [Project Euler](https://ProjectEuler.net) challenge.\n", "\n", "### /!\\ **Warning:** do not spoil yourself the pleasure of solving these problems by yourself!\n", "\n", "[I (Lilian Besson)](http://perso.crans.org/besson/) started in February 2015, and worked occasionally on Project Euler problems in March and April 2015.\n", "I should try to work on it again, hence this notebook...\n", "\n", "![Badge giving the number of solved problems](https://ProjectEuler.net/profile/Naereen.png \"Badge giving the number of solved problems\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "----\n", "\n", "## Problem 32 : Pandigital products\n", "*Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.*" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 6 pandigital is\n", "0\n" ] } ], "source": [ "maxN = 987654321\n", "maxN = 654321 # XXX Passer à la vraie valeur\n", "l = len(str(maxN))\n", "sum32 = 0\n", "digits19 = set(range(1, l+1))\n", "for multiplicand in range(1, 1+maxN): # upto 987 654 321\n", " multiplier = 1\n", " product = multiplicand * multiplier\n", " while multiplier <= maxN and product <= maxN: # Be smart here!\n", " digits = str(multiplicand)+str(multiplier)+str(product)\n", " if len(digits) == l and set(digits) == digits19:\n", " print(\"multiplicand = {}, multiplier = {}, product = {}\".format(multiplicand, multiplier, product))\n", " print(\"digits =\", digits)\n", " sum32 += product\n", " multiplier += 1\n", " product = multiplicand * multiplier\n", "\n", "print(\"The sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through\", l, \"pandigital is\")\n", "print(sum32)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "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.4.3+" } }, "nbformat": 4, "nbformat_minor": 0 }