-10 bytes by implementing the algorithm found by Leo in their brilliant Husk answer.
i€0Ṁḣ@
;€”$µ=þç"
or...
;€”$µ=i0µþ⁸Ṁ€⁸ḣ"
A monadic link taking and returning lists of lists of characters.
Try it online! (the footer makes a full program which prints the result split by newlines.)
How?
i€0Ṁḣ@ - helper link, create an entry of the output: equality row, string with trailing '$'
i€0 - first index of zero in €ach entry of the row
Ṁ - maximum
ḣ@ - head to index with swapped @rguments (the prefix of the string)
;€”$µ=þç" - link: list of lists of characters (list of "strings")
”$ - literal '$'
;€ - concatenate for €ach
µ - monadic chain separation (call that x)
þ - table of (with x on the left and, implicitly, on the right):
= - equals? (vectorises)
" - zip with (with the table on the left and, implicitly, x on the right)
ç - call the last link as a dyad
My original:
-2 bytes thanks to Erik the Outgolfer (replace ḣJ$
with ;\
and ẎċЀЀ$
with ċ@€€Ẏ$
)
NMḢ⁹ḣ;⁸Ṃẋ@”$¤Ṗ
;\€ċ@€€Ẏ$ç"
A monadic link taking and returning lists of lists of characters.
Try it online! (the footer makes a full program which prints the result split by newlines.)
I'm almost certain this is beatable, and probably by a decent margin! (although I have attempted to golf the method.)
The same byte count may be achieved without a helper link too, with:
ḣJ$€ẎċЀЀ$ðNMḢ⁹ḣ;⁸Ṃẋ@”$¤Ṗð"
How?
Note: the reusable link is the second line of code, so start there.
NMḢ⁹ḣ;⁸Ṃẋ@”$¤Ṗ - helper link, create an entry of the output: prefix counts, string
- ("prefix counts" should be counts of the prefixes of the "string" in
the totality of prefixes of *all* the strings)
N - negate the counts
M - maximal indexes (lengths of prefixes appearing least often, ascending)
Ḣ - head (finds the minimal length required), call that ml
⁹ - chain's right argument (prefixes)
ḣ - head (string) to index ml (gets the minimal length prefix)
¤ - nilad followed by links as a nilad:
⁸ - chain's left argument (prefix counts)
Ṃ - minimum (this will either be 1 or 2)
”$ - literal '$'
ẋ@ - repeat with swapped @rguments (either "$" or "$$")
; - concatenate
Ṗ - pop (remove the last "$" - leaving one where the prefix occurs in another
- string's prefixes, and none otherwise)
;\€ċ@€€Ẏ$ç" - link: list of lists of characters (list of "strings")
€ - for €ach string
\ - cumulative reduce with:
; - concatenation
- (gets a list of lists of prefixes)
$ - last two links as a monad:
Ẏ - tighten (flatten by one to make a single list of all prefixes)
@ - swap arguments
€€ - for each prefix in each list of prefixes
ċ - count occurrences in the tightened list (>=1 since it counts itself)
" - zip with the dyad (right argument is this link's argument):
ç - last link (helper) as a dyad
["ba,"baa","bab"]
a valid input? It does not have the same entry twice, but there is no N defined for the first string. If it is a valid input should it return["ba$","baa","bab"]
,["b$","baa","bab"]
,["ba$$","baa","bab"]
,["b$$","baa","bab"]
, any of the above, or something else? \$\endgroup\$