The TransCompilator

Solved LeetCode program · 10 of 1,000

#0010 · Regular Expression Matching

Hard String chunk-01.md

Original English source

The text is "aab". The pattern is "c*a*b". The textsize is the number of characters in text. The patternsize is the number of characters in pattern. The width is patternsize plus 1. The height is textsize plus 1. The size is width times height. The table is a list of size zeros. Set item 0 of table to 1.
For every column from 2 to patternsize.
If character (column minus 1) of pattern is 42 and item (column minus 2) of table is 1, set item column of table to 1.

For every row from 1 to textsize.
For every column from 1 to patternsize.
The index is row times width plus column. The symbol is character (column minus 1) of pattern. If symbol is not 42 and symbol is 46 and item (index minus width minus 1) of table is 1, set item index of table to 1. If symbol is not 42 and symbol is character (row minus 1) of text and item (index minus width minus 1) of table is 1, set item index of table to 1. If symbol is 42 and column is more than 1 and item (index minus 2) of table is 1, set item index of table to 1. If symbol is 42 and column is more than 1 and character (column minus 2) of pattern is 46 and item (index minus width) of table is 1, set item index of table to 1. If symbol is 42 and column is more than 1 and character (column minus 2) of pattern is character (row minus 1) of text and item (index minus width) of table is 1, set item index of table to 1.

The last is one less than size. If item last of table is 1, display true. Otherwise, display false.

Open in Playground Browse all 1,000 problems

Expected stdout

true