ΔA3ãvy'.«ÀDõ1ǝ:
Try it online or verify all test cases. (Extremely slow, so the A
has been replaced with Dálê
(duplicate; keep letters; convert to lowercase; sorted-uniquify) in the TIO-links.)
Original 20 bytes approach:
'.©¡Rć¬.uisć}s€н`r®ý
Try it online or verify all test cases.
Explanation:
I basically keep replacing every ab.c
to a.c
, where abc
are any combination of lowercase letter including duplicates:
Δ # Loop until the result no longer changes,
# using the (implicit) input-string in the first iteration
A # Push the lowercase alphabet
3ã # Create all possible triplets of lowercase letters with the
# cartesian power of 3
v # Loop over each triplet `y`:
y'.« '# Append a "." to the triplet
À # Rotate it once towards the right: "abc." to "ab.c"
D # Duplicate it
õ1ǝ # Replace the character at index 1 with "": "ab.c" to "a.c"
: # Replace all "ab.c" in the string to "a.c"
# (after which the resulting string is output implicitly)
'. '# Push "."
© # Store it in variable `®` (without popping)
¡ # Pop and split the (implicit) input by this "."
R # Reverse this list
ć # Extract head; pop and push remainder-list and first item separated
# to the stack
¬ # Get the first character (without popping the string)
.ui # Pop, and if it's uppercase:
s # Swap so the remainder-list is at the top of the stack
ć # Extract its head again
} # Close the if-statement
s # Swap so the remainder-list is at the top of the stack
€ # Map over each string in this list:
н # Pop and only leave its first character
` # Pop and dump these characters to the stack
r # Reverse the stack
®ý # Join the stack by the "."-delimiter from variable `®`
# (after which the result is output implicitly)
fantastic.foo.func.bar
becomef.f.f.bar
or is it guaranteed that 2 packages can't start with the same letter? \$\endgroup\$f.f.f.bar
would be correct. \$\endgroup\$