7 kyu
BAD Hash - String to Int
108 of 259Bigg-T
Description:
Implement a function which takes a string, and returns its hash value.
Algorithm steps:
a
:= sum of the ascii values of the input charactersb
:= sum of every difference between the consecutive characters of the input (second char minus first char, third minus second, ...)c
:= (a
ORb
) AND ((NOTa
) shift left by 2 bits)d
:=c
XOR (32 * (total_number_of_spaces
+ 1))- return
d
Note: OR, AND, NOT, XOR are bitwise operations.
Examples
input = "a"
a = 97
b = 0
result = 64
input = "ca"
a = 196
b = -2
result = -820
Give an example why this hashing algorithm is bad?
Fundamentals
Similar Kata:
Stats:
Created | Jul 18, 2017 |
Published | Jul 18, 2017 |
Warriors Trained | 643 |
Total Skips | 39 |
Total Code Submissions | 1203 |
Total Times Completed | 259 |
C Completions | 108 |
NASM Completions | 9 |
Python Completions | 156 |
Total Stars | 11 |
% of votes with a positive feedback rating | 80% of 93 |
Total "Very Satisfied" Votes | 60 |
Total "Somewhat Satisfied" Votes | 28 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |