Skip to main content
Commonmark migration
Source Link

#Java 7, 201 bytes

Java 7, 201 bytes

#Java 7, 201 bytes

Java 7, 201 bytes

Java highlighting
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}
String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}
String c(String s){               // Method with String parameter and String return-type
  String r="",                    //  The return-String
         z="e([^e]|$)";           //  Partial regex String that's used twice ('e' followed by non-'e' or nothing)
  char p=0;                       //  The previous character
  int x;                          //  Another temp value
  for(char c : s.toCharArray()){  //  Loop over the characters of the input String
    x = c&~32;                    //   Make every lowercase character uppercase (this returns an integer, hence the integer temp value, which is shorter than a cast to char)
    p = x>64 & x<91 ?             //   If the current character is a letter:
         p == 66 ?                //    And if the previous character is 'B':
          'l'                     //     Set the character value to 'l'
         : p>100&p<109 ?          //    Else if the previous character is either an 'e' or 'l':
            'e'                   //     Set the character value to 'e'
           :                      //    Else:
            66                    //     Set the character value to 'B'
         :                        //   Else (not a letter):
          c;                      //    Set the character to the current character
    r += p;                       //   Append the result-String with this character
  }                               //  End loop
  return r                        //  Return the result-String
    .replaceAll("l"+z,"lt$1")     //   After we've replaced all occurrences of "le." with "lt." (where "." can be anything else, including nothing at the end of a line)
    .replaceAll(z,"et$1")         //   And also replaced all occurrences of "ee." with "et." (where "." can again be anything else)
}                                 // End of method
String c(String s){               // Method with String parameter and String return-type
  String r="",                    //  The return-String
         z="e([^e]|$)";           //  Partial regex String that's used twice ('e' followed by non-'e' or nothing)
  char p=0;                       //  The previous character
  int x;                          //  Another temp value
  for(char c : s.toCharArray()){  //  Loop over the characters of the input String
    x = c&~32;                    //   Make every lowercase character uppercase (this returns an integer, hence the integer temp value, which is shorter than a cast to char)
    p = x>64 & x<91 ?             //   If the current character is a letter:
         p == 66 ?                //    And if the previous character is 'B':
          'l'                     //     Set the character value to 'l'
         : p>100&p<109 ?          //    Else if the previous character is either an 'e' or 'l':
            'e'                   //     Set the character value to 'e'
           :                      //    Else:
            66                    //     Set the character value to 'B'
         :                        //   Else (not a letter):
          c;                      //    Set the character to the current character
    r += p;                       //   Append the result-String with this character
  }                               //  End loop
  return r                        //  Return the result-String
    .replaceAll("l"+z,"lt$1")     //   After we've replaced all occurrences of "le." with "lt." (where "." can be anything else, including nothing at the end of a line)
    .replaceAll(z,"et$1")         //   And also replaced all occurrences of "ee." with "et." (where "." can again be anything else)
}                                 // End of method
class M{
  static String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

  public static void main(String[] a){
    System.out.println(c("Hello, World!"));
    System.out.println(c("lorem ipsum dolor sit amet."));
    System.out.println(c("We praise the Goat God!"));
    System.out.println(c("I have a pen"));
    System.out.println(c("0123456789_"));
    System.out.println(c("0te_st1"));
  }
}
class M{
  static String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

  public static void main(String[] a){
    System.out.println(c("Hello, World!"));
    System.out.println(c("lorem ipsum dolor sit amet."));
    System.out.println(c("We praise the Goat God!"));
    System.out.println(c("I have a pen"));
    System.out.println(c("0123456789_"));
    System.out.println(c("0te_st1"));
  }
}
Bleeet, Bleeet!
Bleeet Bleeet Bleeet Blt Bleet.
Bl Bleeeet Blt Bleet Blt!
B Bleet B Blt
0123456789_
0Bl_Bl1
Bleeet, Bleeet!
Bleeet Bleeet Bleeet Blt Bleet.
Bl Bleeeet Blt Bleet Blt!
B Bleet B Blt
0123456789_
0Bl_Bl1
String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}
String c(String s){               // Method with String parameter and String return-type
  String r="",                    //  The return-String
         z="e([^e]|$)";           //  Partial regex String that's used twice ('e' followed by non-'e' or nothing)
  char p=0;                       //  The previous character
  int x;                          //  Another temp value
  for(char c : s.toCharArray()){  //  Loop over the characters of the input String
    x = c&~32;                    //   Make every lowercase character uppercase (this returns an integer, hence the integer temp value, which is shorter than a cast to char)
    p = x>64 & x<91 ?             //   If the current character is a letter:
         p == 66 ?                //    And if the previous character is 'B':
          'l'                     //     Set the character value to 'l'
         : p>100&p<109 ?          //    Else if the previous character is either an 'e' or 'l':
            'e'                   //     Set the character value to 'e'
           :                      //    Else:
            66                    //     Set the character value to 'B'
         :                        //   Else (not a letter):
          c;                      //    Set the character to the current character
    r += p;                       //   Append the result-String with this character
  }                               //  End loop
  return r                        //  Return the result-String
    .replaceAll("l"+z,"lt$1")     //   After we've replaced all occurrences of "le." with "lt." (where "." can be anything else, including nothing at the end of a line)
    .replaceAll(z,"et$1")         //   And also replaced all occurrences of "ee." with "et." (where "." can again be anything else)
}                                 // End of method
class M{
  static String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

