Week 2

Vanity Plates

A list of rules, checked in order. One failure is enough.

You type

A plate.

The tool
Rules, in order A plate Check each rule Valid or invalid
What comes out

Valid or invalid.

The question, more slowly

The question is: a vanity plate comes in, and you print valid or invalid. The spec gives several rules: length, what the first characters must be, where numbers may sit, and a banned character. Every rule has to pass.

Write the rules as a numbered list and test them in that order. A plate that fails rule two does not need you to think about rule four. Returning as soon as one rule fails is enough.

The number rule is the one people misread: numbers, once they start, have to finish the plate, and the first number cannot be zero. Read that sentence twice. Try a plate that is almost right.

Before you code

Read the spec's rules once and number them. A plate has to pass all of them.