From 8ff023990b1b6c19769e83e710c5b28b33b4ab89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Doblas=20Jim=C3=A9nez?= Date: Mon, 25 Jul 2022 19:24:43 +0200 Subject: [PATCH] Solution to problem 62 in Python --- src/Python/Problem062.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Python/Problem062.py diff --git a/src/Python/Problem062.py b/src/Python/Problem062.py new file mode 100644 index 0000000..a0a33f3 --- /dev/null +++ b/src/Python/Problem062.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +""" +Created on 25 Jul 2022 + +@author: David Doblas Jiménez +@email: daviddoji@pm.me + +Solution for problem 62 of Project Euler +https://projecteuler.net/problem=62 +""" + +from collections import defaultdict + +from utils import timeit + + +@timeit("Problem 62") +def compute(): + """ + The cube, 41063625 (345^3), can be permuted to produce two other cubes: + 56623104 (384^3) and 66430125 (405^3). In fact, 41063625 is the smallest + cube which has exactly three permutations of its digits which are also + cube. + + Find the smallest cube for which exactly five permutations of its digits + are cube. + """ + + cubes = defaultdict(list) + for number in range(345, 10_000): + cube_str = "".join(sorted(list(str(number**3)))) + cubes[cube_str].append(number**3) + if len(cubes[cube_str]) == 5: + return min(cubes[cube_str]) + + +if __name__ == "__main__": + + print(f"Result for Problem {int(62):003d}: {compute()}")