def truncatable(prime): dig = intToDigits(prime) for i in range(1, len(dig)): trunc_r = digitsToInt(dig[:i]) if trunc_r not in sieve: return False trunc_l = digitsToInt(dig[i:]) if trunc_l not in sieve: return False return True
def concatproduct(n): digits = [] for i in range(1, 10): digits += intToDigits(n * i) if len(digits) >= 9: break if pandigital9(digitsToInt(digits)): return digitsToInt(digits) return 0
def familysize(p): if not repeatingdigits(p): return 1 dig = intToDigits(p) bestfamily = [p] for oldd in set(dig) - {dig[-1]}: family = [p] if len([d for d in dig if d == oldd]) < 2: continue for newd in set(range(10)) - {oldd}: if newd == 0 and dig[0] == oldd: continue newp = digitsToInt([newd if d == oldd else d for d in dig]) if newp in sieve: family.append(newp) if len(family) > len(bestfamily): bestfamily = family for pr in bestfamily: memoize[pr] = len(bestfamily) if len(bestfamily) == 8: print(bestfamily) return len(bestfamily)
def rotations(n): dig = intToDigits(n) for i in range(1, len(dig)): yield digitsToInt(dig[i:] + dig[:i])
def concatprime(p1,p2): d1 = intToDigits(p1) d2 = intToDigits(p2) c1 = digitsToInt(d1+d2) c2 = digitsToInt(d2+d1) return isprime(c1) and isprime(c2)
def palindromicInBinary(n): binary = bin(n)[2:] for a, b in zip(binary, reversed(binary)): if a != b: return False return True if __name__ == "__main__": tic() S = 0 for i in range(1, 1000, 2): digits = intToDigits(i) p = digitsToInt(list(reversed(digits)) + digits) #even length: cbaabc if palindromicInBinary(p): S += p p = digitsToInt(list(reversed(digits)) + digits[1:]) #odd length: cbabc if palindromicInBinary(p): S += p if i < 100: #center zeros: cb00bc p = digitsToInt(list(reversed(digits)) + [0] + digits) if palindromicInBinary(p): S += p p = digitsToInt(list(reversed(digits)) + [0, 0] + digits) if palindromicInBinary(p): S += p if i < 10: #center zeros: cb00bc p = digitsToInt(list(reversed(digits)) + [0, 0, 0] + digits)
from Euler.digits import digitsToInt if __name__ == "__main__": tic() S = 0 d = [None] * 10 for d789 in range(17, 987, 17): d[7] = d789 // 100 d[8] = (d789 // 10) % 10 d[9] = d789 % 10 if d[7] == d[8] or d[7] == d[9] or d[8] == d[9]: d[7:] = [None] * 3 continue for d6 in [i for i in range(10) if i not in d]: d[6] = d6 if digitsToInt(d[6:9]) % 13 != 0: d[6] = None continue for d5 in [i for i in [0, 5] if i not in d]: d[5] = d5 if digitsToInt(d[5:8]) % 11 != 0: d[5] = None continue for d4 in [i for i in range(10) if i not in d]: d[4] = d4 if digitsToInt(d[4:7]) % 7 != 0: d[4] = None continue for d3 in [i for i in range(0, 10, 2) if i not in d]: d[3] = d3 #if digitsToInt(d[3:6])%5 != 0: #not necessary because d5 is 0 or 5
first digit must be a one. assuming unique digits. """ from Euler.tictoc import tic, toc from Euler.eprint import eprint from Euler.digits import intToDigits, digitsToInt def repeatingdigits(n): from math import floor, log10 d = intToDigits(n) return len(set(d)) <= floor(log10(n)) if __name__ == "__main__": tic() for x_ in range(10**4, 10**7): dig = [1] + intToDigits(x_) x = digitsToInt(dig) if repeatingdigits(x): continue if sorted(intToDigits(2 * x)) == sorted(dig): if sorted(intToDigits(3 * x)) == sorted(dig): if sorted(intToDigits(4 * x)) == sorted(dig): if sorted(intToDigits(5 * x)) == sorted(dig): if sorted(intToDigits(6 * x)) == sorted(dig): print(x) toc() exit()
#!/usr/bin/env python3.6 """ PROBLEM: 024 AUTHOR: Dirk Meijer STATUS: done EXPLANATION: sympy solution """ from Euler.tictoc import * from Euler.digits import digitsToInt from sympy.combinatorics import Permutation if __name__ == "__main__": tic() p = Permutation.unrank_lex(10, rank=1_000_000 - 1).array_form print(digitsToInt(p)) toc() exit()