# Interpret Repetition!

This challenge is the first in a two-challenge series about Repetition. The second will be up soon.

In a language called Repetition (something I just made up), there consists an infinite string of 12345678901234567890..., with 1234567890 repeating forever.

The following syntax is available to output numbers:

• +-*/: This inserts the operator into the string of repeating digits.
• Examples:
• + -> 1+2 = 3 (The + inserts a + between 1 and 2)
• +* -> 1+2*3 = 1+6 = 7 (Same as above, except two operators are used now)
• / -> 1/2 = 0 (Repetition uses integer division)
• // -> 1/2/3 = 0/3 = 0 (Repetition uses "left association" with multiple subtractions and divisions)
• Each operator is inserted so that it has one digit to its left, unless there are c's (see below).
• c: Concatenates with the next digit in the string.
• Examples:
• c+ -> 12+3 = 15 (The c "continues" the 1 and concatenates it with the next digit, 2, to form 12)
• +c -> 1+23 = 24
• ccc -> 1234
• (): Brackets for processing numbers.
• Examples:
• (c+)* -> (12+3)*4 = 15*4 = 60 (Repetition uses the order of operations)
• (c+)/c -> (12+3)/45 = 15/45 = 0
• (cc+c)/ -> (123+45)/6 = 168/6 = 28
• s: Skip a number (removes the number from the infinite string).
• s+ -> 2+3 = 5 (s skips 1)
• csc -> 124 (The first c concats 1 and 2, the s skips 3, and the final c concats 12 to 4)
• +s+ -> 7 (The first + adds 1 and 2 to make 3, s skips 3, and the final + adds 3 to 4 to make 7)
• cs*(++) -> 12*(4+5+6) = 12*15 = 180

In the examples above, only a finite amount of digits in the infinite string are used. The number of digits used is equivalent to number of operators, concats and skips + 1.

Your task is, when given a string of Repetition code, output the result.

Examples of input and output are:

++ -> 6
- -> -1
(-)* -> -3
cscc -> 1245
(cc+c)/ -> 28
cc+c/ -> 130
cs*(++) -> 180


This is code golf, so shortest code in bytes wins!

## Specs:

• You are guaranteed that the result will never go above 2^31-1.
• You are also guaranteed that the input will only consist of the symbols +-*/cs().
• An empty program will output 1.
• What about the ~s? Don't leave us hanging. – Robert Fraser Sep 17 '16 at 8:24
• @RobertFraser Whoops, that was a mistake - c was originally ~, but it appears that I haven't fixed that completely. – clismique Sep 17 '16 at 8:29
• @TonHospel Ooh, you've got a good point there. The "s" symbol essentially removes the number it's associated with from the infinite string altogether, so it's a yes for both scenarios. – clismique Sep 17 '16 at 9:29
• Your specification however says s+ is 2+3 as its first example. And still s keeps bugging me. I wonder how +s()+ expands. If it is 1+(2)+4 then ( comes before 2 but the s that comes even before the ( seemingly still skips 3, not 2. If however the result is 1+(3)+4 then the effect of a s depends on what comes after it (compare it with +s+) – Ton Hospel Sep 17 '16 at 18:23
• sc is 23 and s+ is 1+3? Does s skip the 1 now or the 2? All examples use the first operation on operands 1 and 2 ... so sc should be 13. – Titus Sep 17 '16 at 19:14

# JavaScript (ES6), 110 bytes

## Batch, 332 bytes

@echo off
set s=
set e=
set d=
set r=
set/ps=
:d
:l
if "%s%"=="" goto g
set c=%s:~0,1%
set s=%s:~1%
if %c%==( set e=%e%(&goto l
if %c%==) set r=%r%)&goto l
if %c%==s goto d
if %c%==c set c=
if "%r%"=="" set/ar=d,d=-~d%%10
set e=%e%%r%%c%
set/ar=d
goto d
:g
if "%r%"=="" set/ar=d
cmd/cset/a%e%%r%


The behaviour of s makes this very awkward. (Maybe cs should evaluate to 13 and -s to -2?) Variables:

• s input string (explicitly blanked out because set/p doesn't change the variable if you don't input anything)
• e partial expression in normal integer arithmetic (which we can pass to set/a as a form of eval)
• d next digit from the infinite string of digits
• r right hand side of latest operator. We can't concatenate this immediately because ( needs to come first, but we need to store it so that s won't increment it. Fortunately it does end up making the handling of ) slightly easier.
• c current character.