All problems
Hash Chain Steps
Problem
Apply the linear congruential hash h(x) = (x * 1103515245 + 12345) mod 2^31 exactly `steps` times to the starting value and return the result. Hash chains like this underpin one-time passwords.
Hint
Zero steps returns the starting value unchanged.
Test cases
case 1
in: [0,1]
expected: 12345
case 2
in: [1,0]
expected: 1
case 3
in: [1,1]
expected: 1103527590
case 4
in: [0,2]
expected: 1406932606
case 5
in: [12345,3]
expected: 1449466924
Starter codePython
def hash_chain(start, steps):
# Your code here
pass5 test cases · run your code against them in the editor