Your task is to compile regexes... by specifying a substitution for each character in a regex.
The regexes support these
REGEX = (LITERAL REGEX / GROUP REGEX / STAR REGEX / ALTERNATIVE) LITERAL = 1 / 0 GROUP = '(' REGEX ')' STAR = (LITERAL / GROUP) '*' ALTERNATIVE = '('REGEX ('|' REGEX)*')'
Why only 1 or 0? It is for simplification. The regex thus has only the following characters:
It is interpreted as follows:
*is Kleene star (repeat left group or literal 0 or more times).
|is alternation (match if either the regex to the left or the regex to the right matches).
1matches character 1.
0matches character 0.
How to compile?
You specify six code snippets: one to replace each regex character. For example, if your answer is:
Then you replace each regex with its respective code snippet, so:
is turned into:
What is the resulting program supposed to do?
Your program will:
- Take the input.
- Output a truthy value if the regex matches whole input.
- Else output a falsy value.
01 is consindered undefined behavior. Input can be empty.
- For a given regex character, the resulting snippet must always be the same.
- There is no prefix or suffix character added afterwards.
- The regex is guaranteed to be nonempty.
The least combined snippet is the winner. So the score for the example case would be calculated as follows:
12 + 7 + 4 + 5 + 8 + 6 = 42