Recursively define a "valid arithmetic expression":
- Any natural number is a valid arithmetic expression.
sis a valid arithmetic expression, then so is
qare valid arithmetic expressions, then so is
In the above, a "natural number" is recursively defined as follows:
9are natural numbers.
- If a natural number
n9are natural numbers.
Alternatively, via the regex
Examples of valid arithmetic expressions:
0 314 (-7) (0+0) (314+(-314))
Examples of invalid arithmetic expressions:
01 -5 5+10
The challenge is to print every valid arithmetic expression line by line, i.e. create a program that will output strings line by line with the constraint that every valid arithmetic expression is eventually printed, and that no invalid arithmetic expression is ever printed.
The valid arithmetic expressions can be printed more than once.
The challenge is to do so in as few bytes as possible, since this is code-golf.
Standard loopholes apply.