Today’s challenge
Build the solution
Write a function called check_pin(pin).
Return contract: A dictionary with accepted (boolean) and reasons (a list of the specified lowercase strings).
Input bounds: pin is a string with 0–40 characters.
Keep the supplied driver below your implementation. It reads one JSON object and prints your return value as JSON. The driver may also probe the behaviour described above; those probe fields are part of the test input.
- A PIN must contain exactly six ASCII digits. If its format is invalid, return only the format reason.
- For a valid format, reject six identical digits, six strictly ascending consecutive digits, or six strictly descending consecutive digits.
- Return reasons in this order: repeated, ascending, descending. A valid PIN without any reason is accepted.
The Twist: Sequences do not wrap around: 789012 is not an ascending consecutive PIN. Leading zeros are meaningful and must survive.
Sample
Input
{"pin":"012345"}Expected output
{"accepted":false,"reasons":["ascending"]}