6 kyu
Squares in a Rectangle
689 of 1,499emaclean
Loading description...
Mathematics
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
python new test framework is required. updated in this fork
Approved
python: function names should be snake_case
Fixed by OP
What do the examples mean when they say 3x2 has 8 squares?
Isn't it explained there?
Grab pen and paper and draw them to help you.
I included a breakdown of the O(1) formula in my solution.
COBOL: Incorrect results (see comment below by JJGR).
fixed by monadius
In COBOL I don't understand test cases. My code works correctly when x >= y, but when x < y it doesn't work. My program returns the same solution when the rectangle is xy or yx, it makes sense because the rotation of the rectangle (vertical or horizontal) should not affect the number of squares that fit inside it. I don't understand. :-(
Please, anyone can review my issue? If the test case is x = 4, y = 2, the result is 11, because inside there are 8 squares 1x1 and 3 squares 2x2 (total = 8 + 3 = 11). It works correctly. But, if the test case is x = 2, y = 4, the result must be 11 also (8 squares 1x1 + 3 squares 2x2), but the expected result says it is 10 (WRONG!!!)
This looks to be an issue in the kata.
I fixed random tests: Now it is enforced that
X >= Y
. Your solution should be able to pass all tests now.Thanks monadius. It is working now.
COBOL translation updated.
approved
@akar-0
@dfhwze
, could any of you guys take a look at the post above? I haven't solved this yet :XCOBOL translation kumited.
approved, but there seems to be an issue with random tests always expecting 0.
Are you sure? I have just controlled forking the translation, and in the trainer, printing the result / UT-actual-numeric and everything seemed to work fine.
Damned, I think I know... Wait a min.
you're executing the solution before the ref solution
I'll post on the translation page.
Can you approve the fork?, it should be ok I used a O(1) solution.
All good now :)
thanks
Nice kata! Can be solved in O(1)
Function name in Python should be snake cased.
Fixed in latest fork
My recursive solution which easily passes in JS throws repetition limit error (995 times) in Python, when the second number is >995. If anything, such error should be thrown with many many more repetitions. Please fix it.
And what's the problem here? Your solution causing an error? Explain yourself properly, until then not an issue.
I don't think it can be explained clearer. Is 995 recursion repetitions really too many in Python? Read with understanding, please.
This comment has been hidden.
still, not a kata issue. 1000 nested recursive calls is default setting of python runtime.it IS Python specific problem, not related to CW.
teoriachaosu, remember using spoiler flag when posting code like that, please.
Oh, I see. Thanks for info, hobovsky.
@Chrono79 Of course. I marked it as a spoiler, saw no effect and marked it again, didn't think about the delay. Second mark unmarked it :)
Current Ruby translation exposes solution and doesn't include random tests. Fixed Ruby translation waiting for approval:
Thanks, approved.
Haskell: some random test cases have
x < y
, which doesn't agree with the description.Fix submitted.
Thanks, approved.
Am I missing something? x=13878 y=3578 expected:<-380198835>
Oh, should've tagged this as an issue, I'll check and fix this.
Ruby: https://www.codewars.com/kumite/5c055ad29e49716c420001c9?sel=5c055ad29e49716c420001c9
Approved, thanks.
Are these overlapping or distinct squares? Because 3x2 contains 2 overlapping 2x2 squares and 6 distinct 1x1 squares
As I said in the description, it's any possible square, including overlapping ones, so the 3x2 rectangle has 8 total squares with 6 1x1s and 2 2x2s. Sorry for the late response, I haven't been very active recently.
are these overlapping squares or distinct? because 3*2 contains 2 overlapping squares of area 2x2. and it contains 6 distinct squares of 1x1.
Haskell : https://www.codewars.com/kumite/5b873a0c36332f9f400000ef?sel=5b873a0c36332f9f400000ef
Approved, thanks, sorry about the late response.
check out my 1 line :)