Skip to main content
added 77 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Java 8, 186 168168 167 bytes

s->{s=s.replaceAll("--|~~","");int l,i=(si=s.length()-(l=(s=s.replace("-~","")).length()))/2;return>>1;return(l-(s=s.replace("~","")).length()>0?"-"+s+~i:s+"+"+i).replace("--","");}

Try it online.-1 byte thanks to @ceilingcat replacing (a-b)/2 with a-b>>1.

Try it online.

s->{                            // Method with String as both parameter and return-type
  s=s.replaceAll("--|~~","");   //  Remove all "--" and "~~"
  int l,                        //  Temp integer to reduce bytes
      i=(si=s.length()-(l=(s=s.replaceAll("-~","")).length()))/2;>>1;
                                //  Remove all "-~" and save count in `i`
  return(l-(s=s.replaceAll("~","")).length()
                                //  Remove all remaining "~"
         >0?                    //  and if its non-empty:
           "-"                  //   Start with a minus sign
           +s                   //   followed by the remaining `s`
           +~i                  //   followed by `-i-1`
          :                     //  Else:
           s                    //   Start with the remaining `s`
           +"+"                 //   followed by a plus sign
           +i                   //   followed by `i`
         ).replaceAll("--","");}//  And then remove all "--"

Java 8, 186 168 bytes

s->{s=s.replaceAll("--|~~","");int l,i=(s.length()-(l=(s=s.replace("-~","")).length()))/2;return(l-(s=s.replace("~","")).length()>0?"-"+s+~i:s+"+"+i).replace("--","");}

Try it online.

s->{                            // Method with String as both parameter and return-type
  s=s.replaceAll("--|~~","");   //  Remove all "--" and "~~"
  int l,                        //  Temp integer to reduce bytes
      i=(s.length()-(l=(s=s.replaceAll("-~","")).length()))/2;
                                //  Remove all "-~" and save count in `i`
  return(l-(s=s.replaceAll("~","")).length()
                                //  Remove all remaining "~"
         >0?                    //  and if its non-empty:
           "-"                  //   Start with a minus sign
           +s                   //   followed by the remaining `s`
           +~i                  //   followed by `-i-1`
          :                     //  Else:
           s                    //   Start with the remaining `s`
           +"+"                 //   followed by a plus sign
           +i                   //   followed by `i`
         ).replaceAll("--","");}//  And then remove all "--"

Java 8, 186 168 167 bytes

s->{s=s.replaceAll("--|~~","");int l,i=s.length()-(l=(s=s.replace("-~","")).length())>>1;return(l-(s=s.replace("~","")).length()>0?"-"+s+~i:s+"+"+i).replace("--","");}

-1 byte thanks to @ceilingcat replacing (a-b)/2 with a-b>>1.

Try it online.

s->{                            // Method with String as both parameter and return-type
  s=s.replaceAll("--|~~","");   //  Remove all "--" and "~~"
  int l,                        //  Temp integer to reduce bytes
      i=s.length()-(l=(s=s.replaceAll("-~","")).length())>>1;
                                //  Remove all "-~" and save count in `i`
  return(l-(s=s.replaceAll("~","")).length()
                                //  Remove all remaining "~"
         >0?                    //  and if its non-empty:
           "-"                  //   Start with a minus sign
           +s                   //   followed by the remaining `s`
           +~i                  //   followed by `-i-1`
          :                     //  Else:
           s                    //   Start with the remaining `s`
           +"+"                 //   followed by a plus sign
           +i                   //   followed by `i`
         ).replaceAll("--","");}//  And then remove all "--"
deleted 151 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

Java 8, 186186 168 bytes

s->{s=s.replaceAll("--|~~","");int l,i=(s.length()-(l=(s=s.replaceAllreplace("-~","")).length()))/2,j=l2;return(l-(s=s.replaceAllreplace("~","")).length();return(j>0>0?"-"+s+"-"+-~i"+s+~i:s+"+"+i).replaceAllreplace("--","");}

Try it online.

Explanation:

Try it here.

s->{                              // Method with String as both parameter and return-type
  s=s.replaceAll("--|~~","");     //  Remove all "--" and "~~"
  int l,                          //  Temp integer to reduce bytes
      i=(s.length()-(l=(s=s.replaceAll("-~","")).length()))/2,2;
                                 //  Remove all "-~" and save count in `i`
      j=lreturn(l-(s=s.replaceAll("~","")).length();
                                 //  Remove all remaining "~" 
 and save count in `j`
   return(j>0 >0?                    //  If `j` isand largerif thanits 0non-empty:
           "-"                   //   Start with a minus sign
           +s                    //   followed by the remaining `s`
           +"-"+~i                  //   followed by another minus sign
           +`-~i                  //   followed by `i+1`i-1`
          :                      //  Else:
           s                     //   Start with the remaining `s`
           +"+"                  //   followed by a plus sign
           +i                    //   followed by `i`
         ).replaceAll("--","");  }//  And then remove all "--"
}                                // End of method

Java 8, 186 bytes

s->{s=s.replaceAll("--|~~","");int l,i=(s.length()-(l=(s=s.replaceAll("-~","")).length()))/2,j=l-(s=s.replaceAll("~","")).length();return(j>0?"-"+s+"-"+-~i:s+"+"+i).replaceAll("--","");}

Explanation:

Try it here.

s->{                              // Method with String as both parameter and return-type
  s=s.replaceAll("--|~~","");     //  Remove all "--" and "~~"
  int l,                          //  Temp integer to reduce bytes
      i=(s.length()-(l=(s=s.replaceAll("-~","")).length()))/2,
                                 //  Remove all "-~" and save count in `i`
      j=l-(s=s.replaceAll("~","")).length();
                                 //  Remove all remaining "~" and save count in `j`
   return(j>0?                   //  If `j` is larger than 0:
           "-"                   //   Start with a minus sign
           +s                    //   followed by the remaining `s`
           +"-"                  //   followed by another minus sign
           +-~i                  //   followed by `i+1`
          :                      //  Else:
           s                     //   Start with the remaining `s`
           +"+"                  //   followed by a plus sign
           +i                    //   followed by `i`
         ).replaceAll("--","");  //  And then remove all "--"
}                                // End of method

Java 8, 186 168 bytes

s->{s=s.replaceAll("--|~~","");int l,i=(s.length()-(l=(s=s.replace("-~","")).length()))/2;return(l-(s=s.replace("~","")).length()>0?"-"+s+~i:s+"+"+i).replace("--","");}

Try it online.

Explanation:

s->{                            // Method with String as both parameter and return-type
  s=s.replaceAll("--|~~","");   //  Remove all "--" and "~~"
  int l,                        //  Temp integer to reduce bytes
      i=(s.length()-(l=(s=s.replaceAll("-~","")).length()))/2;
                                //  Remove all "-~" and save count in `i`
  return(l-(s=s.replaceAll("~","")).length()
                                //  Remove all remaining "~" 
         >0?                    //  and if its non-empty:
           "-"                  //   Start with a minus sign
           +s                   //   followed by the remaining `s`
           +~i                  //   followed by `-i-1`
          :                     //  Else:
           s                    //   Start with the remaining `s`
           +"+"                 //   followed by a plus sign
           +i                   //   followed by `i`
         ).replaceAll("--","");}//  And then remove all "--"
Commonmark migration
Source Link

#Java 8, 186 bytes

Java 8, 186 bytes

#Java 8, 186 bytes

Java 8, 186 bytes

Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading