[ Deduplication ] Programming Exercise

If it is about keeping non-duplicate thing in an array, you can try and spin this into a collection for rarity sort of thing, like card or stamps.
Anything has duplication is not that rare.

4 Likes

Hapax Legomena

Elias Thorpe closed his dictionary. As a writer and student of words, he hoped his book on rare words – words that appear only once in a text – would please people as much as it pleased him. He had found these words over the years, like indexy in Bram Stoker’s Dracula but now his eyes were getting weaker.

“I think we love these words for being outliers.” said Elias.

Help Elias save his eyesight by finding these words quicker.

Example Exercise

Given the following sentance:

To be or not to be

then the words that occur but once are:

or not

We look at sentences case insensitively and preserve original word order. Note that we consider “To” and “to” as the same here.

2 Likes

That framing work for me. We’re explaining why Elias needs to deduplicate the original texts, and the intro implies that the word order is important so the readers can compare his results to the original texts.

My only nitpick is that you probably want to define corpus here as well. Something like words that occur only once within a text is clear and to the point without needing elaboration.

Edit - "The" and "the" might warrant an explicit note that we’re comparing words case-insensitively. Similarly, the input sentence has a period so we may want to tell the students to ignore punctuation. We could just leave out punctuation in the test cases to make this easier though.

1 Like

I like the story! It might benefit from using simpler words, though. Unusual and multi-syllabic words are less friendly to all the users less familiar with English.

2 Likes

I changed corpus in an edit above – thanks for the suggestion @BNAndras .
No bother, I think we should add a note about matching without case.
I think we should probably remove punctuation as this puts too much focus elsewhere than on solving the core part.

1 Like

The nice thing about handling sentences is that the parsing/matching is simple. Either the string matches or it doesn’t. When it comes to words, you start worrying about stripping punctuation and fixing cases. That makes me thing of acronym.

1 Like

I simplified the language and added “indexy” from Dracula as an example.

2 Likes

I like the story. Since it is very explicitly about words, we should probably use only letters (no punctuation, digits, etc). Space might be the separator in the input string (or maybe the input should be a list of words).

2 Likes

I lean towards input as a list of words to draw more attention to the core task.

I’d be interested if you think it would benefit extending hapax to include dis, tris and tretrakis legomenon – words that have double, triple, or quadruple occurrences?

How would that work? Would the expected number of occurrences be passed as a second parameter to the function?