in reply to Re: Simple but thought-provoking programming tasks [OT]
in thread Simple but thought-provoking programming tasks [OT]

555 123 456 is an interesting one. It's obviously invalid because it's too short. But if you make it long enough by adding a digit on the end it's still invalid, because 1 is illegal in the fourth digit of NANP numbers. To be honest, this sort of thing, which requires esoteric domain-specific knowledge to get right, is not really suitable for a student exercise.

But it does make a good teaching example, by starting with the most basic rules (is it the right length?) then add more and more complex ones - start with why the A and D digits can't be 0 or 1 (getting the students to figure out why this is the case is a useful exercise in itself, even without then encoding the rule in a program); then add the other special cases (eg, the BC digits can't be 11 and again get the students to figure out why) and finally wrap up with "and you don't have to do any of that work if you use perl because there's a CPAN module for it". That module is Number::Phone::NANP.

  • Comment on Re^2: Simple but thought-provoking programming tasks [OT]