CATEGORY:
Knuth: Blunder (Thinking the right thing but doing it wrong)
REFERENCE:
https://www.tug.org/TUGboat/tb10-4/tb26knut.pdf
EXPLANATION:
The following code ensures that four double-strikes are done whenever the
current hour is evenly divisible by four:
# Correction for four double-strikes at 00:00, 04:00, 08:00 ...
if double_strikes == 0:
double_strikes = ShipBell.MAX_DOUBLE_STRIKES
However, this condition is also true for all minutes following that hour,
which is not what is desired.
CONSEQUENCES:
Whenever 'double_strikes' is 0, 'double_strikes' is unconditionally set to
'ShipBell.MAX_DOUBLE_STRIKES', even half an hour later, when
'single_strikes' has changed to 1. Consequently, the bell pattern is "2 2 2
2 1", when it should be "1".
BUGFIX:
The correction for four double-strikes shall only be done exactly on the
hour, when 'minutes' equals 0:
# Correction for four double-strikes at 00:00, 04:00, 08:00 ...
if double_strikes == 0 and minutes == 0:
double_strikes = ShipBell.MAX_DOUBLE_STRIKES
REMARKS:
The full code of the Ship's Bell app can be found here:
https://github.com/ralfholly/ships-bell