Java (JDK 10) Java (JDK 11), 146 bytes
String f(String x,String y){int c=x.replace(y," ").split(" ",-1).length-1;return c<1?" ."+x:y.repeat(y,c)+"."+f(y,x.replace(y,"")).replace(".","");}
Java (JDK 10), 146 bytes
String f(String x,String y){int c=x.replace(y," ").split(" ",-1).length-1;return c<1?" ."+x:repeat(y,c)+"."+f(y,x.replace(y,"")).replace(".","");}
Java (JDK 11), 146 bytes
String f(String x,String y){int c=x.replace(y," ").split(" ",-1).length-1;return c<1?" ."+x:y.repeat(c)+"."+f(y,x.replace(y,"")).replace(".","");}
Java (JDK 11)Java (JDK 10), 129146 bytes
String f(String x,String y){int c=x.splitreplace(y," ").split(" ",-1).length-1;return c<1?" ."+x:y.repeat(y,c)+"."+f(y,x.replace(y,"")).replace(".","");}
Try it online using Java 10! Try it online using Java 10! This TIO emulates String::repeat of Java 11 by writing Kevin Cruijssen's implementation as a helper method with the same amount of bytes.
String f(String x,String y){ //
int c=x.splitreplace(y," ").split(" ",-1).length-1; // Count the number of occurrences of y in x.
// Countreplace(y," ") fixes the numberissue ofon occurrencesspecial ofcharacters yfor inthe x.split hereafter
// .split(y" ",-1) makes sure that there are trailing elements
return c<1
? // If there are no occurrence, return
" ."+x // " ."+x
: // Else return
y.repeat(c) // y, c times
+ "." // append a dot
+ f(y,x.replace(y,"")).replace(".",""); // y divided by x without y, and remove all dots
}
Java (JDK 11), 129 bytes
String f(String x,String y){int c=x.split(y,-1).length-1;return c<1?" ."+x:y.repeat(c)+"."+f(y,x.replace(y,"")).replace(".","");}
Try it online using Java 10! This TIO emulates String::repeat of Java 11 by writing Kevin Cruijssen's implementation as a helper method with the same amount of bytes.
String f(String x,String y){ //
int c=x.split(y,-1).length-1; // Count the number of occurrences of y in x.
// .split(y,-1) makes sure that there are trailing elements
return c<1
? // If there are no occurrence, return
" ."+x // " ."+x
: // Else return
y.repeat(c) // y, c times
+ "." // append a dot
+ f(y,x.replace(y,"")).replace(".",""); // y divided by x without y, and remove all dots
}
Java (JDK 10), 146 bytes
String f(String x,String y){int c=x.replace(y," ").split(" ",-1).length-1;return c<1?" ."+x:repeat(y,c)+"."+f(y,x.replace(y,"")).replace(".","");}
Try it online using Java 10! This TIO emulates String::repeat of Java 11 by writing Kevin Cruijssen's implementation as a helper method with the same amount of bytes.
String f(String x,String y){ //
int c=x.replace(y," ").split(" ",-1).length-1; // Count the number of occurrences of y in x.
// replace(y," ") fixes the issue on special characters for the split hereafter
// .split(" ",-1) makes sure that there are trailing elements
return c<1
? // If there are no occurrence, return
" ."+x // " ."+x
: // Else return
y.repeat(c) // y, c times
+ "." // append a dot
+ f(y,x.replace(y,"")).replace(".",""); // y divided by x without y, and remove all dots
}
- 136.2k
- 14
- 154
- 394
Java (JDK 11), 129 bytes
String f(String x,String y){int c=x.split(y,-1).length-1;return c<1?" ."+x:y.repeat(c)+"."+f(y,x.replace(y,"")).replace(".","");}
Try it online using Java 10! Try it online using Java 10! This TIO emulates String::repeat of Java 11 by writing Kevin Cruijssen's implementation as a helper method with the same amount of bytes.
Explanations
String f(String x,String y){ //
int c=x.split(y,-1).length-1; // Count the number of occurrences of y in x.
// .split(y,-1) makes sure that there are trailing elements
return c<1
? // If there are no occurrence, return
" ."+x // " ."+x
: // Else return
y.repeat(c) // y, c times
+ "." // append a dot
+ f(y,x.replace(y,"")).replace(".",""); // y divided by x without y, and remove all dots
}
String.repeat(int) only exists since Java 11, hence the JDK 11 header. Alas and to my knowledge, there are currently no Java 11 online compiler / tester...
Java (JDK 11), 129 bytes
String f(String x,String y){int c=x.split(y,-1).length-1;return c<1?" ."+x:y.repeat(c)+"."+f(y,x.replace(y,"")).replace(".","");}
Try it online using Java 10! This TIO emulates String::repeat of Java 11 by writing Kevin Cruijssen's implementation as a helper method with the same amount of bytes.
Explanations
String f(String x,String y){ //
int c=x.split(y,-1).length-1; // Count the number of occurrences of y in x.
// .split(y,-1) makes sure that there are trailing elements
return c<1
? // If there are no occurrence, return
" ."+x // " ."+x
: // Else return
y.repeat(c) // y, c times
+ "." // append a dot
+ f(y,x.replace(y,"")).replace(".",""); // y divided by x without y, and remove all dots
}
String.repeat(int) only exists since Java 11, hence the JDK 11 header. Alas and to my knowledge, there are currently no Java 11 online compiler / tester...
Java (JDK 11), 129 bytes
String f(String x,String y){int c=x.split(y,-1).length-1;return c<1?" ."+x:y.repeat(c)+"."+f(y,x.replace(y,"")).replace(".","");}
Try it online using Java 10! This TIO emulates String::repeat of Java 11 by writing Kevin Cruijssen's implementation as a helper method with the same amount of bytes.
Explanations
String f(String x,String y){ //
int c=x.split(y,-1).length-1; // Count the number of occurrences of y in x.
// .split(y,-1) makes sure that there are trailing elements
return c<1
? // If there are no occurrence, return
" ."+x // " ."+x
: // Else return
y.repeat(c) // y, c times
+ "." // append a dot
+ f(y,x.replace(y,"")).replace(".",""); // y divided by x without y, and remove all dots
}
String.repeat(int) only exists since Java 11, hence the JDK 11 header. Alas and to my knowledge, there are currently no Java 11 online compiler / tester...