"The author went at length to explain how this is a useful exercize for programming, as it introduces edge cases, alternative implementations, testing, etc. "
Well, as long as he disallowed the obvious solution (last paragraph of the OP), and then he still got the solution wrong... (see other comments up threat)