Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created August 19, 2015 13:28
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/e52bf82f016bc2055710 to your computer and use it in GitHub Desktop.
Save JFFail/e52bf82f016bc2055710 to your computer and use it in GitHub Desktop.
Solution To Reddit Daily Programmer #228
#https://www.reddit.com/r/dailyprogrammer/comments/3h9pde/20150817_challenge_228_easy_letters_in/
function CheckOrder {
param($Word)
#Place the word into an array.
$charArray = $Word.ToCharArray()
$sortedArray = $charArray | Sort-Object
#See if they match.
$match = $true
$reverseMatch = $false
for($i = 0; $i -lt $charArray.Count; $i++) {
if($charArray[$i] -ne $sortedArray[$i])
{
$match = $false
}
}
#Check for reverse order if they don't match.
if(-not $match) {
$reverseArray = $charArray | Sort-Object -Descending
$reverseMatch = $true
for($i = 0; $i -lt $charArray.Count; $i++) {
if($charArray[$i] -ne $reverseArray[$i]) {
$reverseMatch = $false
}
}
}
#Print result.
if($match) {
Write-Host "$Word IN ORDER"
} elseif($reverseMatch) {
Write-Host "$WORD REVERSE ORDER"
} else {
Write-Host "$Word NOT IN ORDER"
}
}
CheckOrder -Word "billowy"
CheckOrder -Word "biopsy"
CheckOrder -Word "chinos"
CheckOrder -Word "defaced"
CheckOrder -Word "chintz"
CheckOrder -Word "sponged"
CheckOrder -Word "bijoux"
CheckOrder -Word "abhors"
CheckOrder -Word "fiddle"
CheckOrder -Word "begins"
CheckOrder -Word "chimps"
CheckOrder -Word "wronged"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment