File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
arrays-strings/palindrome Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments