DAY 08 OF 100 · Strings · adjacent values

Easy

A PIN Policy With a Catch.

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.

  1. A PIN must contain exactly six ASCII digits. If its format is invalid, return only the format reason.
  2. For a valid format, reject six identical digits, six strictly ascending consecutive digits, or six strictly descending consecutive digits.
  3. 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"]}
day-8.py
Python 3
Tab inserts four spaces. Press Escape, then Tab to move to the next control, or Shift+Tab to move to the previous control.

Log in or create an account to run code, submit solutions, and save your progress.

Output

Run your code to see the result here.