Haiku Wizard
Description:
Doesn't everyone love a haiku?
If you don't know what that is, let me make your day :D
A haiku is a traditional form of Japanese poetry, they normally have 3 lines with 5, 7 and 5 syllables respectively. For example:
codewars training day
regular expressions mean
many cups of tea
Feeling a little concerned that I'm about to ask you to write poetry? Fear not! You only have to translate the haiku from numbers to words, no need to start looking frantically for creative inspiration. Let me explain:
I'm giving you:
- a function,
haikuWizard()
, which you have to complete. - a big, predefined array (
word
in JavaScript & Crystal;$words
in Ruby) with lots of words organised in subarrays! As you can see, each subarray has 10 members and they are all words with the same number of syllables. Sowords[0]
contains words of 1 syllable,words[1]
contains words of 2 syllables and so on.[ ["like", "a", "tweet", "what", "for", "world", "whale", "one", "last", "sun"], ["ocean", "beauty", "tweet", "monster", "yellow", "return", "despair", "flower", "return", "contrast"], ["romantic", "curious", "banana", "jealousy", "tactlessly", "remorseful", "follower", "elephant", "however", "instagram"], ["salmonella", "consequently", "irregular", "intelligence", "vegetable", "ordinary", "alternative", "watermelon", "controversial", "marijuana"], ["lackadaisical", "serendipity", "colonoscopy", "dramatically", "parsimonius", "imagination", "electricity", "diabolical", "deforestation", "abomination"], ["extraterrestrial", "onomatopoeia", "responsibility", "revolutionary", "generalisation", "enthusiastically", "biodiversity", "veterinarian", "characteristically", "indefatigable"], ["oversimplification", "individuality", "decriminalisation", "compartmentalisation", "anaesthesiologist", "industrialisation", "buckminsterfullerene", "irresponsibility", "autobiographical", "utilitarianism"] ]
Back to our function: haikuWizard()
takes an array as its input. This array has 3 subarrays - each subarray represents a line of the haiku. For example:
[[52], [17, 23, 39, 18], [33, 22]]
For each number, the first digit tells you the number of syllables of the word, the second digit tells you which member of the relevant subarray it is.
For example:
52
: This means that the first line is made up of one word with 5 syllables, at index 2 in words[4]
.
[17, 23, 39, 18]
: This means that the second line is made up of 4 words. The first has 1 syllable and is at index 7 in words[0]
. The second has 2 syllables and is at index3 in words[1]
.
And so on...
All you have to do is complete the function haikuWizard()
so that it translates the given array back into the beautiful haiku it came from :)
You should return a string, which on using console.log should display in the appropriate haiku format:
console.log(str);
there's a trumpet man
waltzing around the canals
he's getting dizzy
The string itself will not have this format.
To summarise in case you don't feel like reading all that again:
haikuWizard()
should turnarr
into a haiku using the preloaded arraywords
($words
in Ruby).arr
has 3 subarrays, each represents a line of the haiku.- the first digit of each number in
arr
represents the number of syllables of the word, the second digit is its index in the relevant subarray ofwords
. - the return string should display a beautiful haiku with the correct structure.
Enjoy!
Similar Kata:
Stats:
Created | Jul 7, 2017 |
Published | Jul 12, 2017 |
Warriors Trained | 973 |
Total Skips | 15 |
Total Code Submissions | 1693 |
Total Times Completed | 527 |
JavaScript Completions | 231 |
Crystal Completions | 8 |
Python Completions | 267 |
Ruby Completions | 63 |
Total Stars | 16 |
% of votes with a positive feedback rating | 94% of 188 |
Total "Very Satisfied" Votes | 166 |
Total "Somewhat Satisfied" Votes | 20 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |