Questions tagged [pattern-matching]

For questions about pattern matching in computer science, which is the act of checking a given sequence of tokens for the presence of the constituents of some pattern.

In computer science, pattern matching is the act of checking a given sequence of tokens for the presence of the constituents of some pattern. In contrast to pattern recognition, the match usually has to be exact: "either it will or will not be a match." The patterns generally have the form of either sequences or tree structures. Uses of pattern matching include outputting the locations (if any) of a pattern within a token sequence, to output some component of the matched pattern, and to substitute the matching pattern with some other token sequence (i.e., search and replace).

61 questions
9
votes
1 answer

Avoiding exactly one permutation pattern

Let $n \geq k$. We say that a permutation $\sigma \in S_n$ contains a permutation (or "pattern") $\tau \in S_k$ if there is a substring of $k$ (not necessarily consecutive) elements of $\sigma$ ordered like $\tau$. For example, the permutation…
5
votes
2 answers

An analogue to OEIS for graphs and ordered pairs?

Does anyone know if such a thing exists already? I was able to find a number of seemingly very comprehensive encyclopedia-like reference pages on many species of graphs, but it seemed that the use case and spirit behind these pages differed from the…
5
votes
1 answer

Find the $n$'th integer composition with a fixed number of components in lexicographical order

lets there is a number (N) and partitions (p), I have all the possible combinations, each combination sums to N. I want to calculate the nth term of these sequences/ combinations given N and p. N = 7, p = 3 1: 1,1,5 2: 1,2,4 3: 1,3,3 4: 1,4,2 5:…
4
votes
1 answer

NON-martingale approach to ABRACADABRA problem

The well-known ABRACADABRA problem states (see D. Williams, "Probability with martingales", for example): a monkey is typing letters A-Z randomly and independently of each other, each letter with probability $1/26$. What is the expected amount…
4
votes
4 answers

Special palindromic pattern of $(\frac{10^n-1}{9})^2$

I noticed a repetitive, palindromic pattern when I've performed exponentiation with $10$. That is: $$(\frac{10^n-1}{9})^2 \text{ has a palindromic pattern, }\forall\:n\in [1;9]\:(n\in \mathbb{N})$$ We define $f(n)=(\frac{10^n-1}{9})^2$. $f(1) =…
3
votes
2 answers

Finding a pattern, I'm stuck

I have a friend who knows how much I love math, (I imagine new problems just to do the math behind them and to see if I can expand my understanding) and so he brings me the stuff that stumps him. Usually I end up finding the answer for him and then…
3
votes
1 answer

Quantify the similarity between two patterns formed by two sets of spatial locations

Suppose I have two sets of spatial locations $X$ and $Y$ on the plane, each with $n$ locations. The coordinates are $X=\{(x_1, y_1), \dots, (x_n, y_n)\}$ and $Y=\{(u_1, v_1), \dots, (u_n, v_n)\}$. I want to find a quantity representing the…
JACKY88
  • 3,613
2
votes
0 answers

Is it possible to find a short function for a table of points where the result of the function is always -1, 0 or 1?

For context, I am trying to solve a Code golf problem, where you need to solve a problem with a program, where the program with the shortest source code wins. There is a pretty hard problem on there where you have to map Unicode arrows like ↖⇒↳ etc.…
2
votes
1 answer

How do we find the number of sub-intervals whose intersection with the subset of the entire interval is non-empty?

Suppose we have set $A=\left\{\frac{1}{k}:k\in\mathbb{N}\right\}$ and we divide interval $[0,1]$ into $n$ sub-intervals of equal length. How do we find the exact forumula (or approximation) of the number sub-intervals $f(n)$ whose intersection with…
2
votes
1 answer

Distributing Series/Patterns

I'm going to do my best to explain this question, but it's complicated. Please bear with me. I'm trying to solve a practical problem and I know that the answer involves some math, but I can't for the life of me figure it out. You've got a series of…
2
votes
2 answers

Pattern in Sequence of Polynomials

I generate these polynomials from a counting experiment. There are some obvious patterns i.e the order of $f(n)$ is $n(n+1)/2$. Also, each $f(n)$ has repeated binomial coefficeints corresponding to ${(n+1)\choose k}$ , but each coefficient is…
2
votes
1 answer

Number of possible unique patterns of $5$ points on an $8\times 8$ grid.

I'm after a specific answer and workings/formula for the number of possible unique patterns that $5$ points can have on an $8\times 8$ grid. The pattern must be unique and not match another pattern when it's rotated or mirrored. Can the workings be…
Andre
  • 21
2
votes
1 answer

Getting a specific element of a non-recursive sequence

I have a sequence, starting with $1$. You store the current sequence as a list, then duplicate it. In this copy, you invert it, turning $1$s into $0$s, and $0$s into $1$s. Then, you join it on to the first sequence.* So it goes: $$1, 0, 0, 1, 0, 1,…
2
votes
0 answers

Probability of matrix equality under modulo (pattern matching)

Probabilistic pattern matching with matrices works like this: For two given strings, $x,y$ where $x\in\{0,1\}^n$ and $y\in\{0,1\}^m$ and $n\ge m$, we want to find the occurrences of $y$ in $x$. If we describe the $0$ digit as the matrix…
2
votes
0 answers

Matching the position of points in 2D space

Considering there is a 2-dimensional array $A$ consisting of point coordinates in two dimension space (as shown in image). There is another array 2-dimension array $B$ also representing the position of points in similar fashion as that of $A$. $B$…
1
2 3 4 5