35
3
Write a program or a function that will output a given string in a staircase fashion, writing each part of a word that starts with a vowel one line below the previous part.
For example:
Input: Programming Puzzles and Code Golf
Output: Pr P C G
ogr uzzl and od olf
amm es e
ing
Input
A string containing nothing but letters and spaces.
The string can be passed via STDIN
or function arguments or anything equivalent.
Letters can be lowercase or uppercase.
Inputs are always assumed to follow those rules, you don't need to check for incorrect inputs.
Output
Each time a vowel (that is, a
, e
, i
, o
, u
or y
) is encountered in a word, you must output the rest of the word on the next line (the encountered vowel included), at the correct horizontal position. This rule is recursive, which means that if there are n vowels in the word, it will be written on n+1 lines.
The vowel should be written at the beginning of the next line, and not at the end of the previous line when one is encountered.
Each word starts on the first line, and should thus be formatted independently from other words. Two words are separated by a space.
If a word starts with a vowel, you have to write it starting on the second line.
Test cases
- Input:
Programming Puzzles and Code Golf
Output:
Pr P C G
ogr uzzl and od olf
amm es e
ing
- Input:
The quick brown fox jumps over the lazy dog
Output:
Th q br f j th l d
e u own ox umps ov e az og
ick er y
- Input:
aeiouy
Output:
a
e
i
o
u
y
- Input:
YEAh UppErcAsE VOwEls
Output:
V
Y Upp Ow
E Erc Els
Ah As
E
- Input:
If you only knew the power of the Dark Side
Output:
kn th p th D S
If y onl ew e ow of e ark id
o y er e
u
Scoring
This is code-golf, so the shortest code wins.
The third output example seems inconsistent with the rule "If a word starts with a vowel, you have to write it starting on the second line." – JohnE – 2015-07-01T15:01:24.503
1Y is Y a vowel ? – Optimizer – 2015-07-01T15:02:55.317
1@JohnE indeed it was, I fixed it. Thanks. – Fatalize – 2015-07-01T15:03:43.330
@Optimizer Y is used as both in English, so I say it is a vowel in this challenge – Fatalize – 2015-07-01T15:04:30.443
Related. Related. – Martin Ender – 2015-07-01T15:08:33.763
2
The vowel should be written at the beginning of the next line, and not at the end of the previous line when one is encountered.
After some thought, I understand that this means that the move to the next line should happen before the vowel is printed, not after, but it might be worth wording this in a way that is instantly understandable - it took me a while. – trichoplax – 2015-07-01T15:09:26.9833Is trailing newlines / spaces allowed? – Loovjo – 2015-07-01T15:31:00.057
@Loovjo There shouldn't be any unnecessary empty lines. so no. There can be extra spaces at the end of lines as long as it does not make the line longer than the longest line (for instance on the first example, you can have extra spaces on the first line up to the
f
at the end of the second line) – Fatalize – 2015-07-01T15:48:22.623Btw, the UppErcAsE VOwEls are missing backticks. – Loovjo – 2015-07-01T15:53:53.300
@Loovjo Fixed, thanks. – Fatalize – 2015-07-01T15:55:11.413