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
  • 2
    \$\begingroup\$ Welcome to PPCG and nice first answer. You can shorten your code by using a few tricks. Here is a more golfed version of your code: Try it online!. \$\endgroup\$ Commented Oct 10, 2017 at 17:01
  • \$\begingroup\$ Thanks for the comments, I assumed my code had to be executable by itself, so I built it upon that assumption! Thanks for the comment and the mentoring. \$\endgroup\$ Commented Oct 11, 2017 at 7:29
  • 2
    \$\begingroup\$ If you want to find some more tricks on how to golf in C#, take a look at this post, or take a look at existing C# answers. Happy golfing! \$\endgroup\$ Commented Oct 11, 2017 at 7:31
  • \$\begingroup\$ Nice answer. Keep going :) \$\endgroup\$ Commented Oct 12, 2017 at 13:24
  • 1
    \$\begingroup\$ Hi, welcome to PPCG! Great first answer, especially now that it's golfed. +1 from me. Btw, it's currently 180 bytes, not 162. The required import using System.Linq; is unfortunately mandatory to add to the byte-count (or you should change Max to System.Linq.Max and Select to System.Linq.Max, which would be higher than simply using System.Linq; once.) Again welcome, and enjoy your stay. Oh, and I see @IanH. already mentioned Tips for Golfing in C#. Tips for golfing in <all languages> might also be interesting to read through. \$\endgroup\$ Commented Oct 17, 2017 at 13:43

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