Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.5K Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Recognize number string patterns?

Posted 7 years ago
POSTED BY: Robert Marks
2 Replies
Posted 7 years ago

I discuss this problem in details in the following post:

POSTED BY: Alexey Popkov

Ok, here's one attempt. This function looks for patterns (with specified minimum an maximum length) repeated a minimum/maximum number of times:

findRepeatedPatterns[
   string_String,
   minMaxSequenceLength_List,
   minMaxRepititions_List
   ] := findRepeatedPatterns[
   Characters@string,
   minMaxSequenceLength,
   minMaxRepititions
];
findRepeatedPatterns[
  list_List,
  minMaxSequenceLength_List,
  minMaxRepititions_List
] := DeleteDuplicates[
  ReplaceList[
   list,
   {
     Repeated[
      PatternSequence[___, x : Repeated[_, minMaxSequenceLength], ___],
      minMaxRepititions
     ]
   } :> {x}
  ]
];

Look for patterns of at least length 3 repeated at least 3 times:

findRepeatedPatterns["01100110011020110", {3, \[Infinity]}, {3, \[Infinity]}]
Out[2] = {{"0", "1", "1"}, {"0", "1", "1", "0"}, {"1", "1", "0"}}
POSTED BY: Sjoerd Smit
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard