New answers tagged

0

05AB1E, 104 103 102 bytes 0©U0Vv“ìÉP@p>akmO#o<+-*/ew“ykDdi…><nS'Xì'U«"Xç?0UX?®U"4ä«Dε„XU„YV‡}«"+-*÷"S„XYì0ª„©\«„®,ª«sè.Vy'/Q®+iq Try it online or verify all test cases. Explanation: 0©U0V # Set variables `X` (A), `Y` (B) and `®` (R) to 0 # (they are 1, 2, and -1 respectively by default) v ...


0

Perl 5 -Minteger -n0, 274 bytes s//;/g;s/e/R=0/g;s/\+/R=A+B/g;s/-/R=A-B/g;s/\*/R=A*B/g;s/i/A++/g;s/d/A--/g;s/s/A*=A/g;s/p/printA|0/g;s/P/print chrA/g;s/>/A=R/g;s/a/B++/g;s/k/B--/g;s/m/B*=B/g;s/o/printB|0/g;s/O/print chrB/g;s/</B=R/g;s,/,B||exit;R=A/B,g;s/w/sayR|0/g;s/\@/A=0/g;s/#/B=0/g;s/[ARB]/\$$&/g;eval Try it online!


0

JavaScript (V8), 152 bytes i=>{return n="",p=0,e=1,i.split(" ").map(i=>{e&&("inc"==i&&p++,"dec"==i&&p--,"mult"==i&&(p*=2),"half"==i&&(p/=2),"Pri"==i&&(n+=p),"exit"==i&&(e=0))}),n} Try it online!


2

Python 3.8 (single expression, no eval), 711 bytes (g:=lambda s,a,b,p,c:None if p>=len(s)else g(s,a,b,p+1,c+1)if a==s[p]else(p if c==1 else g(s,a,b,p+1,c-1))if b==s[p]else g(s,a,b,p+1,c),x:=lambda f:None if f is None else x(f()),f:=lambda s,p,m,c:[None,(lambda:f(s,*{"+":lambda:(p,m[:p]+[m[p]+1]+m[p+1:],c+1),"-":lambda:(p,m[:p]+[m[p]-1]+...


1

Haskell, 83 bytes data T=S|K|I|T:$T e(x:$y)=e x!e y e x=x I!x=x K:$x!_=x S:$x:$y!z=x!z!(y!z) x!y=x:$y Try it online!


1

C (gcc), 666 616 518 483 476 bytes Who doesn't love classy, Arthur Whitney-styled code? No regular expressions involved, only clever parsing and evaluation. PS: Yes, obviously, a few bytes can be shaved off, but for the artistic style of the obfuscated code, I'll keep them. Also for the byte count :p. Also, this code utilizes undefined behaviour in hope that ...


0

sed, 89 :1;s|(I\(.\))|\1|g;t1;s|((K\(.\)).)|\1|g;t1;s|(((S\(.\))\(.\))\(.\))|((\1\3)(\2\3))|g;t1


1

JavaScript (ES6) - 560 bytes Uses prompt() for input and alert() for output. It could be shortened if alert() was called for every character instead but I decided it would be better to buffer the characters so they could all be displayed at once. b=[],d=0,e=[],f=0,g="",h="",k=prompt().replace(/(\s+|\(.*\))/g,""),l=0;n=()=>{m=g;if(m&&(a=m.substr(...


1

05AB1E, 92 bytes ΔDŒʒ„)(©S¢Ë}ʒÁ®Å?y®S¢O_~}©vy"(Iÿ)"y:}®ãvy`"((Kÿ)ÿ)"yθ:}®3ãvy`"(((Sÿ)ÿ)ÿ)"yĆ1.I`"((ÿÿ)(ÿÿ))": 05AB1E has no regex, so uses a brute-force approach using all valid substrings. Because of this, it's extremely slow for larger test cases. Executes in the order (Ix) → ((Kx)y) → (((Sx)y)z). Try it online or ...


5

Wolfram Language, 63 bytes #//.{{I,x_}->x,{{K,x_},y_}->x,{{{S,x_},y_},z_}->{{x,z},{y,z}}}& Try it online! God, I love pattern matching in Wolfram Language. Represents (xy) as {x,y} (a list of two elements). Alternatively, if we represent (xy) with x>y, we can do it in 55 bytes. #//.{I>x_->x,(K>x_)>y_->x,((S>x_)>y_)&...


3

Retina 0.8.2, 171 bytes {T`()`<> <<<S((\w|(<)|(?<-3>>))+)>((\w|(<)|(?<-6>>))+)>((\w|(<)|(?<-9>>))+>) <<$1$7<$4$7> <<K((\w|(<)|(?<-3>>))+)>(\w|(<)|(?<-5>>))+> $1 <I((\w|(<)|(?<-3>>))+)> $1 T`<>`() Try it online! Explanation: {`...


3

perl -p, 135 bytes 1 while s/\((I)(?<T>[SKI]|\((?&T)(?&T)\))\)|\(\((K)((?&T))\)(?&T)\)|\(\(\((S)((?&T))\)((?&T))\)((?&T))\)/$1?$2:$3?$4:"(($6$8)($7$8))"/e Try it online! Just a regexp applying the three rules. Reads a string from STDIN, applies all the rules until there's nothing to apply, writes the result to STDOUT. (?&...


Top 50 recent answers are included