<jupyter_start><jupyter_text>Cubic permutations 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. ---  Idea The key to this problem is to avoid using real `permutation`, since a 8-digits number will generate $ 8! = 40320 $ permutations, which will signicantly increase search space. The solution is to use a hash-table to record cubes, with sorted digits as the key. ---<jupyter_code>import sys, os; sys.path.append(os.path.abspath('..'))
from timer import timethis
from collections import defaultdict
def generate_candidates(start):
    i = start
    while True:
        i += 1
        c = pow(i, 3)
        yield c
@timethis
def solve(permutation_cnt):
    cached_cubes = defaultdict(list)
    for c in generate_candidates(100):
        digits = tuple(sorted(map(int, str(c))))
        cached_cubes[digits].append(c)
        if len(cached_cubes[digits]) == permutation_cnt:
            return min(cached_cubes[digits])
solve(3)
solve(5)<jupyter_output>Run for 0.068 seconds
{'fraction_non_alphanumeric': 0.0864600326264274, 'fraction_numerical': 0.05057096247960848, 'mean_word_length': 3.908, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '576878', 'license': 'MIT', 'n_tokens_mistral': 438, 'n_tokens_neox': 370, 'n_words': 142, 'path': '51-75/p62.ipynb', 'repo_name': 'Sorosliu1029/Euler', 'size': '1226'}