6 kyu

A Fun Way of Finding Pythagorean Triples

185 of 213brodiemark
Description
Loading description...
Geometry
Mathematics
Algorithms
  • Please sign in or sign up to leave a comment.
  • PickCormac Avatar

    is this broken?

    • rowcased Avatar

      what makes you think it's broken?

    • PickCormac Avatar

      When doing a full attempt, it comes up saying i have extra triples, although these triples are valid, and Im pretty confident my iteration through range of a is working correctly. I saw that the task was somewhat old and that wisdou had issues with c# big numbers before, thought it possible that the testing algorithm had become outdated or something maybe. Can you perhaps look at my code and tell me whether I have just created a faulty program or if the issue is something deeper. Am new to both c# and codewars so could issue be a me issue.

    • brodiemark Avatar

      I believe you are correct! The C# (and the Java and Swift translations) are overlooking solutions where the squares of one or more of a,b,c exceed the integer bound.

      For example, for diff = 8696, low = 945745, high = 2531281, the Python solution finds (947864, 51654240, 51662936) as a valid triple. But the C# version does all the calculations in integers, and so overlooks this (and other triples). If the calculations are done using doubles (as your program wisely does), it finds them. Amazingly, all the people who solved the C# version previously overlooked this as well (so I don't feel so bad :-)).

      I believe I have fixed the translations.

      Congratulations on discovering this!

    • brodiemark Avatar

      PickCormac, please try your solution again. It should be successful.

    • PickCormac Avatar

      Yes, it has been accepted now, thanks

  • amarovita Avatar

    create_pythagorean_triples(564, 456, 1654) [(1128, 846, 1410)] should equal []

    But 1128 ** 2 + 846 ** 2 == 1410 ** 2, 846 + 564 == 1410

    Did i miss something?

    • brodiemark Avatar

      a, the first element of the triple, has to be the smallest side. This is not true for 1128, 846, 1410.

    • amarovita Avatar

      If i return [] everytime first element is not smallest i get another error telling [] should be some not empty list.

      Nvm, solved.

    • PickCormac Avatar

      yes, you shouldnt make it so returning anything is dependent on if one triplet found is actually invalid. I believe your mistake is in making it return no valid triples based off the fact that one triple had a > b. I would reccomend making it so a!>b is a condition within the statement that checks if for a given value of a, if a is triplet so it doesnt add an invalid ( a>b triplet to the list in the first place). Unless i misunderstand your problem i think that is what needs a fix.

  • Wisdou Avatar

    C# translation has issue with big numbers

    • brodiemark Avatar

      Can you please provide an example? When I click on “View Solution I see Python code, so I can't tell a lot from that. The problem is only intended to deal with integers, so you don't have to return bigger numbers.

    • Wisdou Avatar

      It does not consider triangles with the length of A bigger than one million in random tests

    • brodiemark Avatar

      Thanks for noticing! I believe it is fixed (and in the Java version as well).

  • Blind4Basics Avatar

    Hi,

    • Inputs are 3,9,9, so output: [(9, 12, 15)] should equal [] => why?
    • in any case, the above tests should be present in the fixed tests (showed up as a single failure in the random tests)
    • you should put all the fixed tests in the sample tests.

    Cheers

    • dfhwze Avatar

      Why you removed your next comment? I also get the same answer [(9, 12, 15)] , so the ref sol is wrong, no?

    • Blind4Basics Avatar

      because I thought it was a ref solution, but it's an input generator, actually. I didn't investigate further (didn't want to). But it probably boils down to the very saame problem (an exclusive boudnary that should be inclusive). But again, I didn't check that is the actual problem.

    • brodiemark Avatar

      This is the same issue that Just4Coders identified last night. When I 'fixed' it then, I forgot that there are two sets of random tests (small and large inputs), and I only fixed one. I have now fixed both (and I ran 5,000 random tests in my IDE to check.)

      The fixed tests have the example (4, 100, 100) -> [(100,1248,1252)]), so they illustrate the correct behavior.

      Issue marked resolved by brodiemark 2 years ago
  • dfhwze Avatar

    You should specify the input range of arguments.

    • brodiemark Avatar

      Done.

      Question: Is it ever acceptable for a kata to have different input ranges for different languages? Or when you specify the input ranges for the first language, should you think ahead whether all translations will be able to cope with the same ranges?

      Suggestion marked resolved by brodiemark 2 years ago
    • dfhwze Avatar

      If you have performance criteria, the input range should be tweaked to fit those per language. In other cases, I would use the same range across languages.

    • dfhwze Avatar

      This comment has been hidden.

    • dfhwze Avatar

      Let's see how it goes when new translations get added. If each language gets its own range, perhaps it's better to specify the intended complexity (big O notation), rather than range of input.

  • Just4FunCoder Avatar

    This comment has been hidden.

    • brodiemark Avatar

      Wow, amazing catch! I must've run those 50 random tests 10 times without seeing that even once.

      I've removed the case num==0, since the only alternative I see is placing some duplicated code in the else near the end of generate_random_test. If anyone has a cleaner solution that keeps the case num==0 please let me know!

      I added the imports.

      Issue marked resolved by brodiemark 2 years ago