{ "cells": [ { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "906609" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def is_palindrome(n):\n", " t = n\n", " reverse = 0\n", " while t > 0:\n", " reverse *= 10\n", " reverse += t%10\n", " t //= 10\n", " return n == reverse\n", "\n", "def products(lowerlim, upperlim):\n", " products = []\n", " for a in range(lowerlim, upperlim):\n", " b = a\n", " while b <= upperlim:\n", " products.append(a*b)\n", " b += 1\n", " return sorted(products, reverse = True)\n", " \n", "next(p for p in products(100, 1000) if is_palindrome(p))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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.7.4" }, "title": "Largest palindrome product" }, "nbformat": 4, "nbformat_minor": 2 }