Command Palette

Search for a command to run...

Hectal
Phase 4: Ingestion: From Files to Searchable Chunks
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

  1. The hash of the empty text is the starting value
  2. The hash of a is e40c292c
  3. The hash stays within 32 bits
  4. Case, spacing and punctuation do not hide a duplicate
  5. Different texts are not duplicates
  6. 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.