Skip to content

Commit 17f39fc

Browse files
Palindrome #1
1 parent bcc1bf3 commit 17f39fc

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"regexp"
6+
"strings"
7+
)
8+
9+
func clean(word string) string {
10+
regex := regexp.MustCompile(`[^a-zA-Z]`)
11+
return regex.ReplaceAllString(word, "")
12+
}
13+
14+
func reverse(word *string) string {
15+
splitWord := strings.Split(*word , "")
16+
temp := []string{}
17+
18+
for i := len(splitWord)-1; i >= 0; i-- {
19+
temp = append(temp, splitWord[i])
20+
}
21+
22+
reversedWord := strings.Join(temp, "")
23+
return reversedWord
24+
}
25+
26+
func main() {
27+
input := []string{
28+
"Yo de todo te doy.",
29+
"A ti no bonita",
30+
"Esto no es un palindromo",
31+
"",
32+
"******* :::::",
33+
}
34+
35+
for i, _ := range input{
36+
wordClened := clean(input[i])
37+
if len(wordClened) > 0{
38+
lowerString := strings.ToLower(wordClened)
39+
reversedWord:= reverse(&lowerString)
40+
result := reversedWord == lowerString
41+
42+
if result {
43+
fmt.Printf("%t\t-> '%s' is a palindorme. \n", result, input[i])
44+
}else{
45+
fmt.Printf("%t\t-> '%s' is not a palindorme.\n", result, input[i])
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)