Teaser 2423: [PIN combinations]
From The Sunday Times, 1st March 2009 [link]
Joe could not remember his six-digit PIN, but he did remember that it used the digits 1 to 6 in some order. He tried the following four without success:
6 1 2 5 3 4 4 6 5 3 2 1 2 3 4 1 6 5 3 2 6 5 4 1Actually, more than one digit in each of these numbers was in the correct place. Had Joe known this, he would have needed to try only a few more numbers to find his PIN.
How many more numbers did Joe need to try?
This puzzle was originally published with no title.
[teaser2423]
Jim Randell 8:58 am on 17 July 2026 Permalink |
Presumably the puzzle is asking how many possible combinations remain after the initial 4 attempts.
This Python program runs in 64ms. (Internal runtime is 820µs).
from enigma import (subsets, printf) # candidates already tried tries = [ (6, 1, 2, 5, 3, 4), (4, 6, 5, 3, 2, 1), (2, 3, 4, 1, 6, 5), (3, 2, 6, 5, 4, 1), ] # start with all orderings ss = list(subsets((1, 2, 3, 4, 5, 6), size=6, select='P')) # count the number of correct positions def count(xs, ys): return sum(1 for (x, y) in zip(xs, ys) if x == y) # more than one of the digits in each candidate was in the correct position for ts in tries: ss = list(ns for ns in ss if 1 < count(ns, ts) < 6) # output solution printf("remaining candidates = {n}", n=len(ss)) printf("-> {ss}")Solution: There are 3 combinations remaining.
The remaining candidates are:
In each case, each of the initial 4 attempts was correct for exactly 2 digits.
LikeLike
Ruud 4:17 pm on 17 July 2026 Permalink |
import istr def matches(n0, n1): return sum(i0 == i1 for i0, i1 in zip(n0, n1)) tries = istr(["612534", "465321", "234165", "326541"]) for n0 in istr.permutations(range(1, 7), join=True): if all(2 <= matches(n0, n1) <= 5 for n1 in tries): print(n0)LikeLike