Oct-02-2022, 07:24 AM
Hi everyone,
I'm working on a function that avoids transposed numbers. Like if you have 12 you can't have 21 or if you have 126 you can't have 216 oder 621.
What I got so far:
As you can see, I already tried to crunch it with my gpu but compilation failed. That's not really a sustainable option anyway.
Any help is greatly appreciated.
Markus
I'm working on a function that avoids transposed numbers. Like if you have 12 you can't have 21 or if you have 126 you can't have 216 oder 621.
What I got so far:
#!/bin/env python3 import itertools import itertools from numba import jit, cuda import numpy as np #@jit(target_backend='cuda') def getNonSwappables(iStart, iStop, verbose = False): idsClean = [] ids = list(range(iStart, iStop)) for i in ids: if verbose: print("Processing: ", i) # Create permutation for current string. sPermutations = [''.join(p) for p in itertools.permutations(str(i))] # Check if the clean ids list contains any of the permutations. if not any(item in str(idsClean) for item in sPermutations): # If not so, apped the current integer to the list of clean ids. idsClean.append(i) return(idsClean) listIDsClean = getNonSwappables(1, 100000, True) print(listIDsClean) print(len(listIDsClean))For numbers < 10.000 it works somewhat reasonable. But larger numbers take forever. Is there a way I can code this more efficient?
As you can see, I already tried to crunch it with my gpu but compilation failed. That's not really a sustainable option anyway.
Any help is greatly appreciated.
Markus