Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [string[]]$wordList = @(
- 'spade',
- 'curve',
- 'axiomatic',
- 'intelligent',
- 'skin',
- 'verdant',
- 'acrid',
- 'legs',
- 'moaning',
- 'error',
- 'low',
- 'object'
- )
- Function Get-Seed()
- {
- Process
- {
- $rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
- [byte[]]$rBytes = New-Object byte[] 4
- $rng.GetBytes($rBytes)
- [System.BitConverter]::ToUInt32($rBytes, 0)
- }
- End
- {
- $rng.Dispose()
- }
- }
- Function Randomize-Word([string]$word)
- {
- $entries = @{}
- [char[]]$chars = $word.ToCharArray()
- foreach ($c in $chars)
- {
- $seed = [long]::MinValue
- while (-not $entries.ContainsKey($seed))
- {
- $seed = Get-Seed
- $entries.Add($seed, $c)
- }
- }
- [char[]]$sorted = $entries.GetEnumerator() | Sort Key | Select -ExpandProperty Value
- $sorted -join ''
- }
- [string[]]$ScrambledWords = foreach ($w in $wordList)
- {
- Randomize-Word -word $w
- }
- $ScrambledWords -join ', '
- $CorrectWords = $null
- #Main foreach scrambled word
- foreach ($Scramble in $ScrambledWords) {
- #Grab the length of the scrambled word
- $PossibleWords = $wordlist | Where-Object { $_.Length -eq $Scramble.Length }
- #foreach to compare possible words with the current scrambled word
- foreach ($Word in $PossibleWords) {
- #turn both strings to arrays and compare them for only matches
- $Compare = Compare-Object -ReferenceObject $Word.ToCharArray() -DifferenceObject $Scramble.ToCharArray() -IncludeEqual -ExcludeDifferent
- #Grab only words that have the same amount of matched letters as the scrambled word
- if($Compare.Length -eq $Scramble.Length) {
- $CorrectWords += "$word, "
- }
- }
- }
- Write-host $CorrectWords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement