From 043b47b4429e3c0d4cdf7722a456045709fc2a9a Mon Sep 17 00:00:00 2001 From: hudazaan Date: Wed, 15 Oct 2025 21:22:23 +0530 Subject: [PATCH] Add solution for Challenge 17 by hudazaan --- .../submissions/hudazaan/solution-template.go | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 challenge-17/submissions/hudazaan/solution-template.go diff --git a/challenge-17/submissions/hudazaan/solution-template.go b/challenge-17/submissions/hudazaan/solution-template.go new file mode 100644 index 00000000..5bef5d37 --- /dev/null +++ b/challenge-17/submissions/hudazaan/solution-template.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "strings" + "unicode" +) + +func main() { + // Get input from the user + var input string + fmt.Print("Enter a string to check if it's a palindrome: ") + fmt.Scanln(&input) + + // Call the IsPalindrome function and print the result + result := IsPalindrome(input) + if result { + fmt.Println("The string is a palindrome.") + } else { + fmt.Println("The string is not a palindrome.") + } +} + +// IsPalindrome checks if a string is a palindrome. +// A palindrome reads the same backward as forward, ignoring case, spaces, and punctuation. +func IsPalindrome(s string) bool { + // Clean the string: remove non-alphanumeric characters and convert to lowercase + cleaned := strings.Builder{} + for _, char := range s { + if unicode.IsLetter(char) || unicode.IsDigit(char) { + cleaned.WriteRune(unicode.ToLower(char)) + } + } + + cleanStr := cleaned.String() + + // Check if the cleaned string is the same forwards and backwards + left := 0 + right := len(cleanStr) - 1 + + for left < right { + if cleanStr[left] != cleanStr[right] { + return false + } + left++ + right-- + } + + return true +} \ No newline at end of file