#Java 810, 228 227227 224 182 bytes
s->{int l=s.length();return l>6?s:l>5?s+s.charAt(5):l>4?s.replaceAll("(.)(.)(.)(.)$","$1$4$2$4$3$4"):l>3?s.replaceAll("([^#])","$1$1"):l>2?s.replaceAll("([^#]{2})","$1$1$1"):l>1?s.replaceAll("([^#])","$1$1$1$1$1$1"):"#000000";}
I have the feeling some parts can be golfed, especially the regexes. Regexes aren't really my expertise..
s->{var x="$1$1";int l=s.length();return l>6?s:l>5?s+s.charAt(5):l<2?"#000000":s.replaceAll(l>4?"(.)(.)(.)(.)$":l==3?"([^#]{2})":"([^#])",l>4?"$1$4$2$4$3$4":l>3?x:l>2?x+"$1":x+x+x);}
PS: When I change "$1$1"
, "$1$1$1"
and "$1$1$1$1$1$1"
to String t="$1$1";
, x
, x+"$1"
and x+x+x
the byte-count stays the same.Try it online.
Try it here.
s->{ // Method with String parameter and String return-type
int l=s.length(); // Length of the String
return l>6? // If the length is 7:
s // Return the input-String
:l>5? // Else-if the length is 6:
s+s.charAt(5) // Return the input-String with the last character repeated
:l>4? // Else-if the length is 5:
s.replaceAll("(.)(.)(.)(.)$","$1$4$2$4$3$4")
// Use a regex with capture group to return the correct #ADBDCD pattern
:l>3? // Else-if the length is 4:
s.replaceAll("([^#])","$1$1") // Repeat every character, except the starting #
:l>2? // Else-if the length is 3:
s.replaceAll("([^#]{2})","$1$1$1") // Repeat every two characters three times, except the starting #
:l>1? // Else-if the length is 2:
s.replaceAll("([^#])","$1$1$1$1$1$1") // Repeat the character 6 times, excluding the starting #
: // Else:
"#000000"; // Simply return the literal String #000000
} // End of method
s->{ // Method with String as both parameter and return-type
var x="$1$1"; // Create a temp String to repeat a match
int l=s.length(); // Length of the String
return l>6? // If the length is 7:
s // Return the input-String as is
:l>5? // Else-if the length is 6:
s+s.charAt(5) // Return the input-String with the last character repeated
:l<2? // Else-if the length is 1:
"#000000"; // Simply return the literal String #000000
: // Else (the length is 2, 3, 4, or 5):
s.replaceAll( // Return the input-String after a regex replace:
// With as match:
l>4? // If the length is 5:
"(.)(.)(.)(.)$", // Use a match for pattern #(A)(B)(C)(D)
:l==3? // Else-if the length is 3:
"([^#]{2})" // Use a match for pattern #(AB)
: // Else (the length is 2 or 4):
"([^#])", // Use a match for pattern #(A) or #(A)(B)(C)
// And as replacement:
l>4? // If the length is 5:
"$1$4$2$4$3$4" // Change #ABCD to #ADBDCD
:l>3? // Else-if the length is 4:
x // Change #ABC to #AABBCC
:l>2? // Else-if the length is 3:
x+"$1" // Change #AB to #ABABAB
: // Else (the length is 2):
x+x+x);} // Change #A to #AAAAAA