Skip to content

Conversation

@macborowy
Copy link
Contributor

Challenge 2 Solution

Submitted by: @macborowy
Challenge: Challenge 2

Description

This PR contains my solution for Challenge 2.

Changes

  • Added solution file to challenge-2/submissions/macborowy/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 Oct 12, 2025

Walkthrough

Adds a new Go program for Challenge 2 that reads a line from stdin, reverses the string via a new exported function ReverseString using rune slicing, and prints the result.

Changes

Cohort / File(s) Summary of edits
Challenge 2 submission
challenge-2/submissions/macborowy/solution-template.go
New Go file introducing ReverseString(s string) string (rune-based in-place reverse) and a main that reads one line via bufio, reverses it, and prints the output.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Main as Go Program (main)
  participant IO as bufio.Scanner / os.Stdin
  participant Fn as ReverseString
  participant Out as fmt.Println / os.Stdout

  User->>Main: Run program
  Main->>IO: Read single line from stdin
  IO-->>Main: Input string s
  Main->>Fn: ReverseString(s)
  Fn-->>Main: reversed string r
  Main->>Out: Print r
  Out-->>User: Output reversed string
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

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 clearly conveys the main change by stating that a solution for Challenge 2 is being added and names the author, which aligns directly with the contents of the changeset and is concise and specific.
Description Check ✅ Passed The description is directly related to the changeset, outlining the purpose of the PR, listing the new file, and noting that tests pass and Go best practices are followed, which accurately reflects the submitted changes.

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: 1

🧹 Nitpick comments (1)
challenge-2/submissions/macborowy/solution-template.go (1)

23-30: LGTM! Correct Unicode handling.

The implementation correctly handles Unicode characters by converting to runes before reversing. The two-pointer swap technique is efficient and idiomatic.

Optional: The spacing in len(r) - 1 is not standard Go formatting. Running gofmt would change it to len(r)-1, though this is purely cosmetic.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a2868df and 0943493.

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

Comment on lines +9 to +21
func main() {
// Read input from standard input
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
input := scanner.Text()

// Call the ReverseString function
output := ReverseString(input)

// Print the result
fmt.Println(output)
}
}
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

Add error handling for scanner errors.

The code checks scanner.Scan() but does not verify scanner.Err() afterward. If Scan() returns false due to an error (not just EOF), the error is silently ignored, which could mask real I/O problems.

Apply this diff to add proper error handling:

 func main() {
 	// Read input from standard input
 	scanner := bufio.NewScanner(os.Stdin)
 	if scanner.Scan() {
 		input := scanner.Text()
 
 		// Call the ReverseString function
 		output := ReverseString(input)
 
 		// Print the result
 		fmt.Println(output)
 	}
+	if err := scanner.Err(); err != nil {
+		fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
+		os.Exit(1)
+	}
 }
📝 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
func main() {
// Read input from standard input
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
input := scanner.Text()
// Call the ReverseString function
output := ReverseString(input)
// Print the result
fmt.Println(output)
}
}
func main() {
// Read input from standard input
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
input := scanner.Text()
// Call the ReverseString function
output := ReverseString(input)
// Print the result
fmt.Println(output)
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Error reading input: %v\n", err)
os.Exit(1)
}
}
🤖 Prompt for AI Agents
In challenge-2/submissions/macborowy/solution-template.go around lines 9 to 21,
the main function uses scanner.Scan() but never checks scanner.Err(), so I/O
errors are silently ignored; after the Scan loop (or after the Scan call)
capture scanner.Err(), and if non-nil print an error message to stderr (or log
and exit with non-zero status) to surface the I/O failure; ensure you only print
the reversed output when Scan succeeded and handle/return on scanner.Err() to
avoid masking read errors.

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