Skip to main content
Commonmark migration
Source Link

#Java 10, 161 159 152 bytes

Java 10, 161 159 152 bytes

#Java 10, 161 159 152 bytes

Java 10, 161 159 152 bytes

deleted 237 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 810, 161 159159 152 bytes

s->{Stringvar x="",r=x;intx="";int p=0;for(charvar c:s)x+=p<(p=c)?c:";"+c;for(Stringvar y:x.split(";"))r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ".replaceAll("[^"+y+"\n]""[^"+y+"]"," ");return r;);}

-2 bytes thanks to @Nevay.
-7 byte printing directly instead of returning a String, and converting to Java 10.

Try it here.Try it here.

s->{                          // Method with String as both parameter and no return-type
  String x="",var x="";               //  Temp-String
         r=x;                 //  Result-String
  int p=0;                    //  Previous character (as integer), starting at 0
  for(charvar c:s)               //  Loop (1) over the characters of the input
    x+=p<(p=c)?               //   If the current character is later in the alphabet
                              //   (replace previous `p` with current `c` afterwards)
        c                     //    Append the current character to Temp-String `x`
       :                      //   Else:
        ";"+c;                //    Append a delimiter ";" + this character to Temp-String `x`
                              //  End of loop (1) (implicit / single-line body)
  for(Stringvar y:x.split(";"))  //  Loop (2) over the String -parts
    r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"System.out.println(   //   Print, with trailing new-line:
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                          //    Take the alphabet,
        .replaceAll("[^"+y+"\n]""[^"+y+"]"," "));}
                              //    and replace all except the characters with a space
                              //  End of loop (2) (implicit / single-line body)
  return r;                   //letters not Returnin the result-String
}                             //-part Endwith ofa methodspace

The second part loops over these parts, and uses the regex [^...\n]] to replace everything that isn't matched with a space.
For example .replaceAll("[^CO\n]""[^CO]"," ") leaves the C, O and new-line \nO, and replaces everything else with a space.

#Java 8, 161 159 bytes

