43
1
Given a string as input, print a new string with each letter pushed to the right by its respective alphabet index.
We all know that A is a slow and Z is a fast letter. This means that Z gets shifted to the right by 25 spaces, A doesn't get shifted at all and B gets shifted by 1 space.
Your program only has to handle uppercase letters from A-Z, and no other characters, no whitespaces, no punctuation.
Note that if 2 or more letters fall onto the same space after shifting, the latest character will be used. (Example: BA
-> A
)
Examples
"AZ" -> "A Z"
"ABC" -> "A B C"
"ACE" -> "A C E"
"CBA" -> " A"
"HELLOWORLD" -> " E H DLL OLO R W"
Rules
- This is code-golf, so the shortest code in any language bytes wins.
Standard loopholes are forbidden.
Input must be received as a string.
- You may print the result to
stdout
or return a string. - A single trailing whitespace and/or newline is allowed.
- You may also use lowercase letters as input or output, but only use either case.
Trailing whitespace okay? – Okx – 2017-10-13T13:56:56.760
@Okx Yes, note my previous comment. – Ian H. – 2017-10-13T13:58:27.587
1What about a lot of trailing spaces? – Okx – 2017-10-13T13:59:04.210
1@Okx Forbidden, one is all you get. – Ian H. – 2017-10-13T13:59:29.400
I assume we can use lowercase letters instead, right? – Mr. Xcoder – 2017-10-13T15:53:52.480
@Mr.Xcoder If you keep it consistently at only lowercase letters, yes. – Ian H. – 2017-10-13T19:23:41.190
Is it alright to have a single leading space? – miles – 2017-10-14T02:07:50.010
@miles Leading newlines yes, but no leading spaces. – Ian H. – 2017-10-14T06:14:32.567