Find words with alternating vowels and consonants: Difference between revisions
Content deleted Content added
Realize in F# |
Swift - simplified code |
||
Line 2,002: | Line 2,002: | ||
return false |
return false |
||
} |
} |
||
} |
|||
func alternatingVowelsAndConsonants(word: String) -> Bool { |
|||
return zip(word, word.dropFirst()).allSatisfy{isVowel($0.0) != isVowel($0.1)} |
|||
} |
} |
||
do { |
do { |
||
let words = try String(contentsOfFile: "unixdict.txt", encoding: String.Encoding.ascii) |
let words = try String(contentsOfFile: "unixdict.txt", encoding: String.Encoding.ascii) |
||
let lines = words.components(separatedBy: "\n") |
|||
var n = 1 |
|||
for word in |
for (n, word) in lines.filter( |
||
{$0.count > 9 && alternatingVowelsAndConsonants(word: $0)}).enumerated() { |
|||
print("\(String(format: "%2d", n + 1)): \(word)") |
|||
} |
|||
var isOddEvenWord = true |
|||
var prev: Character = "\n" |
|||
for ch in word { |
|||
if prev != "\n" && isVowel(ch) == isVowel(prev) { |
|||
isOddEvenWord = false |
|||
break |
|||
} |
|||
prev = ch |
|||
} |
|||
if isOddEvenWord { |
|||
print("\(String(format: "%2d", n)): \(word)") |
|||
n += 1 |
|||
} |
|||
} |
} |
||
} catch { |
} catch { |