Your task is to compile regexes... by specifying a substitution for each character in a regex.
Regexes
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:
*()|10
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).()is grouping.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:
*:FSAGFSDVADFS
|:GSDGSAG
(:GSDG
):GDSIH
1:RGIHAIGH
0:GIHEBN
Then you replace each regex with its respective code snippet, so:
(0|11)*
is turned into:
GSDGGIHEBNGSDGSAGRGIHAIGHRGIHAIGHGDSIHFSAGFSDVADFS
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.
Input outside 01 is consindered undefined behavior. Input can be empty.
Additional rules
- 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.
Scoring
The least combined snippet is the winner. So the score for the example case would be calculated as follows:
FSAGFSDVADFS + GSDGSAG + GSDG + GDSIH + RGIHAIGH + GIHEBN
12 + 7 + 4 + 5 + 8 + 6 = 42