Skip to main content
added 347 characters in body; deleted 5 characters in body; added 40 characters in body
Source Link
O.O.Balance
  • 1.6k
  • 1
  • 10
  • 19

Java 11, 83+52=135135 65+26=91 bytes

A

s->{intvar i=sp=s.indexOfsplit("\"+\"")+3,j=s.lastIndexOf"\\("\"\"|\"\\.");return sp[0]+"(\"B"+p[1].substringrepeat(0,i)+"B"+""

B

B

C

".repeat(s.substring(i,j).length())+s+'"'+'.substring(j);'+p[2];}

Try it online herehere (TIO does not have Java 11 yet, so this code relies on a helper method instead of String::repeat()).

Ungolfed:

s -> { // lambda taking and returning a String
    var p = s.split("\\(\"|\"\\."); // split input into parts A, B^n, C (where n may be 0) at the "(\"" and "\"."
    return p[0] + "(\"B" + // put it back together: A plus the part the split shaved off, plus an extra B ...
    p[1].repeat("BBB".length()) + // ... plus B^(n*m)
    '"' + '.' + p[2]; // plus C, with the part the split shaved off reattached
}

Java 11, 83+52=135 bytes

A

s->{int i=s.indexOf("\"+\"")+3,j=s.lastIndexOf("\".");return s.substring(0,i)+"B"+"

B

B

C

".repeat(s.substring(i,j).length())+s.substring(j);}

Try it online here (TIO does not have Java 11 yet, so this code relies on a helper method instead of String::repeat()).

Java 11, 135 65+26=91 bytes

A

s->{var p=s.split("\\(\"|\"\\.");return p[0]+"(\"B"+p[1].repeat("

B

B

C

".length())+'"'+'.'+p[2];}

Try it online here (TIO does not have Java 11 yet, so this relies on a helper method instead of String::repeat()).

Ungolfed:

s -> { // lambda taking and returning a String
    var p = s.split("\\(\"|\"\\."); // split input into parts A, B^n, C (where n may be 0) at the "(\"" and "\"."
    return p[0] + "(\"B" + // put it back together: A plus the part the split shaved off, plus an extra B ...
    p[1].repeat("BBB".length()) + // ... plus B^(n*m)
    '"' + '.' + p[2]; // plus C, with the part the split shaved off reattached
}
added 41 characters in body
Source Link
O.O.Balance
  • 1.6k
  • 1
  • 10
  • 19

Java 11, 83+52=135 bytes

A

s->{int i=s.indexOf("\"+\"")+3,j=s.lastIndexOf("\".");return s.substring(0,i)+"B"+"

B

B

C

".repeat(s.substring(i,j).length())+s.substring(j);}

Try it online here (TIO does not have Java 11 yet, so this code relies on a helper method instead of String::repeat()).

Java 11, 83+52=135 bytes

A

s->{int i=s.indexOf("\"+\"")+3,j=s.lastIndexOf("\".");return s.substring(0,i)+"B"+"

B

B

C

".repeat(s.substring(i,j).length())+s.substring(j);}

Try it online here (TIO does not have Java 11 yet, so this code relies on a helper method instead).

Java 11, 83+52=135 bytes

A

s->{int i=s.indexOf("\"+\"")+3,j=s.lastIndexOf("\".");return s.substring(0,i)+"B"+"

B

B

C

".repeat(s.substring(i,j).length())+s.substring(j);}

Try it online here (TIO does not have Java 11 yet, so this code relies on a helper method instead of String::repeat()).

Source Link
O.O.Balance
  • 1.6k
  • 1
  • 10
  • 19

Java 11, 83+52=135 bytes

A

s->{int i=s.indexOf("\"+\"")+3,j=s.lastIndexOf("\".");return s.substring(0,i)+"B"+"

B

B

C

".repeat(s.substring(i,j).length())+s.substring(j);}

Try it online here (TIO does not have Java 11 yet, so this code relies on a helper method instead).