  public static void main(String[] a){
    System.out.println(c("Hello, World!"));
    System.out.println(c("lorem ipsum dolor sit amet."));
    System.out.println(c("We praise the Goat God!"));
    System.out.println(c("I have a pen"));
    System.out.println(c("0123456789_"));
    System.out.println(c("0te_st1"));
  }
}
Bleeet, Bleeet!
Bleeet Bleeet Bleeet Blt Bleet.
Bl Bleeeet Blt Bleet Blt!
B Bleet B Blt
0123456789_
0Bl_Bl1
String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}
String c(String s){               // Method with String parameter and String return-type
  String r="",                    //  The return-String
         z="e([^e]|$)";           //  Partial regex String that's used twice ('e' followed by non-'e' or nothing)
  char p=0;                       //  The previous character
  int x;                          //  Another temp value
  for(char c : s.toCharArray()){  //  Loop over the characters of the input String
    x = c&~32;                    //   Make every lowercase character uppercase (this returns an integer, hence the integer temp value, which is shorter than a cast to char)
    p = x>64 & x<91 ?             //   If the current character is a letter:
         p == 66 ?                //    And if the previous character is 'B':
          'l'                     //     Set the character value to 'l'
         : p>100&p<109 ?          //    Else if the previous character is either an 'e' or 'l':
            'e'                   //     Set the character value to 'e'
           :                      //    Else:
            66                    //     Set the character value to 'B'
         :                        //   Else (not a letter):
          c;                      //    Set the character to the current character
    r += p;                       //   Append the result-String with this character
  }                               //  End loop
  return r                        //  Return the result-String
    .replaceAll("l"+z,"lt$1")     //   After we've replaced all occurrences of "le." with "lt." (where "." can be anything else, including nothing at the end of a line)
    .replaceAll(z,"et$1")         //   And also replaced all occurrences of "ee." with "et." (where "." can again be anything else)
}                                 // End of method
class M{
  static String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

  public static void main(String[] a){
    System.out.println(c("Hello, World!"));
    System.out.println(c("lorem ipsum dolor sit amet."));
    System.out.println(c("We praise the Goat God!"));
    System.out.println(c("I have a pen"));
    System.out.println(c("0123456789_"));
    System.out.println(c("0te_st1"));
  }
}
Bleeet, Bleeet!
Bleeet Bleeet Bleeet Blt Bleet.
Bl Bleeeet Blt Bleet Blt!
B Bleet B Blt
0123456789_
0Bl_Bl1
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 7, 201 bytes

String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

Not really happy with it, and can certainly be golfed some more..

Explanation:

String c(String s){               // Method with String parameter and String return-type
  String r="",                    //  The return-String
         z="e([^e]|$)";           //  Partial regex String that's used twice ('e' followed by non-'e' or nothing)
  char p=0;                       //  The previous character
  int x;                          //  Another temp value
  for(char c : s.toCharArray()){  //  Loop over the characters of the input String
    x = c&~32;                    //   Make every lowercase character uppercase (this returns an integer, hence the integer temp value, which is shorter than a cast to char)
    p = x>64 & x<91 ?             //   If the current character is a letter:
         p == 66 ?                //    And if the previous character is 'B':
          'l'                     //     Set the character value to 'l'
         : p>100&p<109 ?          //    Else if the previous character is either an 'e' or 'l':
            'e'                   //     Set the character value to 'e'
           :                      //    Else:
            66                    //     Set the character value to 'B'
         :                        //   Else (not a letter):
          c;                      //    Set the character to the current character
    r += p;                       //   Append the result-String with this character
  }                               //  End loop
  return r                        //  Return the result-String
    .replaceAll("l"+z,"lt$1")     //   After we've replaced all occurrences of "le." with "lt." (where "." can be anything else, including nothing at the end of a line)
    .replaceAll(z,"et$1")         //   And also replaced all occurrences of "ee." with "et." (where "." can again be anything else)
}                                 // End of method

Test code:

Try it here.

class M{
  static String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

  public static void main(String[] a){
    System.out.println(c("Hello, World!"));
    System.out.println(c("lorem ipsum dolor sit amet."));
    System.out.println(c("We praise the Goat God!"));
    System.out.println(c("I have a pen"));
    System.out.println(c("0123456789_"));
    System.out.println(c("0te_st1"));
  }
}

Output:

Bleeet, Bleeet!
Bleeet Bleeet Bleeet Blt Bleet.
Bl Bleeeet Blt Bleet Blt!
B Bleet B Blt
0123456789_
0Bl_Bl1