Problem of the Day
A new programming or logic puzzle every Mon-Fri

Integer Hash

Coming up with a quick hashing algorithms can prove super useful for many areas of programming. Today's goal is to create a function that takes in a string and returns an integer. The goal of the hashing function that you create is that it shouldn't have any collisions for the following dictionary.

If you run in to any issues post in the comments below for help.

Permalink: http://problemotd.com/problem/integer-hash/

Comments:

  • Anonymous - 8 years, 11 months ago

    python 2.7 ``` #hash a word

    def hash_a_word(word): letter_array = list(word)

    x = 0
    for letters in letter_array:
        letter_array [x] = ord(letters) % 100
        x = x + 1
    
    letter_array.append(len(word))
    
    hash = int(''.join(map(str,letter_array)))
    
    print hash
    

    reply permalink

Content curated by @MaxBurstein