RAG and Vector Search · Exercise 6 of 6 Previous
Intermediate
Hash by hand and find exact duplicates
Write fnv1a(text) returning the 32-bit FNV-1a hash of the text as an integer: start with h = 2166136261; for each character, h = ((h ^ ord(ch)) * 16777619) & 0xFFFFFFFF.
Write duplicates(texts) that returns a list of (index, first_index) pairs for every text that is an exact duplicate of an earlier one after normalising: lower-case, words only (runs of letters and digits), joined by single spaces. Compare normalised hashes.
What Check tests
- The hash of the empty text is the starting value
- The hash of a is e40c292c
- The hash stays within 32 bits
- Case, spacing and punctuation do not hide a duplicate
- Different texts are not duplicates
- Every later copy points at the first one
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.