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+
between1
and2
)+*
->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).
- Examples:
c
: Concatenates with the next digit in the string.- Examples:
c+
->12+3
=15
(Thec
"continues" the1
and concatenates it with the next digit,2
, to form12
)+c
->1+23
=24
ccc
->1234
- Examples:
()
: 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
- Examples:
s
: Skip a number (removes the number from the infinite string).s+
->2+3
=5
(s
skips1
)csc
->124
(The firstc
concats1
and2
, thes
skips3
, and the finalc
concats12
to4
)+s+
->7
(The first+
adds1
and2
to make3
,s
skips3
, and the final+
adds3
to4
to make7
)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
.
~
s? Don't leave us hanging. \$\endgroup\$s+
is2+3
as its first example. And stills
keeps bugging me. I wonder how+s()+
expands. If it is1+(2)+4
then(
comes before2
but thes
that comes even before the(
seemingly still skips3
, not2
. If however the result is1+(3)+4
then the effect of as
depends on what comes after it (compare it with+s+
) \$\endgroup\$sc
is23
ands+
is1+3
? Doess
skip the1
now or the2
? All examples use the first operation on operands1
and2
... sosc
should be13
. \$\endgroup\$