# Cubic permutations (Euler Problem 62)¶

Back to overview.

https://projecteuler.net/problem=62

The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). 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.

In [1]:

    cubes = [n * n * n for n in range(1, 5000)]
    cubes_set = set(cubes)

In [2]:

    solutions = {}

    for n in range(1, 10000):
        cube = n * n * n
        try:
            key = "".join(sorted(str(cube)))
            solutions[key].append(cube)
            if len(solutions[key]) > 4:
                print(solutions[key])
                s = solutions[key][0]
                break
        except KeyError:
            solutions[key] = [cube]

    print(s)
    assert(s == 127035954683)

    [127035954683, 352045367981, 373559126408, 569310543872, 589323567104]
    127035954683

In [ ]: