Document fingerprint anchors
Your task
A duplicate finder fingerprints a document rather than keeping it whole. It cuts the document into grams, a gram being the run of gram_len characters starting at each position, so the gram at position i begins at index i. It folds each gram to a number: start at 0 and for every character of the gram set h to (h * 31 plus the ASCII code of that character) modulo 1000003. It then slides a window over the list of gram numbers, window_len numbers wide, and from each window it anchors the position of the smallest number, breaking a tie by taking the rightmost of the tied positions. Given document, gram_len and window_len, return the anchored positions, each listed once, ascending. Return an empty list when either length is zero or negative, when gram_len is longer than the document, or when there are fewer gram numbers than window_len.
Examples
winnow_anchor_positions(document: str, gram_len: int, window_len: int) -> list[int]winnow_anchor_positions("abcabcabc", 3, 2)[0, 1, 3, 4, 6]winnow_anchor_positions("aaaa", 1, 2)[1, 2, 3]winnow_anchor_positions("abcd", 1, 1)[0, 1, 2, 3]