Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created September 15, 2015 20:44
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/ccb8b6b7dc40a31964cd to your computer and use it in GitHub Desktop.
Save JFFail/ccb8b6b7dc40a31964cd to your computer and use it in GitHub Desktop.
Reddit Daily Programmer #232
#https://www.reddit.com/r/dailyprogrammer/comments/3kx6oh/20150914_challenge_232_easy_palindromes/
$lines = 2
$counter = 0
$text = ""
while($counter -lt $lines) {
$temp = Read-Host "Enter text"
$temp = $temp.ToCharArray()
foreach($letter in $temp) {
$letter = [string]$letter
if($letter -match "\w") {
$text += $letter
}
}
$counter++
}
$text = $text.toCharArray()
$isPalindrome = $true
for($i = 0; $i -lt $text.Count; $i++) {
if([string]$text[$i] -ne [string]$text[-1 - $i]) {
$isPalindrome = $false
break
}
}
if($isPalindrome) {
Write-Host "Palindrome"
} else {
Write-Host "Not a palindrome"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment