Ad
  • Custom User Avatar

    'All triangles will be right isoceles.' from the Kata description.

    Nice extension to a general scenario though.

  • Default User Avatar

    In short, importing the sqrt certainly doesn't benefit from being in the function. :P

  • Default User Avatar

    Interestingly, the site groups code that imports outside the function with code that imports inside the function. Check the variations and you'll see. It just happened to choose the one with the import inside as the canonical version for some reason.

    For the most part, you are right. PEP 8 recommends only importing at the top of a file. Doing otherwise makes debugging much harder. However, technically there might be very rare situations where you might want to import inside of a function -- if only that function ever needs that module, the function is rarely or never called, and you don't want to pollute the global namespace, or if you want to defer and handle ImportError exceptions on a case-by-case basis, or you want to do some sort of conditional import depending on the passed parameters. Some others say they use it to resolve circular dependency issues, but that can almost always be avoided with a little restructuring of the affected files without the overhead a local import would involve.

  • Default User Avatar

    you wouldn't import inside a function.

  • Custom User Avatar

    This assumes that the triangle is isoceles, which might not be the case.
    All tests are but maybe we could have a triange like:

    .
    . . .
    

    Which would result in area of "1" but this solution does not.

  • Default User Avatar

    I believe there is an issue with the card on the fixed test for Python. My code passed all the random tests, but I would get an index error on the fixed tests. I entered this at the top of my code and everything passed:

    if len(card) != 6:
        card = [['B', 'I', 'N', 'G', 'O'],
                [1, 16, 31, 46, 61],
                [3, 18, 33, 48, 63],
                [5, 20, 'FREE SPACE', 50, 65],
                [7, 22, 37, 52, 67],
                [9, 24, 39, 54, 69]]
    
  • Default User Avatar

    i dont thik there is better solution then this one

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Question: My code (python) passes all the 100 "correctness" tests but times out during the 100 "performance" tests. I'm using numpy to count all the nxn subarrarys that have only 1's and storing the results in a dictionary. When there are less than 4 nxn arrays with only 1's, my program returns the result. I can't see how my solution can be optimized without doing some sort of mathematical approach to narrow down the subarrays that need checking. Is a mathematical approach necessary? Any suggestions would be greatly appreciated.

  • Default User Avatar

    This is because you are trying to do the calculation of 'd' within the loop- you have to do it after 'a' has been populated completely.
    Also, you have a typo when checking for v==8, a[i] == ...

  • Default User Avatar

    I have the same question. If the input is the PIN number as a string, then my code should work.

  • Default User Avatar

    I had the same issue. I was calculating based on the largest. Good question and explnation.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Thanks so much for the reply. I got it to work. The fact that someone like you would respond so quickly to someone so new at coding is why I love this community.

  • Default User Avatar

    You can google "Python truncate to decimal places". I think the easy way to truncate is to take the int of "...". I am sure you will find what to put instead of "...".

  • Loading more items...