Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Finding Nearly Identical Sets

by Limbic~Region (Chancellor)
on Sep 28, 2016 at 18:36 UTC ( [id://1172857] : note . print w/replies, xml ) Need Help??

in reply to Re: Finding Nearly Identical Sets
in thread Finding Nearly Identical Sets

If it helps, you don't have to think of them as sets but as strings or numbers (driver's license, passport, employee ID, etc.) with the understanding that they are expected to not contain zero anywhere and should be a length of 9.

For instance, let's say the program has '198472385'

  1. Is it less than 8 characters long? If yes, abort
  2. Is it more than 10 characters long? If yes, abort
  3. Has this "thing" already been seen? If yes, we are done
  4. Has a variation of this thing been seen (same digits but in a different order)? If yes, we are done
  5. Are there any other "things" nearly identical to this one regardless of the order of the digits (can I transform this "thing" into a previously seen "thing" with exactly one operation (insert, delete, transform))? If yes, which ones?

Items 1 - 4 are obviously trivial. I don't even need to be perfect with number 5 though that would make me happy. I am trying to find a way to quickly/cheaply find candidates to number 5.

One way to do it would be just to have a bunch of indices. For instance, for "a single digit has been transformed".

  1. When storing - sort the set
  2. For each of the 9 possible positions that could be changed in the future, assume each one was in fact changed and remove that character and concatenate the remaining 8 characters into an index/hash
  3. When checking candidates, duplicate the process above checking all 9 indices for an exact match
The above scenario would work perfectly for transforms but requires you to maintain 9 different indices and the searches are ugly.

Cheers - L~R