"And we'll reuse the main loop from that problem, too!"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "09e14708",
"metadata": {},
"outputs": [],
"source": [
"from collections import Counter\n",
"\n",
"limit = 1500000\n",
"lengths = Counter()\n",
"\n",
"for (a, b, c) in primitive_pythagorean_triplets(limit):\n",
" for k in count(1):\n",
" L = k * (a + b + c)\n",
" if L > limit:\n",
" break\n",
" \n",
" lengths[L] += 1"
]
},
{
"cell_type": "markdown",
"id": "c12a3e3c",
"metadata": {},
"source": [
"The only differences in this problem are our maximum perimeter, and that we're looking for perimeters that can only be made from one Pythagorean triplet."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0e7ce4b0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"161667"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len({k for (k, v) in lengths.items() if v == 1})"
"* Perimeters with one Pythagorean triple: [A098714](https://oeis.org/A098714)\n",
"\n",
"#### 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)."