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

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Make some Alphabet Rain

Alphabet Rain

The Task:

The basic premise is to print out the input string and then repeat each character vertically, based on it's (0-indexed) position in the (case-insensitive) alphabet A-Z. A is at location 0 so is not repeated, e is at position 4 so is repeated 4 times, P is at position 15 so is repeated 15 times, ! is not in A-Z so is repeated 0 times, etc.

For clarity, anything that falls outside of the range B-Zb-z, for example digits or special characters, will not be repeated, and thus will only appear on the first line.

This is , so shortest solution in each language is the winner.

Input:

  • Input will be in the standard printable ASCII character set, from 32 up to 126 ~.
  • The input string will be 1 character long or longer.
  • There will not be any leading or trailing whitespace.
  • You can take take input as a string ("hello") or list of characters ( ["h", "e", "l", "l", "o"])

Examples:

Input of aaaa gives:

aaaa

Input of abcda gives:

abcda
 bcd
 cd
 d

Input of Programming Puzzles & Code Golf!, gives:

Programming Puzzles & Code Golf!
Progr mming Puzzles Code Golf
Progr mming Puzzles Code Golf
Progr mming Puzzles ode Golf
Progr mming Puzzles o e Golf
Progr mming Puzzl s o Golf
Progr mming Puzzl s o Gol
Pro r mmin Puzzl s o ol
Pro r mmin Puzzl s o ol
Pro r mm n Puzzl s o ol
Pro r mm n Puzzl s o ol
Pro r mm n Puzzl s o ol
Pro r mm n Puzz s o o
Pro r n Puzz s o o
Pro r Puzz s o o
Pr r Puzz s
 r r uzz s
 r r uzz s
 uzz s
 uzz
 uzz
 zz
 zz
 zz
 zz
 zz

Input of ~|[abc<0>cba]|~, gives:

~|[abc<0>cba]|~
 bc cb
 c c

Notes:

  • standard loopholes apply
  • output can be a list of strings, but:
  • extraneous trailing newlines are not allowed (single \n on final line is acceptable)
  • output can be a list of lists of characters, so long as it looks like it's raining characters
  • no leading newline
  • to our Nordic users who have a few extra letters in their "A-Z" alphabet, feel free to support them, but it's not part of the challenge

Answer*

Draft saved
Draft discarded
Cancel
5
  • \$\begingroup\$ For future readers: The part "this answer only works on Mathematica..." is a bit misleading, the problem is Mathematica only support Unicode character in notebook (REPL) mode. In script mode, it only understand ASCII and special characters which have been converted to ASCII (e.g., (3 bytes) -> \[Infinity] (11 bytes)). \$\endgroup\$ Commented Oct 10, 2017 at 16:17
  • \$\begingroup\$ @user202729 ok,I'll edit and address people to read your comment.thanks \$\endgroup\$ Commented Oct 10, 2017 at 16:20
  • \$\begingroup\$ Golf suggestion for Mathematica (script mode): \[Infinity] (11 bytes) can be replaced by Infinity (8 bytes) or \:221e (6 bytes). The last one is the default representation of special characters without names. (although it is not the main part) \$\endgroup\$ Commented Oct 10, 2017 at 16:21
  • \$\begingroup\$ We can avoid Infinity entirely. The problematic part is If[(d=Min@Position[Alphabet[],If[UpperCaseQ@#,ToLowerCase@#,#]])==∞,1,d] and we can change this to Max@Position[Alphabet[]/."a"->#,#|ToLowerCase@#]. (Searching in the list {#,b,c,d,...,y,z}, we're guaranteed to find # at least once.) \$\endgroup\$ Commented Oct 10, 2017 at 23:53
  • \$\begingroup\$ @MishaLavrov very nice. fixed it! \$\endgroup\$ Commented Oct 11, 2017 at 0:36

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