Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created October 22, 2015 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JFFail/b4fb8b062ac4393e2e8c to your computer and use it in GitHub Desktop.
Save JFFail/b4fb8b062ac4393e2e8c to your computer and use it in GitHub Desktop.
Reddit Daily Programmer #237 - Broken Keyboard
#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