Sort by

recency

|

1822 Discussions

|

  • + 0 comments

    The issue in the problem arises because Python 3.3 and above introduced hash randomization for security, which means the hash() of the same tuple can vary between runs and machines, whereas in Python 2 the hash() output for the same tuple is fixed and predictable. The HackerRank problem expects a specific deterministic hash value (3713081631934410656) for the tuple (1, 2), which aligns with Python 2 behavior. Therefore, running the code in Python 3 on your machine gives a different result because of the randomization, but switching to Python 2, where hash() is consistent, produces the expected output and passes the judge. This is why using Python 2 helps solve the problem correctly.

    This is my code and if you are using it too change the python 3 to python2 first from the menu above the shell

    if __name__ == '__main__':
        n = int(raw_input())
        integer_list = map(int, raw_input().split())
        t = tuple(integer_list)
        print hash(t)
    
  • + 0 comments

    I had to switch the language to python 2 and use raw_input() instead of input() to get it to work. It seems that the hash function works differently in python 3 than it did in python 2, which is likely the version of python this challenge was written for. HackerRank really needs to update this challenge for python 3!

    This is my python 2 code I used:

    # read the count (not really used except to know how many)
    n = int(raw_input())
    
    # read the line of numbers as text, split on spaces, map to int, pack into a tuple
    elements = tuple(map(int, raw_input().split()))
    
    # compute and print the hash
    print hash(elements)
    

    compute and print the hash

    print hash(elements)

  • + 0 comments

    Here is - Javascript project for students

  • + 0 comments

    For some reason, Python 3 throws wrong answer. It generates correct answer with Python 2.
    if name == 'main':
    n = int(input())
    t = tuple(map(int, input().split()))
    print(hash(t))

    our Output (stdout)
    -3550055125485641917 `

  • + 2 comments

    I Didn't understand how to use the hash() please explain