7 kyu

Haiku Wizard

267 of 527lucymk

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:

  1. a function, haikuWizard(), which you have to complete.
  2. 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. So words[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 turn arr into a haiku using the preloaded array words ($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 of words.
  • the return string should display a beautiful haiku with the correct structure.

Enjoy!

Arrays
Fundamentals

Similar Kata:

Stats:

CreatedJul 7, 2017
PublishedJul 12, 2017
Warriors Trained973
Total Skips15
Total Code Submissions1693
Total Times Completed527
JavaScript Completions231
Crystal Completions8
Python Completions267
Ruby Completions63
Total Stars16
% of votes with a positive feedback rating94% of 188
Total "Very Satisfied" Votes166
Total "Somewhat Satisfied" Votes20
Total "Not Satisfied" Votes2
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • lucymk Avatar
  • GiacomoSorbi Avatar
  • docgunthrop Avatar
  • Blind4Basics Avatar
  • Haksell Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad