diff --git a/python/e348.py b/python/e348.py new file mode 100644 index 0000000..e1600b9 --- /dev/null +++ b/python/e348.py @@ -0,0 +1,31 @@ +from functools import cache +from collections import defaultdict + + +@cache +def is_palindrome(n: int) -> bool: + ns = str(n) + return ns == ns[::-1] + + +def euler_348(): + counts = defaultdict(int) + + for a in range(30000): + for b in range(3000): + x = a**2 + b**3 + if is_palindrome(x): + counts[x] += 1 + rs = [] + for k, v in counts.items(): + if v == 4: + rs.append(k) + assert len(rs) == 5 + return sum(rs) + + +if __name__ == "__main__": + solution = euler_348() + print(f"e348.py: {solution}") + assert(solution == 1004195061) +