Created
January 24, 2018 18:18
-
-
Save kevsersrca/60ab2b449729e74171ba0c92b49e5a61 to your computer and use it in GitHub Desktop.
palindrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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