Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $CorrectWords = $null
  2.  
  3. #import dictionary
  4. $wordlist = Get-Content C:\temp\wordlist.txt
  5.  
  6. #import scrambled word list
  7. $ScrambledWords = Get-Content C:\temp\scrambled.txt
  8.  
  9. #Main foreach scrambled word
  10. foreach ($Scramble in $ScrambledWords) {
  11.     #Grab the length of the scrambled word
  12.     $PossibleWords = $wordlist | Where-Object { $_.Length -eq $Scramble.Length }
  13.         #foreach to compare possible words with the current scrambled word
  14.         foreach ($Word in $PossibleWords) {  
  15.           #turn both strings to arrays and compare them for only matches  
  16.           $Compare = Compare-Object -ReferenceObject $Word.ToCharArray() -DifferenceObject $Scramble.ToCharArray() -IncludeEqual -ExcludeDifferent
  17.             #Grab only words that have the same amount of matched letters as the scrambled word
  18.             if($Compare.Length -eq $Scramble.Length) {
  19.                 $CorrectWords += "$word, "
  20.                 }
  21.  
  22.         }
  23. }
  24.  
  25. Write-host $CorrectWords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement