Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 884 characters in body
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, 15 bytes

TṪS`?' €..."AZ"ġ>

Try it online!

Explanation

TṪS`?' €..."AZ"ġ> Implicit input, e.g. "HELLO"
 ġ> Split into strictly increasing substrings: x = ["H","EL","LO"]
 ..."AZ" The uppercase alphabet (technically, the string "AZ" rangified).
 Ṫ Outer product of the alphabet and x
 S`?' € using this function:
 Arguments: character, say c = 'L', and string, say s = "EL".
 € 1-based index of c in s, or 0 if not found: 2
 S`?' If this is truthy, then c, else a space: 'L'
 This gives, for each letter c of the alphabet,
 a string of the same length as x,
 containing c for those substrings that contain c,
 and a space for others.
T Transpose, implicitly print separated by newlines.

Husk, 15 bytes

TṪS`?' €..."AZ"ġ>

Try it online!

Husk, 15 bytes

TṪS`?' €..."AZ"ġ>

Try it online!

Explanation

TṪS`?' €..."AZ"ġ> Implicit input, e.g. "HELLO"
 ġ> Split into strictly increasing substrings: x = ["H","EL","LO"]
 ..."AZ" The uppercase alphabet (technically, the string "AZ" rangified).
 Ṫ Outer product of the alphabet and x
 S`?' € using this function:
 Arguments: character, say c = 'L', and string, say s = "EL".
 € 1-based index of c in s, or 0 if not found: 2
 S`?' If this is truthy, then c, else a space: 'L'
 This gives, for each letter c of the alphabet,
 a string of the same length as x,
 containing c for those substrings that contain c,
 and a space for others.
T Transpose, implicitly print separated by newlines.
Source Link
Zgarb
  • 43.2k
  • 4
  • 84
  • 265

Husk, 15 bytes

TṪS`?' €..."AZ"ġ>

Try it online!

AltStyle によって変換されたページ (->オリジナル) /