s->{String x="",r=x;int p=0;for(char c:s)x+=p<(p=c)?c:";"+c;for(String y:x.split(";"))r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n".replaceAll("[^"+y+"\n]"," ");return r;}

-2 bytes thanks to @Nevay.

Try it here.

s->{                          // Method with String as both parameter and return-type
  String x="",                //  Temp-String
         r=x;                 //  Result-String
  int p=0;                    //  Previous character (as integer)
  for(char c:s)               //  Loop (1) over the characters of the input
    x+=p<(p=c)?               //   If the current character is later in the alphabet
                              //   (replace previous `p` with current `c` afterwards)
        c                     //    Append the character to String `x`
       :                      //   Else:
        ";"+c;                //    Append a delimiter ";" + this character to String `x`
                              //  End of loop (1) (implicit / single-line body)
  for(String y:x.split(";"))  //  Loop (2) over the String parts
    r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
                              //   Take the alphabet,
        .replaceAll("[^"+y+"\n]"," ");
                              //   and replace all except the characters with a space
                              //  End of loop (2) (implicit / single-line body)
  return r;                   //  Return the result-String
}                             // End of method

The second part loops over these parts, and uses the regex [^...\n] to replace everything that isn't matched with a space.
For example .replaceAll("[^CO\n]"," ") leaves the C, O and new-line \n, and replaces everything else with a space.

#Java 10, 161 159 152 bytes

s->{var x="";int p=0;for(var c:s)x+=p<(p=c)?c:";"+c;for(var y:x.split(";"))System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ".replaceAll("[^"+y+"]"," "));}

-2 bytes thanks to @Nevay.
-7 byte printing directly instead of returning a String, and converting to Java 10.

Try it here.

s->{                      // Method with String parameter and no return-type
  var x="";               //  Temp-String
  int p=0;                //  Previous character (as integer), starting at 0
  for(var c:s)            //  Loop (1) over the characters of the input
    x+=p<(p=c)?           //   If the current character is later in the alphabet
                          //   (replace previous `p` with current `c` afterwards)
        c                 //    Append the current character to Temp-String `x`
       :                  //   Else:
        ";"+c;            //    Append a delimiter ";" + this character to Temp-String `x`
  for(var y:x.split(";")) //  Loop (2) over the String-parts
    System.out.println(   //   Print, with trailing new-line:
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                          //    Take the alphabet,
        .replaceAll("[^"+y+"]"," "));}
                          //    and replace all letters not in the String-part with a space

The second part loops over these parts, and uses the regex [^...] to replace everything that isn't matched with a space.
For example .replaceAll("[^CO]"," ") leaves the C, and O, and replaces everything else with a space.

added 72 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 8, 161161 159 bytes

s->{String x="",r=x;int p=0;for(char c:s){x+=c>px+=p<(p=c)?c:";"+c;p=c;}for";"+c;for(String y:x.split(";"))r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n".replaceAll("[^"+y+"\n]"," ");return r;}

-2 bytes thanks to @Nevay.

Explanation:"

Try it here.Try it here.

s->{                          // Method with String as both parameter and return-type
  String x="",                //  Temp-String
         r=x;                 //  Result-String
  int p=0;                    //  Previous character (as integer)
  for(char c:s){               //  Loop (1) over the characters of the input
    x+=c>px+=p<(p=c)?                   //   If the current character is later in the alphabet
        c                      //   (replace Appendprevious the`p` characterwith tocurrent String`c` `x`afterwards)
       : c                     //   Else:
 Append the character to String `x`
  ";"+c;     :           //    Append a delimiter ";" + this character to// String `x`
  Else:
  p=c;      ";"+c;                //   Replace theAppend previousa `p`delimiter with";" the+ currentthis `c`character to String `x`
  }                            //  End of loop (1) (implicit / single-line body)
  for(String y:x.split(";"))  //  Loop (2) over the String parts
    r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
                              //   Take the alphabet,
        .replaceAll("[^"+y+"\n]"," ");
                              //   and replace all except the characters with a space
                              //  End of loop (2) (implicit / single-line body)
  return r;                   //  Return the result-String
}                             // End of method

#Java 8, 161 bytes

s->{String x="",r=x;int p=0;for(char c:s){x+=c>p?c:";"+c;p=c;}for(String y:x.split(";"))r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n".replaceAll("[^"+y+"\n]"," ");return r;}

Explanation:"

Try it here.

s->{                          // Method with String as both parameter and return-type
  String x="",                //  Temp-String
         r=x;                 //  Result-String
  int p=0;                    //  Previous character (as integer)
  for(char c:s){              //  Loop (1) over the characters of the input
    x+=c>p?                   //   If the current character is later in the alphabet
        c                     //    Append the character to String `x`
       :                      //   Else:
        ";"+c;                //    Append a delimiter ";" + this character to String `x`
    p=c;                      //   Replace the previous `p` with the current `c`
  }                           //  End of loop (1)
  for(String y:x.split(";"))  //  Loop (2) over the String parts
    r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
                              //   Take the alphabet,
        .replaceAll("[^"+y+"\n]"," ");
                              //   and replace all except the characters with a space
                              //  End of loop (2) (implicit / single-line body)
  return r;                   //  Return the result-String
}                             // End of method

#Java 8, 161 159 bytes

s->{String x="",r=x;int p=0;for(char c:s)x+=p<(p=c)?c:";"+c;for(String y:x.split(";"))r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n".replaceAll("[^"+y+"\n]"," ");return r;}

-2 bytes thanks to @Nevay.

Explanation:"

Try it here.

s->{                          // Method with String as both parameter and return-type
  String x="",                //  Temp-String
         r=x;                 //  Result-String
  int p=0;                    //  Previous character (as integer)
  for(char c:s)               //  Loop (1) over the characters of the input
    x+=p<(p=c)?               //   If the current character is later in the alphabet
                              //   (replace previous `p` with current `c` afterwards)
        c                     //    Append the character to String `x`
       :                      //   Else:
        ";"+c;                //    Append a delimiter ";" + this character to String `x`
                              //  End of loop (1) (implicit / single-line body)
  for(String y:x.split(";"))  //  Loop (2) over the String parts
    r+="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"
                              //   Take the alphabet,
        .replaceAll("[^"+y+"\n]"," ");
                              //   and replace all except the characters with a space
                              //  End of loop (2) (implicit / single-line body)
  return r;                   //  Return the result-String
}                             // End of method
added 1 character in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384
Loading