Skip to content

Conversation

macborowy
Copy link

Challenge 1 Solution

Submitted by: @macborowy
Challenge: Challenge 1

Description

This PR contains my solution for Challenge 1.

Changes

  • Added solution file to challenge-1/submissions/macborowy/solution-template.go

Testing

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

Thank you for reviewing my submission! 🚀

Copy link

coderabbitai bot commented Oct 12, 2025

Walkthrough

Adds a new Go program under challenge-1/submissions/macborowy that reads two integers from stdin, computes their sum via an exported Sum function, handles input errors by printing a message and exiting with status 1, and prints the result.

Changes

Cohort / File(s) Summary of Changes
Challenge 1 solution (macborowy)
challenge-1/submissions/macborowy/solution-template.go
Added standalone Go program with main; reads two ints using "%d, %d", defines exported Sum(a, b int) int, handles scan error with message and exit code 1, prints sum.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User (stdin)
  participant P as Program (main)
  participant F as Sum(a,b)
  participant OS as OS/Runtime

  U->>P: Provide "a, b" as input
  P->>P: Parse input ("%d, %d")
  alt Parse error
    P->>OS: Print error message
    P-->>OS: Exit status 1
  else Success
    P->>F: Call Sum(a,b)
    F-->>P: Return a+b
    P->>OS: Print result
  end
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 that this PR adds a solution for Challenge 1 and directly reflects the main change in the changeset, making it concise and specific.
Description Check ✅ Passed The description outlines the submission’s purpose, file location, and testing status, and it aligns with the changes introduced in the PR, making it relevant and on-topic.

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

@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: 0

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

11-14: Consider printing errors to stderr.

While the error handling logic is correct, Go best practices recommend writing error messages to os.Stderr instead of standard output. Additionally, you could check the return count from Scanf to ensure both values were successfully read.

Apply this diff to improve error handling:

 	var a, b int
 	// Read two integers from standard input
-	_, err := fmt.Scanf("%d, %d", &a, &b)
+	n, err := fmt.Scanf("%d, %d", &a, &b)
 	if err != nil {
-		fmt.Println("Error reading input:", err)
+		fmt.Fprintln(os.Stderr, "Error reading input:", err)
+		os.Exit(1)
+	}
+	if n != 2 {
+		fmt.Fprintln(os.Stderr, "Expected two integers")
 		os.Exit(1)
 	}
📜 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 d4cbc66.

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

1-6: LGTM!

The package declaration and imports are appropriate for this challenge solution.


17-25: LGTM!

The Sum function is correctly implemented with clear logic, and the result is properly printed. The solution effectively solves Challenge 1.

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.

1 participant