It turns out that this teaser is ambiguous since the phrase “the next door house had a number like theirs but with the two digits in reverse order” could mean either “a next door house has this house’s number but with its digits reversed”, or “a next door house has its normal number but with its digits reversed”.

The code below finds a solution for each of these interpretations:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
fs = "House number is {:d}, numberer's age is {:d}" # sensible age range for numberer for age in range(10, 81): # create the house numbers he used as a list house_nbrs = [x % 100 for x in range(age, 100 * age, age)] # check that all numbers (1 .. 99) are used if 0 not in house_nbrs and len(set(house_nbrs)) == 99: # now find a house whose number and 'normal' number are the same for house_nbr in house_nbrs: normal_nbr = house_nbrs.index(house_nbr) + 1 if house_nbr == normal_nbr: prv, nxt = (house_nbr - age) % 100, (house_nbr + age) % 100 # if a next door number has this house's two digits reversed prt = 10 * (house_nbr % 10) + house_nbr // 10 in (prv, nxt) # if a next door number is its 'digit reversed' normal number prt |= (10 * (prv % 10) + prv // 10 == normal_nbr - 1 or 10 * (nxt % 10) + nxt // 10 == normal_nbr + 1) if prt: print(fs.format(house_nbr, age)) |