Skip to content

Conversation

@Johrespi
Copy link
Contributor

Challenge 17 Solution

Submitted by: @Johrespi
Challenge: Challenge 17

Description

This PR contains my solution for Challenge 17.

Changes

  • Added solution file to challenge-17/submissions/Johrespi/solution-template.go

Testing

  • Solution passes all test cases
  • Code follows Go best practices

Thank you for reviewing my submission! 🚀

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

Adds a Go solution implementing a palindrome checker function IsPalindrome that normalizes input to lowercase letters and digits, then validates using a two-pointer approach. Includes a main function for interactive user testing.

Changes

Cohort / File(s) Change Summary
Palindrome checker solution
challenge-17/submissions/Johrespi/solution-template.go
New file with IsPalindrome(s string) bool function that normalizes input by converting to lowercase and filtering to alphanumeric characters, then checks for palindrome symmetry using two pointers. Includes main entry point for interactive user input and output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the two-pointer palindrome logic correctly handles edge cases (empty strings, single characters)
  • Confirm rune filtering and lowercase conversion are properly applied
  • Check that main function properly reads user input and handles EOF scenarios

Possibly related PRs

  • Add solution for Challenge 17 by hudazaan #587: Implements an identical IsPalindrome(s string) bool function with the same normalization and two-pointer approach, plus nearly identical main program structure in a different submission file.

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a solution for Challenge 17 by the contributor Johrespi, which matches the file added.
Description check ✅ Passed The description is directly related to the changeset, clearly identifying it as a Challenge 17 solution submission with specific details about the changes made.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
challenge-17/submissions/Johrespi/solution-template.go (1)

27-27: Remove trailing whitespace.

Lines 27 and 39 contain trailing whitespace. While not functionally problematic, removing it improves code hygiene.

Also applies to: 39-39

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a9dd2e and f6582e4.

📒 Files selected for processing (1)
  • challenge-17/submissions/Johrespi/solution-template.go (1 hunks)

Comment on lines +9 to +22
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.")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix input reading to support multi-word palindromes.

fmt.Scanln stops at the first whitespace, so multi-word palindrome test cases like "A man a plan a canal Panama" will only read "A". This significantly limits the usability of the interactive tester.

Apply this diff to read the entire line:

 import (
+	"bufio"
 	"fmt"
+	"os"
 	"strings"
 	"unicode"
 )

 func main() {
-	// Get input from the user
-	var input string
+	reader := bufio.NewReader(os.Stdin)
 	fmt.Print("Enter a string to check if it's a palindrome: ")
-	fmt.Scanln(&input)
+	input, _ := reader.ReadString('\n')
+	input = strings.TrimSpace(input)

 	// Call the IsPalindrome function and print the result
 	result := IsPalindrome(input)

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In challenge-17/submissions/Johrespi/solution-template.go around lines 9 to 22,
the interactive input uses fmt.Scanln which stops at the first whitespace;
replace it with reading the full line (e.g., use
bufio.NewReader(os.Stdin).ReadString('\n')), then trim the trailing
newline/whitespace with strings.TrimSpace before passing to IsPalindrome, and
update imports to include bufio, os and strings as needed.

Comment on lines +40 to +46
n := len(cleanedStr)

for i := 0; i < n/2; i++ {
if cleanedStr[i] != cleanedStr[n-1-i] {
return false
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix byte-level comparison that breaks for non-ASCII Unicode characters.

The current implementation compares individual bytes via cleanedStr[i], which fails for multi-byte UTF-8 characters. Since the function accepts Unicode letters (via unicode.IsLetter), palindromes with non-ASCII characters like "été" will incorrectly return false.

Example failure:

  • Input: "été" (French, a valid palindrome)
  • UTF-8 bytes: [0xC3, 0xA9, 0x74, 0xC3, 0xA9]
  • Comparison: cleanedStr[0] (0xC3) ≠ cleanedStr[4] (0xA9) → false ❌

Apply this diff to compare runes instead of bytes:

 	cleanedStr := cleaned.String()
-    
-	n := len(cleanedStr)
+	
+	runes := []rune(cleanedStr)
+	n := len(runes)
 	
 	for i := 0; i < n/2; i++ {
-		if cleanedStr[i] != cleanedStr[n-1-i] {
+		if runes[i] != runes[n-1-i] {
 			return false 
 		}
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
n := len(cleanedStr)
for i := 0; i < n/2; i++ {
if cleanedStr[i] != cleanedStr[n-1-i] {
return false
}
}
runes := []rune(cleanedStr)
n := len(runes)
for i := 0; i < n/2; i++ {
if runes[i] != runes[n-1-i] {
return false
}
}
🤖 Prompt for AI Agents
In challenge-17/submissions/Johrespi/solution-template.go around lines 40 to 46,
the code compares bytes (cleanedStr[i]) which breaks for multi-byte UTF-8
characters; change the logic to operate on runes by converting cleanedStr to a
[]rune (or building a rune slice while filtering) and then compare runes by
index (runes[i] vs runes[n-1-i]) using the rune-length n, so multi-byte Unicode
letters are handled correctly.

@RezaSi RezaSi merged commit 67182fb into RezaSi:main Nov 11, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants