Games: Advanced 3
This one involves reading a text file, finding all the words that use a single vowel (may have multiple instances of that vowel e.g. look) and write them out to a text file.
| 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015
| ## find the univowel words ## - 1 or more instances of the same vowel ## - all vowels the same if (Test-Path univowel.txt){Remove-Item univowel.txt} Get-Content Wordlist_ADV3.txt | foreach { $y = 0 $z = $_.ToCharArray() if ($z -contains "a") {$y++} if ($z -contains "e") {$y++} if ($z -contains "i") {$y++} if ($z -contains "o") {$y++} if ($z -contains "u") {$y++} if ($_ -eq "look"){"$_ $y"} if ($y -eq 1){Add-Content -Path univowel.txt -Value $($_)} } |
Delete the answer file if it exists. Read the file & loop through the contents. Quick & dirty brute force approach for this one. Convert the work to a character array and use contains to check for vowel membership – only 5 vowels so 5 if statements. Tried a switch but it counts each each instance so wrecks the result ie didn’t accept “look”. For each hit increment the counter ($y).
At the end if $y = 1 it means we have only one vowel in the word so write it to the text file.
Not a task I need to do very often but it works.