Created
October 22, 2015 12:57
-
-
Save JFFail/b4fb8b062ac4393e2e8c to your computer and use it in GitHub Desktop.
Reddit Daily Programmer #237 - Broken Keyboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://www.reddit.com/r/dailyprogrammer/comments/3pcb3i/20151019_challenge_237_easy_broken_keyboard/ | |
#Import the list of words. | |
$wordList = Get-Content -Path .\word.txt #http://norvig.com/ngrams/enable1.txt | |
#Get the first part of input, which is an integer. | |
$numbers = Read-Host "Enter the number of combinations to check" | |
$counter = 0 | |
$checkArray = @() | |
#Loop through them to get all of the input. | |
while($counter -lt $numbers) { | |
$checkArray += Read-Host "Enter a string of characters" | |
$counter++ | |
} | |
#Perform each check. | |
foreach($item in $checkArray) { | |
$winningWord = "" | |
foreach($word in $wordList) { | |
$goodWord = $true | |
#Split each word into an array of characters. | |
$letterArray = $word.ToCharArray() | |
#Now check each character. | |
foreach($letter in $letterArray) { | |
if(-not($item.Contains($letter))) { | |
$goodWord = $false | |
break | |
} | |
} | |
#If the word is valid, figure out the length. | |
if($goodWord) { | |
if($word.Length -gt $winningWord.Length) { | |
$winningWord = $word | |
} | |
} | |
} | |
#At the end, write everything back out. | |
Write-Host "$item = $winningWord" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment