Visiting England's Wirral Peninsula in 1853, Nathaniel Hawthorne came upon1 a queer battlemented house in the town of Bebington:
… quite a novel symbol of decay and neglect, …
… probably the whim of some half-crazy person.
On the wall, close to the street, there were certain eccentric inscriptions cut into slabs of stone, but I could make no sense of them.
The crazy person was resident Thomas Francis, and the inscriptions had apparently been commissioned to bemuse and entertain passersby.
They offer three puzzles, with the middle one reading as
Subtract 45 From 45 That 45 May Remain.
This seems to refer to the following mathematical curiosity:
987654321 - 123456789 ----------- 864197532
Each of these figures comprises the digits 1 to 9, so all have the same digit sum: 45.
The house was demolished in the 1960s, but the stones can be seen today in the foyer of the library at the Bebington Civic Medical Centre2.
For a number $$n \in \mathbb{N}_0$$, the riddle
Subtract $$n$$ from $$n$$, that $$n$$ may remain.
has multiple solutions when ignoring the restriction that the numbers must be permutations of the digits 1 to 9. After all, there are several numbers $$i, j \in \mathbb{N_0}$$ ($$i > j$$) for which each of the three numbers $$i$$, $$j$$ and $$i - j$$ has digit sum $$n$$.
Your task:
Write a function digit_sum that takes a number $$i \in \mathbb{N}_0$$ (int). The function must return the sum (int) of the digits of $$i$$. We call this result the digit sum of $$i$$.
Write a function issolution that takes two numbers $$i, j \in \mathbb{N}_0$$. The function may assume that $$i > j$$, without the need to check this explicitly. The function must return a Boolean value (bool) that indicates whether each of the three numbers $$i$$, $$j$$ and $$i - j$$ has the same digit sum. If this is the case, we call the two numbers $$i$$ and $$j$$ a solution of the middle puzzle of Bebington.
Write a function solutions that takes two numbers $$a, b \in \mathbb{N}_0$$. The function may assume that $$a < b$$, without the need to check this explicitly. The function must return number of different solutions (int) that can be found for the middle puzzle of Bebington, where the two numbers $$i$$ and $$j$$ are in the interval $$[a, b]$$ ($$a \leq j < i \leq b$$).
>>> digit_sum(987654321)
45
>>> digit_sum(123456789)
45
>>> digit_sum(864197532)
45
>>> issolution(987654321, 123456789)
True
>>> issolution(93243, 58134)
False
>>> solutions(1000, 2000)
1311
>>> solutions(2000, 3000)
1202
>>> solutions(3000, 4000)
1128
The first stone presents the image of an inn, The Two Crowns, and the following riddle:
My name And sign is thirty Shillings just, and he that will tell My Name Shall have a Quart on trust, for why is not Five the Fourth Part of Twenty the Same in All Cases?
This was easier to guess at the time of its inscription. The landlord of the Two Crowns was Mark Noble, the old English coin known as the noble was worth 6 shillings and eightpence, the mark was worth 13 shillings and fourpence, and two crowns were worth 10 shillings. Together these values total 30 shillings (a shilling was worth 12 pence).
The last puzzle is the easiest:
AR UBB I NGS TONEF ORAS SE S
Read this straight through and you get A RUBBING STONE FOR ASSES — possibly a comment by Francis on the loiterers who would gather outside his home.