Skip to content
Tape‑n‑Trace
PracticeSearch 26 tools

← All case studies

Password pattern validator

CO2BTL 3 – ApplySDG 16 — Peace, Justice & Strong InstitutionsModule 2

Starts with a letter and contains at least one digit. The alphabet abstracts a password into three classes: "a" a letter, "d" a digit, "s" a symbol. Note what is *hard* here — "at least one of each class" is an intersection of three conditions, and writing it as a single expression is painful even though the language is plainly regular. That is a good argument for the closure lab.

The expression

a(a+d+s)*d(a+d+s)*

The machine below is its minimal DFA — 4 states over {a, d, s}. Open it in the playground to see the parse tree and the ε-NFA it came from.

ad, sa, sda, d, sa, d, s{{q0}}{{q1,q2,q4,q6,q8,q10,q12,q13,q14},{q2,q3,q4,q6,q7,q8,q10,q11,q13,q14},{q2,q4,q6,q8,q9,q10,q11,q13,q14}}{{}}{{q2,q3,q4,q6,q7,q8,q10,q11,q13,q14,q16,q17,q18,q20,q21,q22,q24,q25,q27},{q2,q4,q5,q6,q7,q8,q10,q11,q13,q14,q15,q16,q18,q19,q20,q21,q22,q24,q25,q26,q27},{q2,q4,q5,q6,q7,q8,q10,q11,q13,q14,q15,q16,q18,q20,q22,q24,q26,q27},{q2,q4,q6,q8,q9,q10,q11,q13,q14,q16,q18,q20,q22,q23,q24,q25,q27}}
Try
ad, sa, sda, d, sa, d, s{{q0}}{{q1,q2,q4,q6,q8,q10,q12,q13,q14},{q2,q3,q4,q6,q7,q8,q10,q11,q13,q14},{q2,q4,q6,q8,q9,q10,q11,q13,q14}}{{}}{{q2,q3,q4,q6,q7,q8,q10,q11,q13,q14,q16,q17,q18,q20,q21,q22,q24,q25,q27},{q2,q4,q5,q6,q7,q8,q10,q11,q13,q14,q15,q16,q18,q19,q20,q21,q22,q24,q25,q26,q27},{q2,q4,q5,q6,q7,q8,q10,q11,q13,q14,q15,q16,q18,q20,q22,q24,q26,q27},{q2,q4,q6,q8,q9,q10,q11,q13,q14,q16,q18,q20,q22,q23,q24,q25,q27}}

Input

0 of 2 read

Narration

{{q0}}

Start in state {{q0}} with "ad" still to read.

Hopcroft 2e, §2.2.4

Accepted

Run many strings

One string per line. A blank line means the empty string.