Skip to content

Instantly share code, notes, and snippets.

@kevsersrca
Created January 24, 2018 18:18
Show Gist options
  • Save kevsersrca/60ab2b449729e74171ba0c92b49e5a61 to your computer and use it in GitHub Desktop.
Save kevsersrca/60ab2b449729e74171ba0c92b49e5a61 to your computer and use it in GitHub Desktop.
palindrome
package main
import (
"fmt"
"regexp"
"strings"
)
func Reverse(s string) string {
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
func main() {
k := strings.ToLower("Eva, can I see bees in a cave?")
reg, _ := regexp.Compile("[^a-zA-Z0-9]+")
processedString := reg.ReplaceAllString(k, "")
if processedString == Reverse(processedString) {
fmt.Println("palindrome")
} else {
fmt.Println("değil")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment