[Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not.


### About syllables

[Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of words. *In this kata*, a syllable is a part of a word including a vowel ("a-e-i-o-u-y") or a group of vowels (e.g. "ou", "ee", "ay"). A few examples: "tea", "can", "to·day", "week·end", "el·e·phant".

**However**, silent "E"s **do not** create syllables. *In this kata*, an "E" is considered silent if it's alone at the end of the word, preceded by one (or more) consonant(s) and there is at least one other syllable in the word. Examples: "age", "ar·range", "con·crete"; but not in "she", "blue", "de·gree".

Some more examples:
* one syllable words: "cat", "cool", "sprout", "like", "eye", "squeeze"
* two syllables words: "ac·count", "hon·est", "beau·ty", "a·live", "be·cause", "re·store"


## Examples
```
An old silent pond...
A frog jumps into the pond,
splash! Silence again.
```

...should return `True`, as this is a valid 5–7–5 haiku:
```
An old si·lent pond...            # 5 syllables
A frog jumps in·to the pond,      # 7
splash! Si·lence a·gain.          # 5
```

Another example:

```
Autumn moonlight -
a worm digs silently
into the chestnut.
```

...should return `False`, because the number of syllables per line is not correct:
```
Au·tumn moon·light -          # 4 syllables
a worm digs si·lent·ly        # 6
in·to the chest·nut.          # 5
```

---

## My other katas

If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-)

Source: codewars | Difficulty: EASY

Starter code: def is_haiku(text):
	

Solutions:
import re
PATTERN = re.compile('[aeyuio]+[^aeyuio ]*((?=e\\b)e)?', flags=re.I)

def is_haiku(text):
	return [5, 7, 5] == [check(s) for s in text.split('\n')]

def check(s):
	return sum((1 for _ in PATTERN.finditer(s)))


import re

def is_haiku(text):

	def count_syllables(line):
		return len(re.findall('[aeiouy]{2,}|[aiouy]|e\\B|\\b[^\\Waeiouy]*e\\b', line, re.I))
	return tuple(map(count_syllables, text.splitlines())) == (5, 7, 5)


import re

def is_haiku(text):

	def parse_line(line):
		word_pattern = '[^\\W\\d_]+'
		return re.findall(word_pattern, line)

	def count_syllables(word):
		vowel_pattern = '[aeiouy]+'
		vowels = re.findall(vowel_pattern, word, re.I)
		ends_in_e = lambda seq: seq[-1] == 'e'
		if vowels and ends_in_e(vowels) and ends_in_e(word):
			vowels.pop()
		return max(len(vowels), 1)
	syllables = [sum(map(count_syllables, parse_line(line))) for line in text.splitlines()]
	return syllables == [5, 7, 5]


def is_haiku(text):
	import string
	vow = 'aeiouy'

	def syl_in_word(word):
		if word is '':
			return 0
		syls = sum([1 for (ind, l) in enumerate(word[:-1]) if l in vow and word[ind + 1] not in vow])
		if word[-1] in vow:
			if word[-1] != 'e' or (len(word) > 1 and word[-2] in vow) or syls == 0:
				syls += 1
		return syls
	strings = text.split('\n')
	syls = []
	for s in strings:
		s = ''.join([c for c in s.lower() if c not in string.punctuation])
		syls.append(sum([syl_in_word(word) for word in s.split(' ')]))
	return syls == [5, 7, 5]


def is_haiku(s, v='aeiouy'):
	C = []
	for x in [a.strip('.;:!?,').split() for a in s.lower().split('\n')]:
		t = ''
		for y in x:
			if y.endswith('e') and any((c in y[:-1] for c in v)):
				y = y[:-1]
			for c in y:
				t += c if c in v else ' ' if t and t[-1] != ' ' else ''
			t += ' '
		C += [len(t.split())]
	return C == [5, 7, 5]


def is_haiku(text):
	temp = text.replace('.', '').replace(',', '').replace('-', '').replace('?', '').replace('!', '').replace('#', '').replace(';', '').replace('/', '').replace(':', '').replace(')', '').replace('()', '')
	temp = temp.lower()
	temp = temp.split('\n')
	haiku = []
	count = 0
	for i in temp:
		for word in i.split():
			count += syllable(word)
		haiku.append(count)
		count = 0
	if len(haiku) != 3:
		return False
	return True if haiku[0] == 5 and haiku[1] == 7 and (haiku[2] == 5) else False

def syllable(text):
	count = 0
	index = 0
	while index < len(text):
		if text[index] in 'aeiouy':
			if text[index] == 'e' and index == len(text) - 1:
				break
			count += 1
			while index + 1 < len(text):
				if not text[index + 1] in 'aeiouy':
					break
				index += 1
		index += 1
	if count == 0:
		count = 1
	return count


import re, string

def is_haiku(text):
	text = text.translate(str.maketrans('', '', string.punctuation))
	text = text.lower().splitlines()
	sylRegex = re.compile('[^aeiouy\\s][aeiouy]')
	syl2Regex = re.compile('                 #for edge cases\n    (ia[^lgn])|(riet)|\n    (iu)|([^tn]io[^nr])|(ii)|\n    ([aeiouym]bl$)|(aeiou){3}|(^mc)|(ism$)|\n    (([^aeiouy])\\1l$)|([^l]lien)|\n    (^coa[dglx].)|([^gq]ua[^auieol])|(dnt$)', re.VERBOSE)
	endsERegex = re.compile('[^aeiouy][aeiouy][aeiou]*[^e\\s]+e(?:\\s|$)')
	endsE2Regex = re.compile('^\\b[ea]\\w{1,2}e(?:\\s|$)')
	beginVRegex = re.compile('\\b[aeiouy]')
	exceptions_add = re.compile('(triangle)')
	exceptions_minus = re.compile('(obvious)')
	count = []
	for i in range(len(text)):
		syl = len(sylRegex.findall(text[i])) + len(syl2Regex.findall(text[i]))
		endsE_set1 = set(endsERegex.findall(text[i]))
		endsE_set2 = set(endsE2Regex.findall(text[i]))
		endsE = len(endsE_set1.union(endsE_set2))
		count.append(syl - endsE + len(beginVRegex.findall(text[i])) + len(exceptions_add.findall(text[i])) - len(exceptions_minus.findall(text[i])))
		print(text[i])
		print(sylRegex.findall(text[i]))
		print(syl2Regex.findall(text[i]))
		print(endsERegex.findall(text[i]))
		print(endsERegex.findall(text[i]))
		print(beginVRegex.findall(text[i]))
		print(count)
	return count == [5, 7, 5]


def is_haiku(text):
	is_haiku = True
	vowel_list = ['a', 'e', 'i', 'o', 'u', 'y']
	haiku = text.splitlines()
	if len(haiku) != 3:
		return False
	for line in range(0, 3):
		syllable = 0
		haiku[line] = haiku[line].split(' ')
		for word in haiku[line]:
			current_syllable = 0
			silent_e = False
			word = word.lower()
			word = ''.join(filter(str.isalnum, word))
			if len(word) == 1 and word in vowel_list:
				current_syllable += 1
			elif len(word) >= 2:
				if word[0] in vowel_list:
					current_syllable += 1
					silent_e = True
				for position in range(1, len(word)):
					if word[position] in vowel_list and word[position - 1] not in vowel_list:
						current_syllable += 1
						silent_e = True
				if current_syllable != 1 and silent_e == True and (word[-1] == 'e') and (word[-2] not in vowel_list):
					current_syllable -= 1
			syllable += current_syllable
		if line == 0 or line == 2:
			if syllable != 5:
				is_haiku = False
		elif line == 1:
			if syllable != 7:
				is_haiku = False
		if is_haiku == False:
			return is_haiku
	return is_haiku


def is_haiku(text):
	syllables_per_line = []
	lines = text.splitlines()
	for i in range(len(lines)):
		line = lines[i].split(' ')
		syllables = 0
		for word in line:
			syllables += count_syllables(word)
		syllables_per_line.append(syllables)
	if syllables_per_line == [5, 7, 5]:
		return True
	else:
		return False

def count_syllables(word):
	syllables_in_word = 0
	vowels = 'aeiouy'
	word = ''.join(filter(str.isalnum, word))
	word = word.lower()
	if len(word) > 0:
		if word[0] in vowels:
			syllables_in_word = 1
		if len(word) > 1:
			i = 0
			while i < len(word) - 1:
				if (word[i] not in vowels) & (word[i + 1] in vowels):
					syllables_in_word += 1
					i += 1
				i += 1
			if (syllables_in_word > 1) & word.endswith('e') & (word[len(word) - 2] not in vowels):
				syllables_in_word -= 1
	return syllables_in_word