The TransCompilator

Solved LeetCode program · 309 of 1,000

#0420 · Strong Password Checker

Hard String chunk-07.md

Original English source

Keep a shared password as empty text. Keep a shared last of 0. Keep a shared run of 0. Keep a shared runs as an empty list of whole numbers. Keep a shared deletes of 0. Keep a shared wanted of 0. Keep a shared budget of 1. Keep a shared replacements of 0.
To measure from start (a whole number) with spot (a whole number). If spot is more than last, set run to spot minus start, return. The firstsymbol is the slice of password from start to start plus 1. The nextsymbol is the slice of password from spot to spot plus 1. If firstsymbol is nextsymbol, measure from start with spot plus 1, return. Set run to spot minus start.

To filter from spot (a whole number). The final is the last position of runs. If spot is more than final, return. The length is item spot of runs. The rest is length modulo 3. The triple is length divided by 3. The batch is deletes divided by budget. If triple is less than batch, set batch to triple. If rest is not wanted, set batch to 0. If batch is more than 0, subtract batch times budget from deletes, Set item spot of runs to length minus batch times budget. Filter from spot plus 1.

To score. Set replacements to 0.
For each part in runs.
The triples is part divided by 3. Add triples to replacements.

Place "a" into password. Set last to the last position of password. The size is last plus 1. The index is 0.
Repeat while index is at most last.
Set run to 0. Measure from index with index. Place run into runs. Add run to index.

The haslower is 0. The hasupper is 0. The hasdigit is 0.
For every spot from 0 to last.
The symbol is the slice of password from spot to spot plus 1. The code is character 0 of symbol. The lowlower is character 0 of "a". The highlower is character 0 of "z". The lowupper is character 0 of "A". The highupper is character 0 of "Z". The lowdigit is character 0 of "0". The highdigit is character 0 of "9". If code is at least lowlower and code is at most highlower, set haslower to 1. If code is at least lowupper and code is at most highupper, set hasupper to 1. If code is at least lowdigit and code is at most highdigit, set hasdigit to 1.

The missing is 3 minus haslower minus hasupper minus hasdigit. The answer is 0.
If size is less than 6.
Set answer to 6 minus size. If missing is more than answer, set answer to missing.

If size is at least 6 and size is at most 20.
Score. The extra is missing. If replacements is more than extra, set extra to replacements. Set answer to extra.

If size is more than 20.
Set deletes to size minus 20. Set wanted to 0. Set budget to 1. Filter from 0. Set wanted to 1. Set budget to 2. Filter from 0. Set wanted to 2. Set budget to 3. Filter from 0. Score. The extra is missing. If replacements is more than extra, set extra to replacements. Set answer to size minus 20 plus extra.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

5