Skip to main content
deleted 4 characters in body
Source Link
Kevin Cruijssen
  • 136.1k
  • 14
  • 154
  • 394

05AB1E, 19 bytes

œJJæé.ΔIåP}ÐIk©èu®ǝ

Based on @JonathanAllan's Jelly answer, but even slower. 😅

Input-list of words in full lowercase.

(Don't) try it online.

A slightly faster approach (replacing œJJæé with S©ε®N>.Æ}€`J) that is able to output most individual test cases (although it's still pretty slow, and still won't be able to output the first two test cases..):

S©ε®N>.Æ}€`J.ΔIåP}ÐIk©èu®ǝ

Try it online.

Explanation:

œ                # Get all permutations of the (implicit) input-list
 J               # Join each inner list of words together
  J              # Then join everything together to one large string
   æ             # Get the powerset of this
    é            # Sort it by length (shortest to longest)
     .Δ          # Pop and find the first/shortest that's truthy for:
        å        #  It contains as substrings
         P       #  all
       I         #  the input-words
      }Ð         # After we've got our shortest string: triplicate it
        I        # Push the input-list of words
         k       # Get the index of each word in the top copy
          ©      # Store those indices in variable `®` (without popping)
           è     # Pop another copy, and get the characters at those indices
            u    # Uppercase each character
             ®ǝ  # Insert them back into the string at indices `®`
                 # (after the loop,which the result is output implicitly)

05AB1E, 19 bytes

œJJæé.ΔIåP}ÐIk©èu®ǝ

Based on @JonathanAllan's Jelly answer, but even slower. 😅

Input-list of words in full lowercase.

(Don't) try it online.

A slightly faster approach (replacing œJJæé with S©ε®N>.Æ}€`J) that is able to output most individual test cases (although it's still pretty slow, and still won't be able to output the first two test cases..):

S©ε®N>.Æ}€`J.ΔIåP}ÐIk©èu®ǝ

Try it online.

Explanation:

œ                # Get all permutations of the (implicit) input-list
 J               # Join each inner list of words together
  J              # Then join everything together to one large string
   æ             # Get the powerset of this
    é            # Sort it by length (shortest to longest)
     .Δ          # Pop and find the first/shortest that's truthy for:
        å        #  It contains as substrings
         P       #  all
       I         #  the input-words
      }Ð         # After we've got our shortest string: triplicate it
        I        # Push the input-list of words
         k       # Get the index of each word in the top copy
          ©      # Store those indices in variable `®` (without popping)
           è     # Pop another copy, and get the characters at those indices
            u    # Uppercase each character
             ®ǝ  # Insert them back into the string at indices `®`
                 # (after the loop, the result is output implicitly)

05AB1E, 19 bytes

œJJæé.ΔIåP}ÐIk©èu®ǝ

Based on @JonathanAllan's Jelly answer, but even slower. 😅

Input-list of words in full lowercase.

(Don't) try it online.

A slightly faster approach (replacing œJJæé with S©ε®N>.Æ}€`J) that is able to output most individual test cases (although it's still pretty slow, and still won't be able to output the first two test cases..):

S©ε®N>.Æ}€`J.ΔIåP}ÐIk©èu®ǝ

Try it online.

Explanation:

œ                # Get all permutations of the (implicit) input-list
 J               # Join each inner list of words together
  J              # Then join everything together to one large string
   æ             # Get the powerset of this
    é            # Sort it by length (shortest to longest)
     .Δ          # Pop and find the first/shortest that's truthy for:
        å        #  It contains as substrings
         P       #  all
       I         #  the input-words
      }Ð         # After we've got our shortest string: triplicate it
        I        # Push the input-list of words
         k       # Get the index of each word in the top copy
          ©      # Store those indices in variable `®` (without popping)
           è     # Pop another copy, and get the characters at those indices
            u    # Uppercase each character
             ®ǝ  # Insert them back into the string at indices `®`
                 # (after which the result is output implicitly)
Source Link
Kevin Cruijssen
  • 136.1k
  • 14
  • 154
  • 394

05AB1E, 19 bytes

œJJæé.ΔIåP}ÐIk©èu®ǝ

Based on @JonathanAllan's Jelly answer, but even slower. 😅

Input-list of words in full lowercase.

(Don't) try it online.

A slightly faster approach (replacing œJJæé with S©ε®N>.Æ}€`J) that is able to output most individual test cases (although it's still pretty slow, and still won't be able to output the first two test cases..):

S©ε®N>.Æ}€`J.ΔIåP}ÐIk©èu®ǝ

Try it online.

Explanation:

œ                # Get all permutations of the (implicit) input-list
 J               # Join each inner list of words together
  J              # Then join everything together to one large string
   æ             # Get the powerset of this
    é            # Sort it by length (shortest to longest)
     .Δ          # Pop and find the first/shortest that's truthy for:
        å        #  It contains as substrings
         P       #  all
       I         #  the input-words
      }Ð         # After we've got our shortest string: triplicate it
        I        # Push the input-list of words
         k       # Get the index of each word in the top copy
          ©      # Store those indices in variable `®` (without popping)
           è     # Pop another copy, and get the characters at those indices
            u    # Uppercase each character
             ®ǝ  # Insert them back into the string at indices `®`
                 # (after the loop, the result is output implicitly)