Last active
March 18, 2023 05:08
-
-
Save Mike-Crowley/09a03b770ab94af01147d4c7f9a10460 to your computer and use it in GitHub Desktop.
Get-WordscapesResults
This file contains 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
<# Wordscapes solver | |
14Jul2021 | |
https://apps.apple.com/us/app/wordscapes/id1207472156 | |
https://play.google.com/store/apps/details?id=com.peoplefun.wordcross&hl=en_US&gl=US | |
#> | |
#import Get-StringPermutation from https://learn-powershell.net/2013/02/21/fun-with-powershell-and-permutations/ | |
$wordArray = Get-Content C:\tmp\words.txt | |
$wordHash = @{} | |
foreach ($word in $wordArray) { | |
$wordHash.Add($word.ToLower(), $word.ToLower()) | |
} | |
Function Get-WordscapesResults { | |
[cmdletbinding()] | |
Param( | |
[parameter(ValueFromPipeline = $true)] [string] $Letters = "crowley", | |
[parameter(ValueFromPipeline = $false)] [int32] $MaxLetters = $Letters.Length, | |
[parameter(ValueFromPipeline = $false)] [int32] $MinLetters = 3 | |
) | |
Begin{ | |
If ($MaxLetters -gt $Letters.Length) { | |
Write-Warning ("MaxLetters greater than input letters not used in this game. Setting MaxLetters to " + $Letters.Length) | |
$MaxLetters = $Letters.Length | |
} | |
If ($MinLetters -lt 2) { | |
Write-Warning "MinLetters must be greater than 1. Setting MinLetters to 2" | |
$MinLetters = 2 | |
} | |
If ($MinLetters -ge $MaxLetters) { | |
Write-Warning ("MinLetters must be less than MaxLetters. Setting MinLetters to 2 and MaxLetters to " + $Letters.Length) | |
$MinLetters = 2 | |
$MaxLetters = $Letters.Length | |
} | |
} | |
Process { | |
$permutations = Get-StringPermutation $Letters | |
$rangedPermutations = $MinLetters..$MaxLetters | ForEach-Object { | |
$upperindex = $_ | |
$permutations | select @{n="Permutation"; e={($_.Permutation.substring(0,$upperindex))}} | select Permutation -Unique | |
} # -Parallel | |
$results = $rangedPermutations | ForEach-Object { | |
$wordHash.get_item($_.permutation) | |
} # -Parallel | |
} | |
End { | |
$results | select @{n="results";e={$_}} | sort results | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment