21
1
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
Is each snippet to be at least 1 character long? – trichoplax – 2015-11-17T15:50:16.803
The snippet can have zero length. The edit is OK. – Akangka – 2015-11-18T09:09:45.027
Is the language RegEx valid for this challenge? :P – Loovjo – 2015-11-18T09:31:42.147
I consider RegEx have RegEx build-in. I am forced to do this. I want to exclude Retina and regex, however, according to Mego, it is not allowed. Still, I don't know about Snails and friends. – Akangka – 2015-11-18T10:59:47.543
@ChristianIrwan Interestingly, I'm still not sure this is even solvable in Retina, and even it is, it will be far from competitive. – Martin Ender – 2015-11-18T11:45:23.370
Actually, I want to exclude Retina, RegEx, Snail, SnakeEx, etc. However, I don't know about Snail, SnakeEx, ..., so someone post the loophole. Since I can't prevent it, now you can post in it. – Akangka – 2015-11-18T12:16:40.380
I want to see answer without regex nor other pattern-matching language. I will give him a bounty. – Akangka – 2015-11-18T12:19:41.343
Does The regex is guaranteed to be nonempty. apply only to the entire input, or two REGEX as well? In particular, do we have to support
(0|)? – Dennis – 2015-11-18T22:34:47.777Only to entire input. – Akangka – 2015-11-19T15:18:21.497