#Java 8, 228 227 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..
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.
Explanation:
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