Solución al reto:
Hola mundo en Go
Introducción al Curso de Golang
¿Qué es, por qué y quienes utilizan Go?
Instalar Go en Linux
Instalar Go en Mac
Instalar Go en Windows
Nuestras primeras líneas de código con Go
Variables, funciones y documentación
Variables, constantes y zero values
Operadores aritméticos
Tipos de datos primitivos
Paquete fmt: algo más que imprimir en consola
Uso de funciones
Go doc: La forma de ver documentación
Estructuras de control de flujo y condicionales
El poder de los ciclos en Golang: for, for while y for forever
Operadores lógicos y de comparación
El condicional if
Múltiple condiciones anidadas con Switch
El uso de los keywords defer, break y continue
Estructuras de datos básicas
Arrays y Slices
Recorrido de Slices con Range
Llave valor con Maps
Structs: La forma de hacer clases en Go
Modificadores de acceso en funciones y Structs
Métodos e interfaces
Structs y Punteros
Stringers: personalizar el output de Structs
Interfaces y listas de interfaces
Concurrencia y Channels
¿Qué es la concurrencia?
Primer contacto con las Goroutines
Channels: La forma de organizar las goroutines
Range, Close y Select en channels
Manejo de paquetes y Go Modules
Go get: El manejador de paquetes
Go modules: Ir más allá del GoPath con Echo
Modificando módulos con Go
Despedida del curso
Despedida
Bonus
Cheat Sheet Go
Librerías para desarrollo web con Go
Data Science con Go
No tienes acceso a esta clase
¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera
Aportes 120
Preguntas 1
Solución al reto:
Lo pense un poco diferente 🐹
Solución al reto:
func isPalindrome(text string) {
var textReverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
Comparto la solución redactada en The Go Playground:
package main
import "fmt"
func isPalindrome(input string) bool {
for i := 0; i < len(input)/2; i++ {
if input[i] != input[len(input)-i-1] {
return false
}
}
return true
}
func main() {
fmt.Println(isPalindrome("anna"))
}
// Output: True
Consulte más información aquí
Comparto mi solución además realice otra lógica con recursividad para reconocer si es palindromo.
package main
import (
"fmt"
"strings"
"reflect"
)
func reverseString(input []string) []string {
if len(input) == 0 {
return input
}
return append(reverseString(input[1:]), input[0])
}
func isPalindromo(word string) bool{
splitWord := strings.Split(strings.ToUpper(word), "")
return reflect.DeepEqual(splitWord, reverseString(splitWord))
}
func main() {
word :="Ama"
if(isPalindromo(word)){
fmt.Println("Es palindromo")
}else{
fmt.Println("No es palindromo")
}
}
Mi solución del reto
package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) bool {
var textReverse string
/* Reto: validar que si el texto contiene
mayúsculas igual siga validando el palíndromo. */
text = strings.ToLower(text) // Pasamos el texto a minúsculas
text = strings.ReplaceAll(" ", text, text) // Eliminamos los espacios
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
return true
} else {
return false
}
}
func main() {
/* Recorrer slices */
/* slice := []string{"hola", "golang"}
for _, v := range slice {
fmt.Println(v)
} */
fmt.Println(isPalindrome("Anita lava la tina"))
}
package main
import (
"fmt"
"strings"
)
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es un palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
func main() {
isPalindromo(strings.ToLower("Ama"))
}
package main
import (
"fmt"
"strings"
)
func main() {
//Slices con Range
slice := []string{"hola", "que", "hace"}
for _, valor := range slice {
fmt.Println(valor)
}
//Palindromos
isPalindromo(strings.ToLower("amor a romA"))
isPalindrome("amor a roma")
var palabra string
fmt.Scan(&palabra)
minus := strings.ToLower(palabra)
isPalindromo(minus)
}
//funcion Detectar si una palabra es palindromo
func isPalindromo(text string) {
var testReverse string
for i := len(text) - 1; i >= 0; i-- {
testReverse += string(text[i])
}
if text == testReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
func isPalindrome(text string) {
var textReverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("is palindrome")
} else {
fmt.Println("Not is palindrome")
}
}
Mis soluciones xd
package main
import (
“fmt”
“strings”
)
func isPalindrome(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
//fmt.Println(textReverse)
if text == textReverse {
fmt.Println("El valor", text, " ES PALINDROMO")
//return "ES PALINDROMO"
} else {
fmt.Println("El valor", text, "NO ES PALINDROMO")
}
}
func main() {
fmt.Println(“Hello World”)
valores := []string{“aMa”, “hola”, “arePera”, “limon”}
for _, valor := range valores {
v := strings.ToUpper(valor)
isPalindrome(v)
}
}
package main
import (
"fmt"
"strings"
)
//reto
func isPalindromo(palabra string) string {
var reversePalabra string
palabra = strings.ToUpper(palabra)
for i := len(palabra) - 1; i >= 0; i-- {
reversePalabra += string(palabra[i])
}
if palabra == reversePalabra {
return "palindromo"
} else {
return "no es un palindromo"
}
}
func main() {
fmt.Println(isPalindromo("amor a roma"))
}
func main() {
text := “Ama"
if isPalindrome(text) {
fmt.Printf(”%v it’s a palindrome word/phrase", text)
} else {
fmt.Printf("%v it’s not a palindrome word/phrase", text)
}
}
func isPalindrome(text string) bool {
text = strings.ToLower(text)
var textReverse string
for j := len(text) - 1; j >= 0; j-- {
textReverse += string(text[j])
}
if text == textReverse {
return true
}
return false
}
Solución al reto:
Aqui mi solución ❤️
func isPalindromo(str string) bool {
byte_str := []rune(str)
for i, j := 0, len(byte_str)-1; i < j; i, j = i+1, j-1 {
byte_str[i], byte_str[j] = byte_str[j], byte_str[i]
}
if strings.ToLower(string(byte_str)) == strings.ToLower(str) {
return true
}
return false
}
func main() {
fmt.Println(isPalindromo("Amor a roma"))
fmt.Println(isPalindromo("casas"))
}
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += strings.ToLower(string(text[i]))
}
fmt.Println(textReverse)
if strings.ToLower(text) == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
func isPalindrome(word string) bool {
word = strings.ToLower(word) //Normalizar la información
var newWord string
for i := len(word) - 1; i >= 0; i-- {
newWord += string(word[i])
}
return word == newWord
}
<package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) bool {
var text_reverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
text_reverse += string(text[i])
}
if text_reverse == text {
return true
} else {
return false
}
}
func main() {
slice := []string{"hi", "what", "are", "you", "doing", "?"}
for i := range slice {
fmt.Printf("\ni=%d\n", i)
fmt.Println(slice[i])
}
var text string = "AvA"
// This print a ASCII code, not a letter; for this we need convert it with string(arg)
fmt.Println(text[0])
// Convert to string
fmt.Println(string(text[0]))
// This will return a bool if the text is a palindrome
// true = is a palindrome
// false = is not a palindrome
fmt.Printf("The text is a palindrome = %v", isPalindrome(text))
}>
Mi solucion al reto
package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) {
var textReverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
textReverse += strings.ToLower(string(text[i]))
}
if text == textReverse {
fmt.Println("Is palindrome")
} else {
fmt.Println("Is not a palindrome")
}
}
func main() {
isPalindrome("Amar")
}
strings.ToLower() -> convertira nuestra cadena de caracteres a minusculas todas las palabras.
package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) {
text = strings.ToLower(text)
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es un palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
func main() {
slice := []string{"hola", "que", "hace"}
for _, valor := range slice {
fmt.Println(valor)
}
// Palindromo
isPalindrome("Amor A Roma")
}
Solucion al problema
<func isPalindromo(text string) {
textLowerCase := strings.ToLower(text) //Toda palabra entrantea la funcion , con esta linia la transforma a minuscula
var textReverse string
for i := len(textLowerCase) - 1; i >= 0; i-- {
textReverse += string(textLowerCase[i])
}
if textLowerCase == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es un palindromo")
}
}>
package main
import (
“fmt”
“strings”
)
func esPalindromo(text string) {
var textReverse string
var textMin string = strings.ToLower(text)
for i := len(textMin) - 1; i >= 0; i-- {
textReverse += string(textMin[i])
}
if textMin == textReverse {
fmt.Println(text, ": es palindromo")
} else {
fmt.Println(text, ": no es palindromo")
}
}
func main() {
slice := []string{“hola”, “que”, “hace”}
for i, valor := range slice {
fmt.Println(i, valor)
}
// Palíndromos : ama, amor a roma
esPalindromo("amA")
esPalindromo("Asa")
esPalindromo("casa")
esPalindromo("arma")
}
func DetectPalindrome(someText string) {
var textReverse string
somoText = strings.ToLower(someText)
for i := len(someText) - 1; i >= 0; i-- {
textReverse += string(someText[i])
}
if someText == textReverse {
fmt.Println("Éxito es un palindromo")
} else {
fmt.Println("Ouch no es palindromo")
}
}
Listo! 😄
package main
import (
"fmt"
"strings"
)
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if strings.ToLower(text) == strings.ToLower(textReverse) {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
func main() {
isPalindromo("anitalavalatina")
}
Solución sencilla y eficiente para el reto:
// Hay que importar "strings" para usar ToLower
func isPalindrome(word string) bool {
word = strings.ToLower(word)
for i := 0; i < len(word)/2; i++ {
if word[i] != word[len(word)-(i+1)] {
return false
}
}
return true
}
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if strings.ToLower(text) == strings.ToLower(textReverse) {
fmt.Println("La palabra ", strings.ToLower(text), " si es un palindromo ", strings.ToLower(textReverse))
} else {
fmt.Println("La palabra ", strings.ToLower(text), " no es un palindromo ", strings.ToLower(textReverse))
}
}
Solución al reto:
Mi solución:
func isPalindrome(text string) {
text = strings.ToLower(text)
text = strings.ReplaceAll(text, " ", "")
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Is palindrome")
} else {
fmt.Println("Is not palindrome")
}
}
Solución del reto
package main
import (
"fmt"
"strings"
)
func main() {
isPalindrome("amor a Roma")
}
func isPalindrome(text string) {
text = strings.ToLower(text)
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
strings.ToLower(text)
convertir todo a minusculas antes de la operacion
Otra manera es comparar el primero con el último, el segundo con el penúltimo, etc… Si es impar ignoramos el caracter del medio, esto lo consigue la división entera por nosotros.
func palindromo(text string) bool {
var max = len(text) - 1
for i := 0; i < max/2; i++ {
if text[i] != text[max-i] {
return false
}
}
return true
}
package main
import (
"fmt"
"reflect"
"strings"
)
type Runes []rune
func (str Runes) ReverseString() (rev_str Runes) {
l := len(str)
rev_str = make(Runes, l)
for i := 0; i <= l/2; i++ {
rev_str[i], rev_str[l-1-i] = str[l-1-i], str[i]
}
return rev_str
}
func (str Runes) String() string {
return string(str)
}
func main() {
input_str := "AMor a RoMa"
str_rune := Runes(input_str)
rev_str := str_rune.ReverseString()
if strings.ToLower(input_str) == strings.ToLower(rev_str.String()) {
fmt.Println("Is palindrome")
} else {
fmt.Println("Is NOT palindrome")
}
fmt.Println(input_str, reflect.TypeOf(input_str))
fmt.Println(rev_str, reflect.TypeOf(rev_str))
}
package main
import (
"fmt"
"strings"
)
func palindromo ( palabra string ) bool {
var palabraReversada string
palabra = strings.ToLower(palabra)
for i := len(palabra) - 1; i >= 0; i-- {
palabraReversada += string(palabra[i])
}
if palabraReversada == palabra {
return true
}else{
return false
}
}
func main() {
var palabra string = "Amor A ROma"
esUnPalindromo := palindromo(palabra)
if esUnPalindromo {
fmt.Printf("La palabra << %s >> es un palíndromo\n", palabra)
}else{
fmt.Printf("La palabra << %s >> NO es un palíndromo\n", palabra)
}
}
En este caso solo envié a la función que hizo el instructor una variable convertida a minúsculas con strings.ToLower(text)
package main
import (
"fmt"
"strings"
)
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
func main() {
// Reto de palindromos con mayúsculas
text := "Amor A ROma"
isPalindromo(strings.ToLower(text))
}
Este es mi aporte creo que es super sencillo:
func IsPalindrome(s string) bool {
var result string
sL := strings.ToLower(s)
for _, letter := range sL {
result = string(letter) + result
}
fmt.Println(s, result)
return sL == result
}
Funcion booleana
func isPalindrome(text string) bool {
var textReverse string
for i:= len(text) - 1; i>=0; i-- {
textReverse += string(text[i])
}
return strings.ToLower(textReverse) == strings.ToLower(text)
}
Mi solución al reto:
func isPalindrome(text string) string {
text = strings.ToLower(text)
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
return "Es palindromo"
} else {
return "No es palindromo"
}
}
usando el paquete strings
func isPalindromo(texto string) {
var textReverse string
for i := len(texto) - 1; i >= 0; i-- {
textReverse += string(texto[i])
}
if strings.ToLower(texto) == strings.ToLower(textReverse) {
fmt.Println("SI es Palindromo")
} else {
fmt.Println("NO es Palindromo")
}
}
Mi solución :
func isPalindromo(text string) {
var reverseText string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
reverseText += string(text[i])
}
if text == reverseText {
fmt.Println("Es Palindromo")
} else {
fmt.Println("No es Palindromo")
}
}
func main() {
isPalindromo("Amor a Roma")
}
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if strings.EqualFold(text, textReverse) {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
Codigo escrito en la clase.
package main
import "fmt"
func main() {
slice := []string{"Hola", "Como", "Estas"}
//Imprimir el indice y el valor del string
for i, valor := range slice {
fmt.Println(i, valor)
}
///imprimir unicamente el valor dentro del indice
for _, valor := range slice {
fmt.Println(valor)
}
///imprimir el indice
for i := range slice {
fmt.Println(i)
}
}
Reto con palindromos
package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) bool {
var textReverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
return textReverse == text
}
func main() {
if isPalindrome("Ama") {
fmt.Println("is palindrome")
} else {
fmt.Println("is not a palindrome")
}
}
Solucion al reto
package main
import (
"fmt"
"strings"
)
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if strings.EqualFold(textReverse, text) {
fmt.Printf("%s es palindromo\n", text)
} else {
fmt.Printf("%s no es palindromo\n", text)
}
}
func main() {
slice := []string{"hola", "como", "estas"}
for i, valor := range slice {
fmt.Printf("%d - %s\n", i, valor)
}
isPalindromo("Ana")
isPalindromo("Casas")
}
Dejo mi solución:
import (
"fmt"
"strings"
)
func isPalindromo( text string) {
var textReverse string
for i:= len(text) -1;i>= 0;i--{
textReverse+= string(text[i])
}
if textReverse == text{
fmt.Println("Es palindromo")
}else{
fmt.Println("No es palindromo")
}
}
func main() {
var palabra string
fmt.Scan(&palabra)
isPalindromo(strings.ToLower(palabra))
}
func esPalindromo(text string) (bool, string) {
var reverse string = ""
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
reverse += string(text[i])
}
return reverse == text, reverse
}```
package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) {
var textReverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Is palindrome")
} else {
fmt.Println("isn't palindrome")
}
}
func main() {
var word string
fmt.Scan(&word)
isPalindrome(word)
}
Mi solucion al reto c:
Reto
func isPalindromo(text string) {
var minusculas string = strings.ToLower(text)
var textReverse string
for i := len(minusculas) - 1; i >= 0; i-- {
textReverse += string(minusculas[i])
}
if minusculas == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindormo")
}
}
Mi propuesta para desarrollar el ejercicio, estableciendo que mayúsculas y minúsculas son equivalentes para el caso.
func esPalindromo(a string) bool {
for i := 0; i <= len(a)/2; i++ {
if a[i] != a[len(a)-(i+1)] && a[i]-32 != a[len(a)-(i+1)] && a[i]+32 != a[len(a)-(i+1)] {
return false
}
}
return true
}
Una manera mas eficiente
package main
import "strings"
func isPalindrom(text string){
length:=len(text)
text=strings.ToLower(text)
for i:=0;i<(length); i++{
if(text[i]!=text[(length-1)-i]){
println("is not palindrom")
return
}
}
println("is palindrom")
}
func main(){
isPalindrom("amor a roma")
}
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
fmt.Println("Enter a word or sentence")
reader := bufio.NewReader(os.Stdin)
inputWord, _ := reader.ReadString('\n')
if inputWord != "" {
result, originalText, reverseText := isPalindromo(inputWord)
if result {
fmt.Printf("Es un palindromo, porque '%s' al reves es '%s'", originalText, reverseText)
} else {
fmt.Printf("No es un palindromo, porque '%s' al reves es '%s'", originalText, reverseText)
}
} else {
fmt.Println("Empty string is not allowed")
}
}
func isPalindromo(text string) (bool, string, string) {
var textReverse string
trimmedText := strings.TrimSpace(text)
for i := len(trimmedText) - 1; i >= 0; i-- {
textReverse += string(trimmedText[i])
}
fmt.Println(textReverse)
fmt.Println(trimmedText, len(text), len(trimmedText))
return (strings.ToLower(textReverse) == strings.ToLower(trimmedText)), strings.ToLower(trimmedText), strings.ToLower(textReverse)
}
La solución se puede dar aplicando la función strings.ToLower() o strings.ToUpper().
My codeeeeeee
func isPalindrome(word string) bool {
word = strings.ReplaceAll(strings.ToLower(word), " ", "")
wordLength := len(word)
var reverse string
for i := 1; i <= wordLength; i++ {
reverse += fmt.Sprintf("%s%s", reverse, string(word[wordLength-i]))
}
return word == reverse
}
Mi solución:
package main
import "fmt"
func abs(a byte) byte {
if a > 0 {
return a
}
return -a
}
func isPalindrome(a string) bool {
ans := true
for i, j := 0, len(a)-1; i < j; i++ {
if abs(a[i]-a[j])%32 != 0 {
ans = false
break
}
j--
}
return ans
}
func main() {
var word string
fmt.Scan(&word)
if !isPalindrome(word) {
fmt.Print("no ")
}
fmt.Println("es palindromo")
}
Sin importar si la palabra tiene alguna mayúscula
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if strings.ToLower(text) == strings.ToLower(textReverse) {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
func main() {
slice := []string{"hola", "que", "hace"}
for _, valor := range slice {
fmt.Println(valor) //
}
// ama
// amor a roma
isPalindromo("Ama")
}
Aquí mi solución
Solucion al Reto
func Reverse(s string) (result string) {
for _, v := range s {
result = string(v) + result
}
return result
}
func isPalindromo(input string) bool {
inpupTolower := strings.ToLower(input)
if inpupTolower == Reverse(inpupTolower) {
return true
}
return false
}
func main() {
entry := "amor a roma"
if isPalindromo(entry) {
fmt.Println(entry, "es palindromo")
} else {
fmt.Println(entry, "no es palindromo")
}
}
Reto:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println("-amor a roma- es palindromo? :", esPalindromo("Amor A roMa"))
}
func esPalindromo(str string) bool {
var text string
for i := len(str) - 1; i >= 0; i-- {
text += string(str[i])
}
fmt.Println(texto)
return strings.EqualFold(str, text)
}
Así quedó mi función:
func isPalindromo(text string) {
text = strings.ToLower(text)
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
func main() {
isPalindromo("Amor a Roma")
}
func isPalindromo(text string) {
text = strings.ToLower(text)
text = strings.ReplaceAll(text, " ", "")
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
Mi version de la función palindrome:
package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) {
var reversedText string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
reversedText += string(text[i])
}
if reversedText == text {
fmt.Println("Text ", text, " is Palindrome")
} else {
fmt.Println(text, "is not palindrome")
}
}
func main() {
slice := []string{"hi", "what", "are", "you", "doing?"}
for i, valor := range slice {
fmt.Println(i, valor)
}
isPalindrome("Anona")
isPalindrome("oso")
isPalindrome("none")
}
salida:
0 hi
1 what
2 are
3 you
4 doing?
Text anona is Palindrome
Text oso is Palindrome
none is not palindrome```
Solución
<
package main
import (
"fmt"
"strings"
"unicode"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func isMn(r rune) bool {
return unicode.Is(unicode.Mn, r) // Mn: nonspacing marks
}
func removeAccents(s string) string {
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
result, _, _ := transform.String(t, s)
return result
}
func isPalindromo(texto string) {
var textReverse string
texto = strings.ReplaceAll(texto, ",", "")
texto = strings.ReplaceAll(texto, " ", "")
texto = strings.ToUpper(texto)
texto = removeAccents(texto)
for i := len(texto) - 1; i >= 0; i-- {
textReverse += string(texto[i])
}
fmt.Println("texto: ", texto)
if texto == textReverse {
fmt.Println("es palindromo")
} else {
fmt.Println("no es palindromo")
}
}
func main() {
isPalindromo("A mamá, Roma le aviva el amor a papá, y a papá, Roma le aviva el amor a mamá")
}
>
Solución del reto
Solución:
Reto: Aunque estoy seguro que esto puede reducirse más 🤔
package main
import(
"fmt"
"strings"
)
func main(){
fmt.Println(
func(input string) bool{
var inputReverse string
for i:= len(input)-1; i>=0; i--{
inputReverse += string(input[i])
if input == inputReverse{
return true
}
}
return false
}(strings.ToLower("ana")),
)
}
Solución al reto
func isPalidromo(text string) {
text = strings.ToLower(text)
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palíndromo")
} else {
fmt.Println("No es un palíndromo")
}
}
func isPalindrome(word string) {
var textReverse string
for i := len(word) - 1; i >= 0; i-- {
textReverse += string(word[i])
}
if strings.ToLower(word) == strings.ToLower(textReverse) {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
package main
import (
"fmt"
"strings"
)
//Funcion palindromo
func isPalindromo(texto string) {
var textReverse string
texto = strings.ToLower(texto)
for i := len(texto) - 1; i >= 0; i-- {
textReverse += string(texto[i])
}
if texto == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
package main
import (
“fmt”
“strings”
)
func isPalindromo(text string) {
var textReverse string
fmt.Printf(“Texto original: %s\n”, text)
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
fmt.Printf(“Texto al revés: %s\n”, textReverse)
if strings.ToLower(text) == strings.ToLower(textReverse) {
fmt.Printf("%s es palíndromo \n", text)
} else {
fmt.Printf("%s no es palíndromo \n", text)
}
}
func main() {
isPalindromo(“Amor a Roma”)
}
//IMPRIME LO SIGUIENTE:
Texto original: Amor a Roma
Texto al revés: amoR a romA
Amor a Roma es palíndromo
solucion 😄
func palindromo(text string) {
var textReverse string
for i:= len(text) -1; i >=0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("es palindromo")
} else {
fmt.Println("no es palindromo")
}
}
func main() {
var letter string = "Amor a Roma"
letter = strings.ToLower(letter)
palindromo(letter)
}
Mi aporte con lectura de teclado:
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func isPalidromo(text string) bool {
var newText string
for i := len(text) - 1; i >= 0; i-- {
newText += string(text[i])
}
if strings.ToLower(newText) == strings.ToLower(text) {
return true
} else {
return false
}
}
func main() {
var texts = []string{}
var scanner = bufio.NewScanner(os.Stdin)
fmt.Print("Para finalizar presiona [Enter] sin texto...", "\n\n")
for {
fmt.Print("Ingresa el palindromo: ")
scanner.Scan()
text := scanner.Text()
if len(text) != 0 {
texts = append(texts, text)
} else {
break
}
}
fmt.Print("\n\nResultados: \n\n")
for _, value := range texts {
var out string
if isPalidromo(value) {
out = "es palindromo"
} else {
out = "no es palindromo"
}
fmt.Printf("[%s] %s \n", value, out)
}
}
Mi aporte
Saludos
// Palindromo
func main(){
checkPalindromo("Ala")
checkPalindromo("pesa")
checkPalindromo("ALa")
}
func checkPalindromo(word string) {
text := strings.ToLower(word)
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
😃
Solución al reto, incluyendo borrado de espacios y mayúsculas
package main
import (
"fmt"
"strings"
)
func cleanText(text string) string {
text = strings.ReplaceAll(text, " ", "")
text = strings.ToLower(text)
return text
}
func isPalindrome(text string) bool {
var textReverse string
text = cleanText(text)
textReverse = cleanText(textReverse)
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
return text == textReverse
}
func main() {
palindromes := [...]string{"ama", "Anita lava la tina", "AMOR A Roma", "Hola"}
for _, palindrome := range palindromes {
if isPalindrome(palindrome) {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
}
Tomando la librería strings
es posible utilizar la funcionalidad ToLower()
para hacer la traducción a minúsculas de la frase.
import "strings"
str := strings.ToLower(str)
Para realizar el algoritmo de búsqueda, se toma la siguiente lógica:
for i := 0; i < len(input)/2; i++
if input[i] != input[len(input)-i-1]
brake
para realizar la operación lógica. Sin embargo, buscamos la falla de la cadena con un return
resuelve el caso.La implementación de la función quedaría así:
func isPalindrome(input string) bool {
input = strings.ToLower(input)
for i := 0; i < len(input)/2; i++ {
if input[i] != input[len(input)-i-1] {
return false
}
}
return true
}
package main
import ( "fmt" "strings" )
func isPalindrome(input string) bool {
input = strings.ToLower(input)
for i := 0; i < len(input)/2; i++ {
if input[i] != input[len(input)-i-1] {
return false
}
}
return true
}
func main() {
fmt.Println(isPalindrome("ama")) // true
fmt.Println(isPalindrome("Amor a roma")) // true
fmt.Println(isPalindrome("other word")) // false
}
mi solución
package main
import (
"fmt"
"strings"
)
func reverseArr(arr []string) []string {
arrAux := []string{}
for i := len(arr) - 1; i >= 0; i-- {
arrAux = append(arrAux, arr[i])
}
return arrAux
}
func esPalindromo(str string) bool {
str = strings.ToLower(str)
strArr := strings.Split(str, "")
var strReverse string = strings.Join(reverseArr(strArr), "")
return (str == strReverse)
}
func main() {
var palindromo = esPalindromo("amor a Roma")
fmt.Println(palindromo)
}
package main
import (
"fmt"
"strings"
)
func isPalindromo(text string) {
var textReverse string
for i:= len(text) - 1; i >= 0; i-- {
textReverse += string(text[i]) // Esto es equivalente a textReverse = textReverse + lo que quiera agregar
}
if strings.ToLower(text) == strings.ToLower(textReverse) {
fmt.Println("Es palíndromo")
} else {
fmt.Println("No es palíndromo")
}
}
func main(){
isPalindromo("Ana")
}
😎
Interesante
Reto:
func isPalindromo(text string) {
var textReverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("es palindromo")
} else {
fmt.Println("no es palindromo")
}
}
Asi lo resolvi
package main
import (
"fmt"
"strings"
)
// Se crea la funcion is Palindromo con un parametro text
func isPalindromo(text string) {
var textReverse string
//text se convierte en minuscula con la funcion ToLower
lowerText := strings.ToLower(text)
fmt.Println(())
//Se convierte en textReverse
for i := len(lowerText) - 1; i >= 0; i-- {
textReverse += string(lowerText[i])
}
if lowerText == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
func main() {
isPalindromo("wAMA")
}
Mi solucion 😀
package main
import (
"fmt"
"strings"
)
func esPalindromo(text string) {
text = strings.ToLower(text)
text = strings.ReplaceAll(text, " ", "")
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
func main() {
esPalindromo("luz azul") // Es palindromo
esPalindromo("Ama") // Es palindromo
}
Este es el reto y como valor agregado otra forma de saber si un numero es palíndromo.
package main
import (
"fmt"
"strings"
)
func isPalindrom(s string) bool {
ans := true
for i := 0; i < len(s)/2; i++ {
if s[i] != s[len(s)-i-1] {
ans = false
}
}
return ans
}
func main() {
text := "Amor a Roma"
text2 := strings.ToLower(text)
if isPalindrom(text2) {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindomo")
}
}
Solución recorriendo la mitad de la cadena y sin almacenar en variable
func isPalindrome(pal string) bool{
for i := 0; i < len(pal)/2; i++{
if pal[i] != pal[len(pal) - 1 - i]{
return false
}
}
return true
}
Le quise dar una vuelta de tuerca al reto que compare dos palabras. El primer if está hecho así para no tener que hacer un loop innecesario, ya que nunca pueden ser palíndromos 2 palabras que no tenga la misma longitud.
No se si alguno me podrá ayudar, ya que creo que no haría falta tener 2 loop porque hacen lo mismo pero no se bien como hacerlo. Adjunto el código
package main
import (
"fmt"
"strings"
)
func isPalindromo(text1, text2 string) {
text1 = strings.ToLower(text1)
text2 = strings.ToLower(text2)
var text1Reverse string
var text2Reverse string
if len(text1) != len(text2) {
println("No es palindromo por caracteres")
} else {
for i := len(text1) - 1; i >= 0; i-- {
text1Reverse += string(text1[i])
}
for i := len(text2) - 1; i >= 0; i-- {
text2Reverse += string(text2[i])
}
if text1 == text2Reverse && text2 == text1Reverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
}
func main() {
isPalindromo("Amor", "Romaa")
}
Solución:
// Palindromos
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if strings.ToLower(text) == strings.ToLower(textReverse) {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
Palindromo
package main
import "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 palindromo(word string) bool {
if Reverse(strings.ToLower(word)) == strings.ToLower(word){
return true
}
return false
}
func main() {
print(palindromo("amor a roma"))
}
Hola. Comparto la clase en código de otra forma:
package main
import "fmt"
func main() {
fmt.Println()
fmt.Println("=======================================================================")
fmt.Println("Recorrido de Slices con Range... tipo de dato 'string' y manipulaciones")
fmt.Println("=======================================================================")
fmt.Println()
fmt.Println("En los ciclos FOR se ofrece una manera de tener el índice e inmediatamente el valor del 'la rebanada'")
fmt.Println()
fmt.Println("for indiceDeMiRebanada, valorDeMiRebanada := range miRebanada { ... }")
fmt.Println()
fmt.Println("A continuación se imprimen los índices y valores de un slice::::")
fmt.Println()
miRebanada := []string{"hola.", "que.", "hace"}
for indiceDeMiRebanada, valorDeMiRebanada := range miRebanada {
fmt.Printf("indisito: %d, valorsito >>> %s\n", indiceDeMiRebanada, valorDeMiRebanada)
}
fmt.Println()
fmt.Println("Si se quiere ignorar en el FOR alguna de las 'salidas', se puede usar el caracter '_'")
fmt.Println()
fmt.Println("for indiceDeMiRebanada, _ := range miRebanada {")
fmt.Println()
fmt.Println("o de forma simplificada:")
fmt.Println()
fmt.Println("for indiceDeMiRebanada := range miRebanada {")
fmt.Println()
fmt.Println("Valores impresos:::")
fmt.Println()
for indiceDeMiRebanada := range miRebanada {
fmt.Printf("indisito: %d, valorsito >>>...no se imprime...\n", indiceDeMiRebanada)
}
fmt.Println()
fmt.Println("Si se quisiera montar un FOR de una manera 'clásica tipo C' se podría hacer de la siguiente forma:")
fmt.Println()
fmt.Println("for i:= 0; i < len(miRebanada); i++ { fmt.Printf(\"|%s|\", miRebanada[i]) }")
fmt.Println()
fmt.Println("Imprimiendo:")
fmt.Println()
for i := 0; i < len(miRebanada); i++ {
fmt.Printf("|%s|", miRebanada[i])
}
fmt.Println()
fmt.Println()
fmt.Println("--------------------------------------")
fmt.Println("Breve manipulación de cadenas de texto")
fmt.Println("--------------------------------------")
fmt.Println()
fmt.Println("Primero decir que la concatenación de valores se puede hacer con el operador '+=', por ejemplo:")
fmt.Println("contador = contador + 1 >>> es igual a <<< contador += 1")
fmt.Println()
fmt.Println("Una cadena de texto se puede analizar caracter por caracter a partir de un índice, pero el valor retornado es la " +
"representación en código ASCII.")
fmt.Println()
const cadenaTexto8Caracteres string = "MiNombre"
fmt.Printf("El texto: '%s' se descompone así:\n", cadenaTexto8Caracteres)
fmt.Println()
fmt.Printf("|%v|", cadenaTexto8Caracteres[0])
fmt.Printf("|%v|", cadenaTexto8Caracteres[1])
fmt.Printf("|%v|", cadenaTexto8Caracteres[2])
fmt.Printf("|%v|", cadenaTexto8Caracteres[3])
fmt.Printf("|%v|", cadenaTexto8Caracteres[4])
fmt.Printf("|%v|", cadenaTexto8Caracteres[5])
fmt.Printf("|%v|", cadenaTexto8Caracteres[6])
fmt.Printf("|%v|", cadenaTexto8Caracteres[7])
fmt.Println()
fmt.Println()
fmt.Println("El valor ASCII se puede transformar a un valor string de un solo caracter con la función: string(...codigoAscci...):")
fmt.Println()
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[0]))
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[1]))
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[2]))
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[3]))
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[4]))
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[5]))
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[6]))
fmt.Printf("|%v|", string(cadenaTexto8Caracteres[7]))
fmt.Println()
fmt.Println()
fmt.Println("La comparación de string en GO no tiene el problema del lenguaje Java con el operador '==' y se puede obtener " +
"como booleano la respuesta de si es exáctamente el mismo texto.")
fmt.Println()
fmt.Println("if(cadenaTexto8Caracteres == \"MiNombre\") {")
if cadenaTexto8Caracteres == "MiNombre" {
fmt.Println()
fmt.Println("Fin de la lección.")
}
}
<
package main
import (
"fmt"
"strings"
)
func isPalindrome(text string) {
var textReverse string
text = strings.ToLower(text)
for i := len(text) - 1; i >= 0; i-- {
fmt.Println(string(text[i]))
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Palindrome")
} else {
fmt.Println("Not Palindrome")
}
}
func main() {
slice := []string{"Nunca", "Pares", "De", "Aprender"}
// Recordar que si no se necesita el indice se coloca _
for _, valor := range slice {
fmt.Println(valor)
}
isPalindrome("Ama")
}
>
package main
import (
“fmt”
“strings”
)
func isPalindromo(textA string) {
text := strings.ToLower(textA)
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
fmt.Println(len(text))
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es un palindromo")
}
}
func main() {
isPalindromo(“AmA”)
}
Importando la libreria strings y usando la función ToLower para formatear el texto ingresado en la función
Recorriendo la mitad del string
De esta forma evitamos recorrer toda la cadena para saber si es o no palíndromo,
func palindromo(test string) {
res := true
tmp := strings.ToLower(test)
for i := 0; i<len(tmp); i++ {
if tmp[i] != tmp[len(tmp) - i - 1] {
res = false
break;
}
}
if res {
fmt.Println("Es palindromo");
} else {
fmt.Println("No es palíndromo");
}
}
this is figured out
package main
import (
"fmt"
"strings"
)
func isPalindromo(text string) {
var lowerText = strings.ToLower(text)
var textReverse string
for i := len(lowerText) - 1; i >= 0; i-- {
textReverse += string(lowerText[i])
}
if lowerText == textReverse {
println("Es palindromo")
} else {
println("No es palindromo")
}
}
func main() {
slice := []string{"Ola", "K", "Ase"}
for i := range slice {
fmt.Println(i)
}
isPalindromo("amor a romA")
}
Solución leyendo multiples palabras.
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func isPalindromo(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if text == textReverse {
fmt.Println("Si es Palindromo")
} else {
fmt.Println("No es Palindromo")
}
}
func main() {
fmt.Println("Teclea una palabra y te diremos si es palindromo o no")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
palabra := scanner.Text()
minus := strings.ToLower(palabra)
isPalindromo(minus)
}
Espero les sirva compañeros. 😄
Solución al reto
Agregué el paquete de go “strings” para poder parsear a minusculas los strings
func isPalindrom(text string) {
var textReverse string
for i := len(text) - 1; i >= 0; i-- {
textReverse += string(text[i])
}
if strings.ToLower(text) == strings.ToLower(textReverse) {
fmt.Println("Is Palindrom")
} else {
fmt.Println("Is not Palindrom")
}
}
Mi solución al reto
Screenshot tomado con la extensión de VSCode llamada Polacode https://marketplace.visualstudio.com/items?itemName=pnp.polacode
package main
import (
"fmt"
"strings"
)
var texto string = "Amor a roma"
var sinEspacios []string // declarar un slice
var textoInvertido []string
func main(){
texto = strings.ToLower(texto)
//line := string(texto[2]) // devuelve el ascii, hay que parsearlo a string
for i := 0; i < len(texto); i++ {
if string(texto[i]) != " " {
sinEspacios = append(sinEspacios, string(texto[i]))
}
}
for i := len(sinEspacios) - 1; i >= 0 ; i-- {
textoInvertido = append(textoInvertido, string(sinEspacios[i]))
}
textoUno := strings.Join(sinEspacios, "")
textoDos := strings.Join(textoInvertido, "")
/*
verificar el output
for _, value := range sinEspacios { // key, value no voy a usar key entonces lo escapo
fmt.Printf(value)
}
*/
if textoUno == textoDos {
fmt.Println("Palindromo")
} else {
fmt.Println("No es Palindromo")
}
}
/*
for i := 0; i < len(texto); i++ {
texto[i]
}
*/
Mi aporte 😃
package main
import (
"fmt"
"strings"
)
func isPalindromo(text string) {
textLower := strings.ToLower(text)
var textReverse string
for i := len(textLower) - 1; i >= 0; i-- {
textReverse += string(textLower[i])
}
if textLower == textReverse {
fmt.Println("Es palindromo")
} else {
fmt.Println("No es palindromo")
}
}
func main() {
isPalindromo("AmaT")
}
Los aportes, preguntas y respuestas son vitales para aprender en comunidad. Regístrate o inicia sesión para participar.