So you want to create a haiku, but you're not sure if it follows the syllable rules for a haiku.
I couldn't be bothered to write a proper blurb like I usually do, so you'll have to make do with this. Let's get stuck right in.
Finding a haiku out in the wild
For the purposes of this challenge, we will be checking if the given poem satisfies these criteria:
- There are three lines.
- The first line has 5 syllables.
- The second line has 7 syllables.
- The third line has 5 syllables.
Each line is composed of one or more words, separated by groups of spaces. These words are not necessarily valid English words.
Each word is split up into syllables, and then those syllables are counted to get the total syllable count of the line.
A syllable has either 2 or 3 parts to it: the beginning, the end, and possibly the middle. Each part is either a group of consonsants (also known as a consonant cluster, such as
spl) or a group of vowels (such as
If the beginning is a group of consonants, the middle will be a group of vowels and the end will be a group of consonants. If the beginning is a group of vowels, the end will be a group of consonants and there will be no middle.
For example, the word
example is made up of three syllables,
ple has no ending as it was cut short by the end of the word.
As another example, the word
syllable also has three syllables,
e, which also has no ending.
For one final example, the word
word has one syllable,
word, which ends with a group of consonants.
Given a string, list of strings, list of lists or any other reasonable format representing a poem with at least one line, determine if it meets the criteria of a haiku outlined above and return the result.
You may return the result in any of these formats:
- A truthy value if the poem is a haiku and a falsy one otherwise.
- A falsy value if the poem is a haiku and a truthy one otherwise.
- A value from a finite range of values specified in the submission if the poem is a haiku and a value from a mutually exclusive finite range of values also specified in the submission.
You may also assume the poem contains no non-alphabetical characters, but you may not assume that it is entirely in uppercase or lowercase.
For the purposes of this challenge,
Y is a vowel.
This is a haiku Yes it truly is one See what I did man
I am so tired of writing this already when can I stop this
Writing another Of these horrific things Come on please
Consonant only Counts as one syllable ghjk tgh knmb wrts vbc
oh boy writing non haiku is so much easier
This is so good on my poor dear brain
The syllables do not match at least I do not think so I have not checked
It does not really matter these test cases will help At least I think they will
I am done here This is enough Goodbye
Since this is code-golf
The shortest answer will win
Good luck to you all