Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nicestring
- fun String.isNice(): Boolean {
- // It doesn't contain substrings bu, ba or be;
- /*fun String.condition1(): Boolean = !(contains("bu") || contains("ba") || contains("be"))*/
- val doesNotContain = setOf("bu", "ba", "be").none { this.contains(it) }
- // It contains at least three vowels (vowels are a, e, i, o and u);
- /*fun String.condition2():Boolean = filter { it in "aeiou" }.count() >= 3*/
- val hasThreeVowels = count { it in "aeiou" } >= 3
- /*It contains a double letter (at least two similar letters following
- one another), like b in "abba"*/
- /*fun String.condition3():Boolean = zipWithNext() { a, b -> a == b }.filter { it }.count() >= 1*/
- val hasDouble = zipWithNext().any { it.first == it.second }
- /*return ((condition1() && condition2()) || (condition1() && condition3()) || (condition2() && condition3())) }*/
- return listOf(doesNotContain, hasThreeVowels, hasDouble).count { it } >= 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement