Skip to main content
added 118 characters in body
Source Link
lynn
  • 69.7k
  • 11
  • 137
  • 285

Python 2, 6262 61 bytes

lambda s,L=1:eval(re.sub('(\d*)(.)',r'+\1L*"\2"'r'+1*\1*1*"\2"',s)) import re 

Try it online!Try it online!

The regex substitution expands 3<2+- into the string:

+3L*"<"+2L*"+"+L*"+1*3*1*"<"+1*2*1*"+"+1**1*"-" 

which is then evaled. (Note how when 3L\1 is parsed as a long integer literalempty, whereaswe get L1**1 = 1 is parsed as a variable, which we defined as 1. Note how the) The first + is a unary operator which binds to the first number, and the other +s are string concatenation!. This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by 1314 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.


xnor saved a byte, supplying the 1*\1*1 trick. Previously I had \1L in the regex, and defined L=1 as a lambda argument, which is also pretty cool: 3L is a long int literal and L is a variable.

Python 2, 62 bytes

lambda s,L=1:eval(re.sub('(\d*)(.)',r'+\1L*"\2"',s)) import re 

Try it online!

The regex substitution expands 3<2+- into the string:

+3L*"<"+2L*"+"+L*"-" 

which is then evaled. 3L is parsed as a long integer literal, whereas L is parsed as a variable, which we defined as 1. Note how the first + is a unary operator which binds to the first number, and the other +s are string concatenation! This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by 13 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.

Python 2, 62 61 bytes

lambda s:eval(re.sub('(\d*)(.)',r'+1*\1*1*"\2"',s)) import re 

Try it online!

The regex substitution expands 3<2+- into the string:

+1*3*1*"<"+1*2*1*"+"+1**1*"-" 

which is then evaled. (Note how when \1 is empty, we get 1**1 = 1.) The first + is a unary operator which binds to the first number, and the other +s are string concatenation. This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by 14 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.


xnor saved a byte, supplying the 1*\1*1 trick. Previously I had \1L in the regex, and defined L=1 as a lambda argument, which is also pretty cool: 3L is a long int literal and L is a variable.

added 77 characters in body
Source Link
lynn
  • 69.7k
  • 11
  • 137
  • 285

Python 2, 62 bytes

lambda s,L=1:eval(re.sub('(\d*)(.)',r'+\1L*"\2"',s)) L=1 import re 

Try it online!Try it online!

ExpandsThe regex substitution expands 3<2+- into the string:

+3L*"<"+2L*"+"+L*"-" 

which is then evaled. 3L is parsed as a long integer literal, whereas L is parsed as a variable, which we definedefined as 1. Note how the first + is a unary operator which binds to the first number, and the other +s are string concatenation! This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by 13 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.

Python 2, 62 bytes

lambda s:eval(re.sub('(\d*)(.)',r'+\1L*"\2"',s)) L=1 import re 

Try it online!

Expands 3<2+- into

+3L*"<"+2L*"+"+L*"-" 

which is then evaled. 3L is parsed as a long integer literal, whereas L is parsed as a variable, which we define as 1. Note how the first + is a unary operator which binds to the first number, and the other +s are string concatenation! This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by 13 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.

Python 2, 62 bytes

lambda s,L=1:eval(re.sub('(\d*)(.)',r'+\1L*"\2"',s)) import re 

Try it online!

The regex substitution expands 3<2+- into the string:

+3L*"<"+2L*"+"+L*"-" 

which is then evaled. 3L is parsed as a long integer literal, whereas L is parsed as a variable, which we defined as 1. Note how the first + is a unary operator which binds to the first number, and the other +s are string concatenation! This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by 13 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.

added 148 characters in body
Source Link
lynn
  • 69.7k
  • 11
  • 137
  • 285

Python 2, 6862 bytes

lambda s:eval(re.sub('(\d*)(.)',r'+int("\1"or 1)*"\2"'r'+\1L*"\2"',s)) L=1 import re 

Try it online!Try it online!

Expands 3<2+- into

+int("3"or 1)*"<"+int("2"or 1)*"+"+int(""or 1)*"+3L*"<"+2L*"+"+L*"-" 

which is then evaled. 3L is parsed as a long integer literal, whereas L is parsed as a variable, which we define as 1. Note how the first + is a unary operator onwhich binds to the result of intfirst number, and the other +s are string concatenation! This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by seven13 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.

Python 2, 68 bytes

lambda s:eval(re.sub('(\d*)(.)',r'+int("\1"or 1)*"\2"',s)) import re 

Try it online!

Expands 3<2+- into

+int("3"or 1)*"<"+int("2"or 1)*"+"+int(""or 1)*"-" 

which is then evaled. Note how the first + is a unary operator on the result of int, and the other +s are string concatenation! This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) 

by seven bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.

Python 2, 62 bytes

lambda s:eval(re.sub('(\d*)(.)',r'+\1L*"\2"',s)) L=1 import re 

Try it online!

Expands 3<2+- into

+3L*"<"+2L*"+"+L*"-" 

which is then evaled. 3L is parsed as a long integer literal, whereas L is parsed as a variable, which we define as 1. Note how the first + is a unary operator which binds to the first number, and the other +s are string concatenation! This beats the more obvious

lambda s:re.sub('(\d+)(.)',lambda m:int(m.group(1))*m.group(2),s) import re 

by 13 bytes. Ordinarily "\2" wouldn’t always work, but thankfully \ and " aren’t brainfuck commands.

Source Link
lynn
  • 69.7k
  • 11
  • 137
  • 285
Loading