I would first try to make the code look as simple as possible (from the point of view of a pattern matching algorithm. Not a human). For example, why have all kind of whitespace instead of just one, a newline say (EDIT: or none at all)? You can compress the code a bit by replacing repeated, small chunks of it with a word from compression-vocabulary. So that pattern matchings can be faster. For example ActiveSheet.Cells can become _ASC_.

If there was a VBA-to-bytecode, it could be used instead of the above (perhaps). (EDIT: no, unless you can convert it back to VBA code.)

After that, your task may be similar to DNA matching. And there exist efficient algorithms (implemented) for doing that and spotting common sections between 2 DNA sequences. See Boyer–Moore_string-search_algorithm. And also this for more food for thought: https://www.hindawi.com/journals/bmri/2019/7074387/

Of course there are linguistic approaches to this too (but code is NOT human-text): https://www.baeldung.com/cs/ml-similarities-in-text and https://towardsdatascience.com/the-best-document-similarity-algorithm-in-2020-a-beginners-guide-a01b9ef8cf05 will give you ideas.

bw, bliako


In reply to Re: [OT] Finding similar program code by bliako
in thread [OT] Finding similar program code by afoken

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.