Skip to content

Add solution for Challenge 10 by shansing#1436

Open
shansing wants to merge 4 commits intoRezaSi:mainfrom
shansing:challenge-10-shansing
Open

Add solution for Challenge 10 by shansing#1436
shansing wants to merge 4 commits intoRezaSi:mainfrom
shansing:challenge-10-shansing

Conversation

@shansing
Copy link
Contributor

Challenge 10 Solution

Submitted by: @shansing
Challenge: Challenge 10

Description

This PR contains my solution for Challenge 10.

Changes

  • Added solution file to challenge-10/submissions/shansing/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 Feb 26, 2026

Warning

Rate limit exceeded

@shansing has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7cf1e06 and c8503a8.

📒 Files selected for processing (1)
  • challenge-10/submissions/shansing/solution-template.go

Walkthrough

Adds a new Go package implementing a Shape interface and concrete types (Rectangle, Circle, Triangle) with validated constructors, Area/Perimeter/String methods, and a ShapeCalculator providing aggregate utilities (TotalArea, LargestShape, SortByArea, PrintProperties).

Changes

Cohort / File(s) Summary
Shape Types and Calculator
challenge-10/submissions/shansing/solution-template.go
Adds Shape interface and concrete types Rectangle, Circle, Triangle with validated constructors and methods (Area, Perimeter, String). Adds ShapeCalculator with NewShapeCalculator, PrintProperties, TotalArea, LargestShape, and SortByArea. String formatting and input validation included.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hop through shapes both round and straight,
Circles, triangles, rectangles—what a fate!
I measure areas and perimeters with glee,
Sort them, sum them, proud as can be,
A tiny rabbit coders' jubilee! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add solution for Challenge 10 by shansing' directly and clearly describes the main change: adding a solution file for Challenge 10 by the contributor shansing.
Description check ✅ Passed The description is directly related to the changeset, explaining the Challenge 10 solution submission, listing the added file, and noting testing and code quality checks.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 (2)
challenge-10/submissions/shansing/solution-template.go (2)

94-101: Consider extracting semi-perimeter for clarity.

The semi-perimeter (t.SideA + t.SideB + t.SideC) / 2.0 is computed four times. Extracting it into a local variable improves readability.

♻️ Proposed refactor
 func (t *Triangle) Area() float64 {
-	return math.Sqrt(
-		((t.SideA + t.SideB + t.SideC) / 2.0) *
-			(((t.SideA + t.SideB + t.SideC) / 2.0) - t.SideA) *
-			(((t.SideA + t.SideB + t.SideC) / 2.0) - t.SideB) *
-			(((t.SideA + t.SideB + t.SideC) / 2.0) - t.SideC),
-	)
+	s := t.Perimeter() / 2.0
+	return math.Sqrt(s * (s - t.SideA) * (s - t.SideB) * (s - t.SideC))
 }

140-148: Misleading variable name: lastShape should be largestShape.

The variable stores the shape with the largest area, not the "last" shape.

♻️ Proposed fix
 	largestArea := 0.0
-	var lastShape Shape
+	var largestShape Shape
 	for _, shape := range shapes {
 		if shape.Area() > largestArea {
 			largestArea = shape.Area()
-			lastShape = shape
+			largestShape = shape
 		}
 	}
-	return lastShape
+	return largestShape

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a7ac764 and 06608bd.

📒 Files selected for processing (1)
  • challenge-10/submissions/shansing/solution-template.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

🧹 Nitpick comments (2)
challenge-10/submissions/shansing/solution-template.go (2)

94-101: Consider extracting the semi-perimeter calculation.

The semi-perimeter (t.SideA + t.SideB + t.SideC) / 2.0 is computed four times. Extracting it into a local variable improves readability and adheres to DRY.

♻️ Proposed refactor
 // Area calculates the area of the triangle using Heron's formula
 func (t *Triangle) Area() float64 {
-	return math.Sqrt(
-		((t.SideA + t.SideB + t.SideC) / 2.0) *
-			(((t.SideA + t.SideB + t.SideC) / 2.0) - t.SideA) *
-			(((t.SideA + t.SideB + t.SideC) / 2.0) - t.SideB) *
-			(((t.SideA + t.SideB + t.SideC) / 2.0) - t.SideC),
-	)
+	s := t.Perimeter() / 2.0
+	return math.Sqrt(s * (s - t.SideA) * (s - t.SideB) * (s - t.SideC))
 }

140-148: Misleading variable name: lastShape should be largestShape.

The variable holds the shape with the largest area found so far, not the "last" shape. Renaming improves code clarity.

📝 Proposed fix
 	largestArea := 0.0
-	var lastShape Shape
+	var largestShape Shape
 	for _, shape := range shapes {
 		if shape.Area() > largestArea {
 			largestArea = shape.Area()
-			lastShape = shape
+			largestShape = shape
 		}
 	}
-	return lastShape
+	return largestShape

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06608bd and 7cf1e06.

📒 Files selected for processing (1)
  • challenge-10/submissions/shansing/solution-template.go

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