Sobes.tech
Middle

Write a function that checks whether a string is a palindrome. - A palindrome is a sequence of characters that reads the same forwards and backwards. - Only alphabetic characters a-zA-Zа-А-я should be checked, case-sensitive should not be considered.

sobes.tech AI

Answer from AI

go package main

import ( "fmt" "unicode" "strings" )

func isPalindrome(s string) bool { var filtered []rune for _, r := range s { if unicode.IsLetter(r) { filtered = append(filtered, unicode.ToLower(r)) } }

// Check for palindrome
for i := 0; i < len(filtered)/2; i++ {
	if filtered[i] != filtered[len(filtered)-1-i] {
		return false
	}
}
return true

}

func main() { fmt.Println(isPalindrome("А роза упала на лапу Азора")) // true fmt.Println(isPalindrome("Hello, World!")) // false }


The function first filters the string, keeping only letters (Latin and Cyrillic), converting them to lowercase, then checks if the sequence matches its reverse.