Sort code digit pairs **can** have zero as a first digit. I have an account where all three sort code digit pairs begin with zero. The above coding examples assume that this cannot be the case, though in the event, this assumption holds up.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from itertools import combinations # the first digit of the PIN ... for d in range(1, 10): # ... and its power of ten (the PIN has at most six digits) for N in range(3, 6): # find the remaining digits (n) of the PIN # by solving (d.10^N + n) / d == 10.n + d n, r = divmod(d * (10 ** N - d), 10 * d - 1) if not r: pin = d * 10 ** N + n # generate all two digit divisors of the PIN div_list = (x for x in range(10, 100) if pin % x == 0) # list all combinations of three two-digit divisors # whose product is equal to the PIN digits = [(a, b, c) for a, b, c in combinations(div_list, 3) if a * b * c == pin] if digits: # select the three two-digit numbers with the minimum sum sc = min(digits, key=sum) # consider the possible account numbers for n in sc: acn = str(n * pin) if len(acn) == 8 and str(pin)[0] not in acn: print(f"Account Number: {acn}, Sort Code: {sc}, PIN: {pin}") |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
from number_theory import divisor_pairs # find three two digit integers with the minimum # possible sum whose product is equal to the PIN def sc_from_pin(pin): psc = [(a, b, c) for a, bc in divisor_pairs(pin) if 10 <= a < 100 for b, c in divisor_pairs(bc) if a <= b <= c < 100] return (min(psc, key=sum),) if psc else () # The PIN is the product of three two-digit numbers so has at most # six digits; the minimum PIN is the minimum eight-digit account # number divided by the maximum two-digit number, i.e. 101,010; so # the PIN has the form d.10^5 + n where d is its first digit and n # is a five-digit number. # # Solving (d.10^5 + n) / d == 10.n + d gives: # # PIN = (10^6 - 1).d^2 / (10.d - 1) # consider the first digit (d) of the PIN (d.10^N + n) ... for d in range(1, 10): # find the remaining digits (n) of the PIN by pin, r = divmod(999999 * d ** 2, 10 * d - 1) if not r: # find the sort code for sort_code in sc_from_pin(pin): for m in sort_code: # ... and the account number acn = str(m * pin) # which has eight digits, none equal to the PIN's first digit if len(acn) == 8 and str(d) not in acn: print(f"Account number {acn}, sort code {sort_code}, PIN {pin}") |