Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-313

Fletcher Checksum

Problem

Compute the Fletcher-16 checksum of a string: keep two running sums modulo 255, adding each character code to the first sum and then the first sum to the second, and return the second sum shifted left eight bits plus the first.

This detects both single-bit errors and many transpositions. The empty string gives 0.

Hint

The second sum accumulates the running value of the first, which makes order matter.

Test cases

case 1
in: [""]
expected: 0
case 2
in: ["a"]
expected: 24929
case 3
in: ["abc"]
expected: 19495
case 4
in: ["hello"]
expected: 11542
case 5
in: ["ABC"]
expected: 35782
Starter codePython
def fletcher_checksum(data):
    # Your code here
    pass

5 test cases · run your code against them in the editor