Skip to content

Instantly share code, notes, and snippets.

@Cirzen
Created August 11, 2015 08:36
Show Gist options
  • Save Cirzen/bbb9e442ece38dc67e1c to your computer and use it in GitHub Desktop.
Save Cirzen/bbb9e442ece38dc67e1c to your computer and use it in GitHub Desktop.
Wordinian word search.
#Find Wordinian words. See www.wordinian.com
#E.g. Stage: Stag, age, ta, a
$wordlist = Get-Content C:\Users\DJ\Downloads\TWL06.txt #Downloaded scrabble dictionary
$Searchwordlength = 12
Function Test-Word ($word, $wordlist) {
Return $wordlist -match $word -as [bool]
}
Function Get-Subwords ($word, $length) {
ForEach ($i in 0..(($word.Length - $length)))
{
$word.Substring($i,$length)
}
}
$ctr = 0
$wordlistCount = $wordlist.Count
ForEach ($word in $wordlist)
{
Write-Progress -Activity "Testing Words" -Status $word -PercentComplete ($ctr++ / $wordlistCount * 100)
If ($word -match "a" -OR $word -match "i" -AND $word.Length -eq $Searchwordlength)
{
# Word contains valid single letter
$TestWords = New-Object Hashtable
$ValidWords = New-Object Hashtable
ForEach ($i in ($word.Length -1)..2)
{
#Write-Verbose "Testing length $i" -verbose
$TestWords.Add($i,( Get-Subwords -word $word -length $i))
ForEach ($Subword in $TestWords[$i])
{
If ($Wordlist -contains $Subword)
{$ValidWords[$i] = $Subword}
}
If (!$ValidWords[$i]) {Write-Verbose "$word - Nothing found at length $i" -verbose;Break}
}
If ($Word.Length -eq $ValidWords.Count + 2)
{
Write-Verbose $word -verbose
New-Object pscustomobject -Property @{Length=$Word.Length;Word=$word;Subwords=$ValidWords.Values -join ';'}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment