diff --git a/notebooks/problem0032.ipynb b/notebooks/problem0032.ipynb index 23e3636..b4e04aa 100644 --- a/notebooks/problem0032.ipynb +++ b/notebooks/problem0032.ipynb @@ -17,24 +17,13 @@ "execution_count": 1, "id": "5d61d14d", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "45228" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "def is_pandigital(n):\n", " return ''.join(sorted(n)) == \"123456789\"\n", "\n", "\n", - "products = set()\n", + "products = dict()\n", "for p in range(1, 10000):\n", " for q in range(p, 10000):\n", " product = p * q\n", @@ -44,9 +33,65 @@ " break\n", " \n", " if is_pandigital(s):\n", - " products.add(product)\n", - "\n", - "sum(products)" + " products[(p, q)] = product" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "bd9cd5ec", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{(4, 1738): 6952,\n", + " (4, 1963): 7852,\n", + " (12, 483): 5796,\n", + " (18, 297): 5346,\n", + " (27, 198): 5346,\n", + " (28, 157): 4396,\n", + " (39, 186): 7254,\n", + " (42, 138): 5796,\n", + " (48, 159): 7632}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products" + ] + }, + { + "cell_type": "markdown", + "id": "3dfd3706", + "metadata": {}, + "source": [ + "As the problem hinted, some of these products appear more than once, but we only count each once in our sum." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "f63472a3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "45228" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sum(set(products.values()))" ] } ],