6 kyu

Counting Rectangle Triangles

213 of 448raulbc777
Description
Loading description...
Fundamentals
Mathematics
Geometry
Algorithms
Logic
View
AllIssues7Questions1Suggestions11Show Resolved
  • Please sign in or sign up to leave a comment.
  • pavloslav Avatar

    Rust tests generate warning on using itertools::zip; fixed in the branch, please merge.

  • Alexenon Avatar

    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:

    ...
    
    @Test
    public void dublicatePointsTest() {
        assertEquals(3, Solution.countRectTriang(new Point[]{
                new Point(1, 2), new Point(4, -1), new Point(3, 3),
                new Point(4, -1), new Point(4, 1), new Point(1, 1),
                new Point(4, -1), new Point(4, -1), new Point(3, 3),
                new Point(1, 2)
        }));
    }
    
    ...
    
  • Alexenon Avatar

    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 where c 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 wides

      AB = 2 
      BC = 2 
      AC = 3
    

    which is obvious that this is not a rectangle triangle.

  • hrafov Avatar

    There will be maybe good to have also tests with real(double) not int input data like Point(0.2345677, 12.1234577).

  • CapBrandonML Avatar

    This comment has been hidden.

  • xianjin Avatar

    Deprecation warning in Rust while attempting to pass:

    warning: use of deprecated function `itertools::zip`: Use [std::iter::zip](https://doc.rust-lang.org/std/iter/fn.zip.html) instead
    
  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • lokman gokce Avatar

    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.

  • eurydice5717 Avatar

    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.

  • akar-0 Avatar
  • akar-0 Avatar
  • FArekkusu Avatar

    We need to count all the rectangle triangles

    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.

  • FArekkusu Avatar

    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 is O(n^3) itself, and often it is impossible to construct a single right triangle out of them anyway.

  • nomennescio Avatar

    C test code has compilation warnings.

  • nomennescio Avatar

    The description is technically lacking that only unique triangles must be counted, and not "all triangles". Only the one example is hinting at that.

  • ecolban Avatar

    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.

  • Voile Avatar

    Python 3 should be enabled for Python version.

  • Blind4Basics Avatar

    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?)

  • wowkanwowka Avatar

    This comment has been hidden.

  • clcraig Avatar

    @raulbc777, C and Java translations available.

  • clcraig Avatar

    @raulbc777, C++ translation available.

  • amarovita Avatar

    We need to count all the right triangles that may be formed by a given list of points.

    Right? Or rect?

  • Unnamed Avatar

    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; that font tag these days too (although it will probably work forever for compatibility)... And how about Python 3 support?

  • JohanWiltink Avatar

    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.)

  • JohanWiltink Avatar

    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.

  • JohanWiltink Avatar

    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.)

  • smile67 Avatar

    Some new points for you:-)... You are able to publish new katas??? Isn't there something missing - which has to do with C#...:-)))?!