6 kyu
Counting Rectangle Triangles
213 of 448raulbc777
Loading description...
Fundamentals
Mathematics
Geometry
Algorithms
Logic
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.
Rust tests generate warning on using itertools::zip; fixed in the branch, please merge.
Let's see with the translator of this kata into Rust: @akar-0
looks ok
A small recomandation is to create separate testcases, and not placing all verifications in one test. I got stuck for a long time on finding that dublicates points should be ignored.
Example for java:
Hi guys, can someone pls help me with the part to check if triangle is a rectangle one.
I use the basic formula
a^2 + b^2 = c^2
wherec
is the biggest side of the triangle. However, my algorigthm had found 0 triangles so far.Let's take for example the triangle
ABC
from description's picture. There are 3 rounded wideswhich is obvious that this is not a rectangle triangle.
Your general idea is not wrong, but you do need to calculate sides correctly, e.g. AB is actually 2.236.
How for example triangle
DCE
is a rectangle triangle ?Why not?
Yes, you get a rounding error, but there's a simple workaround to eliminate that.
Thanks, my main issue was comparing floating values like
12.999999999999998
and13
.There will be maybe good to have also tests with real(double) not int input data like Point(0.2345677, 12.1234577).
This comment has been hidden.
Deprecation warning in Rust while attempting to pass:
python new test framework is required. updated in this fork
Approved!
Since I used numpy in this problem, my code ran a little longer than necessary. In total, like about 20000 ms. I couldn't get below 12000 ms. Although I struggled for about 6 hours, unfortunately I could not see that the problem was caused by numpy and I opened the solutions. I actually saw that I wrote code similar to other solutions and it didn't make me happy. I wasn't happy again because I wasted my day and lost the kata's points :)) Now I didn't use numpy and my code took between 7500-8500 ms. Thank you for reading.
Not a real issue but....
Your 'Point' structure defines both bool operator==() and bool operator<() for Point.
Thus your comment at the top of the c++ code is misleading: having to write those operators leads to a compiler fault 'redefinition'.
IMHO You have to make a special 'Pointx' structure (in your solution & tests) and keep the pure {x,y} Point in the kata as parameter to the function call.
Please say which language you are refering to, most of them don't use a Point structure.
So sorry... C++ alas :-)
D translation
Approved +1!!
Rust translation
Approved +1
Please, use the actually correct term, "right triangle". At least the description has to be fixed; although it may be problematic, ideally, the kata title should be changed too.
O(n^3)
solution times out in Python but passes without any issue in JavaScript.Edit: now
O(n^3)
solutions pass - both mine inside the trainer and other users' as forks; maybe the code-runner servers were under heavy load just now. I'm leaving this issue open as the inputs are unreasonably big (up to 80 points per test) which is pointless since the author's solution isO(n^3)
itself, and often it is impossible to construct a single right triangle out of them anyway.C test code has compilation warnings.
Updated
The description is technically lacking that only unique triangles must be counted, and not "all triangles". Only the one example is hinting at that.
The tests pass with O(N^3) solutions, which shouldn't happen. Add a random test with a approx. 300 points chosen from a 20x40 grid.
Python 3 should be enabled for Python version.
Enabled just now!
If something doesn't work well, let me know it.
Java:
@clcraig: don't reinvent the wheel: use the builtin java.awt.Point. And declaring your class with that name leads to weird things "to do", imo... (I hesitated a lot between a suggestion and an issue... Let's say it's an issue?)
.
Before I make a change, let's hash this out. As it stands, the code works. The custom Point class is comparable. I can add that comment to the solution setup. I went with that name for consistency with the other language versions. If I changed it, then what would you suggest? Vertex?
Mmmmh... Ok, so let me summarize my mind about the whole thing:
awt.Point
class is hashable, manage equality if needed, has already half of the stuff you need for this task (see my code), so it is what you really need for this kata.From there, I see several options:
awt.Point
, and tell all the things we should know about in the description (or in the solution setup if you do not want to have to manage empty code blocks for the other languages)int[][]
as inputs. I'd really urge you toward this direction: the task wouldn't be oriented, all approaches are still possible, the users who don't know about will learn more things, looking at others solutions.I'm fine with either of the last 2 options. Anyone else have feedback? I'll wait to publish the changes tomorrow.
@raulbc777, Java update published. I went with option 2.
;-)
This comment has been hidden.
@raulbc777, C and Java translations available.
.
please see upper about your java translation
@raulbc777, C++ translation available.
.
Right? Or rect?
I'll fix it now. Thanks a lot.
It's printed as text now:
<font color='sky blue'>testing for:
. I'm not sure why color is needed at all, especially only font color without background color, you never know what styles will be in the future. (I once opened mongodb.com in Steam browser and there was black text on black background because the font color was set to black and the background was black by default.) Anyway, HTML in logs can be forced with<LOG:HTML:>
in the beginning. Also, color names are not official, most never were; even more surprising it even works with the space; thatfont
tag these days too (although it will probably work forever for compatibility)... And how about Python 3 support?This comment has been hidden.
164 Random tests is maybe just a bit much.
About, oh, say 40 or 50 would prove just as plausibly that a given solution is correct [whisper] and incidentally might allow me to pass my beautiful functional solution .. :P please? [/whisper]
(This is JavaScript BTW.)
This comment has been hidden.
Apparently with the example in the description you mean identical points should be used only once, and it is possible for there to be more than five points from which to pick three (different ones).
I suggest this does not add to the essence of the kata.
There are now three unrelated challenges: picking out different points from the input; picking all combinations of three points out of the resulting list; determining if those three points form a right-angled triangle.
If you want it that way, fine, your kata. :D Even then, you might consider explaining it that way, instead of with an example case.
In the picture, it's not AEC that is 90°, it's DEC. (Mind that in this case, order matters. DEC is not the same as CDE.)
Oh, I noticed your observation. I'll correct it.
Finally I corrected the error you observed. Thanks.
Some new points for you:-)... You are able to publish new katas??? Isn't there something missing - which has to do with C#...:-)))?!
I was busy reading a very interesting book, "How to Overcome Life Challenges". :) Honestly, I've got an inspiration to publish some katas related with geometry computation while I start to solve the first 8 kyu C# katas.
WOOOOHOOOOO. First C#-katas sounds great! And soon you will solve the "THE-RAUL-KATA". Who else could do something like this? :-)
Seems to me that this is the right book for your next (c#) time:-)...
A friend of mine lend me another another interesting book for tonight. "The Coding Conspiracy". It's a thriller. :)