{ "cells": [ { "cell_type": "markdown", "id": "9c7a281d", "metadata": {}, "source": [ "# [Largest Palindrome Product](https://projecteuler.net/problem=4)\n", "\n", "Our search space is only $\\binom{900}{2} = 404550$ 3-digit pairs - a lot to check by hand but peanuts to a modern computer (we're using notation for [combinations](https://en.wikipedia.org/wiki/Combination) if you're unfamiliar)." ] }, { "cell_type": "code", "execution_count": 1, "id": "e5fd66f6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "906609" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from itertools import combinations\n", "\n", "is_palindrome = lambda x: str(x) == str(x)[::-1]\n", "three_digit_pairs = combinations(range(100, 1000), 2)\n", "max(x*y for (x,y) in three_digit_pairs if is_palindrome(x*y))" ] }, { "cell_type": "markdown", "id": "ac68b4da", "metadata": {}, "source": [ "#### Copyright (C) 2025 filifa\n", "\n", "This work is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) and the [BSD Zero Clause license](https://spdx.org/licenses/0BSD.html)." ] } ], "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 }