Questions tagged [sequence]
For challenges involving sequences, typically of numbers following some pattern.
977 questions
21
votes
17
answers
1k
views
A yet-unlisted sequence
I was looking for a simple sequence that's not yet referenced on the OEIS and came up with this one(*):
\$a_1=2\$
\$a_2=3\$
For \$n>2\$, \$a_n\$ is the smallest number of the form \$a_i\times a_j+...
15
votes
17
answers
2k
views
IMO 2025: Divisor sums that go forever
Problem 4 of the 2025 International Mathematical Olympiad asked (paraphrased):
Let \$f(n)\$ be the sum of the largest three proper divisors of \$n\$,
that is divisors excluding \$n\$ itself. For ...
-5
votes
4
answers
236
views
Locate \r\n\r\n in a HTTP/1.1 POST request
Given an HTTP/1.1 POST request represented as a buffer (e.g., Uint8Array; uint8_t) of bytes, ...
9
votes
4
answers
667
views
Triangular Transposition Cipher
A text that can be arranged triangularly in some fashion can be read back in some other fashion effectively enciphering it.
Narrowing down a set of plausible triangular numberings allows to ...
9
votes
2
answers
343
views
Putting the pieces together
In this code-golf challenge, you will count the number of ways of putting together pieces of a building toy which consists of slotted squares that interlock with one another, shown below. In ...
16
votes
17
answers
1k
views
Output the Echo Numbers
Echo numbers (A383896) are positive integers k such that the largest prime factor of k-1 is a suffix of ...
13
votes
18
answers
2k
views
Is it a product of 4 unique primes (A046386)?
A046386 is the sequence of all natural numbers that are the product of exactly 4 distinct primes.
Write the shortest program, function, or code snippet, that, when given a natural number, outputs ...
9
votes
1
answer
384
views
Ruler-and-compass constructions
In this code-golf challenge, you will work with a construction that was used by the ancient Greeks: the straightedge-and-compass construction. In particular, you will count how many different ...
9
votes
15
answers
1k
views
A121016: Numbers whose binary expansion is properly periodic. or A328594: Numbers whose binary expansion is aperiodic
I have been studying how to compress the Dis programs into their equvalent ones. One of the possibly easiest subset is programs with only } and ...
16
votes
17
answers
1k
views
Counting Gessel walks
OEIS A135404 gives the number of Gessel walks \$g(n)\$ of length \$2n\$. A Gessel walk is
a walk on the square lattice starting and ending at the origin
with possible steps (1,0), (-1,0), (1,1), (-1,-...
16
votes
12
answers
993
views
Repetition-restricted strings
Given an alphabet size, \$n>0\$, and an occurrence limit, \$k>0\$, produce the number, \$a(n, k)\$, of strings that may be constructed from the \$n\$ letters in the alphabet which have no more ...
17
votes
20
answers
2k
views
Number of legal positions in 1D go
A 1D go position on a board of size n is a sequence of length n consisting of the numbers0, <...
15
votes
9
answers
1k
views
How many chains?
Given a positive integer \$n\$, a partition of \$n\$ is an ascending sequence of numbers that sum to \$n\$.
Given two partitions \$a\$ and \$b\$, \$a\$ is a refinement of \$b\$ iff \$b\$ can be ...
13
votes
13
answers
2k
views
Meandering over ℤ
The easiest way to understand this task is to look at this
graph,
which you can change interactively.
It defines a sequence n -> a(n) like this:
a(0) = 0; thereafter a(n) is the least integer (in ...
14
votes
11
answers
1k
views
Counting Rota-Baxter words
A Rota-Baxter word, \$w\$, is a string made of the symbols a, (, and ) such that the ...
7
votes
7
answers
512
views
How many free polyominos without holes
Related CodeGolf posts
How many unique one sided polyominos
Enumeration of free polyominoes
Context
From Wikipedia:
A polyomino is a plane geometric figure formed by joining one or more equal ...
2
votes
11
answers
824
views
Climbing through the mountains on all paths
Narrative
We are standing at the foot of a mountain. To find the best route when climbing the mountain, let's consider all possible routes.
On our route, there is no point lower than our starting ...
15
votes
10
answers
2k
views
Walks in Nice (Nizza)
Narrative
Recently, I visited Nice (a French city on the Mediterranean coast) and saw a curious tourist wandering through the city. His walk started at the center of the 'Promenade des Anglais'. He ...
12
votes
6
answers
2k
views
Frogs on lily pads want to make a party
Consider binary strings (reading from left to right) starting with a '1' as ponds of lily pads. A '1' signifies a frog sitting on the lily pad, and a '0' represents an empty lily pad.
Here, we see a ...
7
votes
6
answers
408
views
Walks on a circle
A walk on a circle is a sequence of oriented arcs of equal length on a circle starting and ending at the same point. The endpoint of an arc is always the starting point of the next arc of the walk. ...
12
votes
10
answers
2k
views
Girls and boys parades
Donald Knuth describes the setup:
"There are \$n\$ girls \${g_1, ..., g_n}\$ and \$k\$ boys \${b_1, ..., b_k}\$,
where \$g_i\$ is younger than \$g_{i+1}\$ and \$b_j\$ is younger than
\$b_{j+1}\$, ...
17
votes
10
answers
2k
views
The smallest number with a given water capacity
This is the outline of this challenge: Every number greater than or equal to two has a prime factorization. A prime factorization can be represented as a bar graph. Every bar graph has a water ...
7
votes
2
answers
557
views
Count the possible folds of an n² grid
Update: 8x8 case from @gsitcia has finished! according to that code, there are 162,403,827,553,180,928 ways it could be folded. now to get it into the oeis...
Inspired by this recent video, I figured ...
11
votes
7
answers
2k
views
Perfect ruler search
Definitions:
A sparse ruler, or simply a ruler, is a strict increasing finite sequence of nonnegative integers starting from 0, called marks.
A ruler is complete if the set of all distances it can ...
8
votes
5
answers
434
views
Stackable and unstackable numbers
Consider boxes stacked on top of each other.
Boxes on the bottom row are labeled 1.
Boxes not on the bottom row must be supported directly below, and are labeled as the sum of the 2 or 3 boxes they ...
11
votes
13
answers
1k
views
Number of complete binary unordered tree-factorizations of n
For prime p, the factorization tree is a single vertex in just one way so that a(p) = 1.
For composite n, the two subtrees at n are a split of n into two factors n = d * (n/d), without order, so that
$...
7
votes
12
answers
816
views
Counting constrained permutations
Challenge:
Write a program or function that, given positive integers n, t, b, c, counts permutations of 1..n where:
Exactly t numbers are in their original position
Exactly b numbers are higher than ...
-1
votes
1
answer
191
views
Golomb's self-describing sequence problem [duplicate]
Inspired by this problem.
Golomb's self-describing sequence g(n) is a sequence where any natural number n is repeated within the sequence g(n) times.
Given an input of \$ n \$, output: $$ \left( \sum_{...
7
votes
8
answers
439
views
Padé approximant of \$\exp(x)\$
In mathematics, a Padé approximant (Wikipedia, MathWorld) is the "best" approximation of a function by a rational function. For a function \$f(x)\$, the Padé approximant of order \$[m/n]\$ ...
7
votes
6
answers
451
views
Fractions nobody needs (because they can be reduced to a simpler form)
It happened in the 19th century. Georg was bored and started counting the rational numbers. Surprisingly, he discovered that there were no more of them than natural numbers. This insight made Georg ...
18
votes
11
answers
2k
views
Count squares in my pi approximation
One way to approximate π is the following: Start by drawing a 2x2 square with a quarter-circle in it. Then, the area of the quarter-circle is π.
We can approximate this area by filling it with ...
11
votes
10
answers
2k
views
Smallest prime q such that concatenation (p+q)"q is a prime
Let p, q, and c := (p + q)"q (where " denotes concatenation) be positive integers such that p and c are primes and q is the smallest prime such that c is prime.
Such a prime triple (p, q, (p ...
8
votes
6
answers
1k
views
Pólya trees counted efficiently
The number of unlabeled rooted trees with n nodes is a fundamental sequence in graph theory and in discrete mathematics in general.
Some authors call these trees 'Polya trees'. The number of these ...
15
votes
10
answers
1k
views
Sylvester primes
Sylvester's sequence can be defined recursively S(n) = S(n-1)*(S(n-1) + 1) for n >= 1 starting S(0) = 1.
Since S(n) and S(n) + 1 have no common divisors, it follows that S(n) has at least one more ...
15
votes
15
answers
2k
views
Sums of X*Y chunks of the nonnegative integers
Consider the infinite table of the nonnegative integers with width 12:
...
20
votes
21
answers
1k
views
Rabinowitz-Wagon \$\pi\$ formula
In 1995, Stanley Rabinowitz and Stan Wagon found an interesting algorithm to generate the digits of \$\pi\$ one by one without storing the previous results. The algorithm is called the spigot ...
2
votes
3
answers
343
views
Non-Decreasing Fibonacci Sequence modulo M
Given integers \$a,b,m, k, n\$ and array \$F = (f_1, f_2,...,f_n)\$ defined as:
\begin{cases}
f_1 = \text{a}\\
f_2 = \text{b}\\
f_i = (f_{i-1} + f_{i-2}) \text{ mod m},∀i > 2
\end{cases}
When \$F\$ ...
14
votes
5
answers
541
views
Generate a subgroup of a free group
In group theory, the free group with \$n\$ generators can be obtained by taking \$n\$ distinct symbols (let's call them \$a, b, c ...\$ etc), along with their inverses \$ a^{-1},b^{-1},c^{-1} ...\$ . ...
18
votes
28
answers
2k
views
Smallest Harmonic number greater than N
The sequence of Harmonic numbers are the sums of the reciprocals of the first k natural numbers (not including zero):
\${\displaystyle H_{k}=1+{\frac {1}{2}}+{\frac {1}{3}}+\cdots +{\frac {1}{k}}=\sum ...
20
votes
23
answers
2k
views
Output the inventory sequence
Goal
Write a program that outputs this list:
...
15
votes
2
answers
463
views
Where are zeros? Self-describing sequence
Background
A167519: Lexicographically earliest increasing sequence which lists the positions of the zero digits in the sequence.
...
16
votes
6
answers
1k
views
Golfing the complexity with subtraction
The Mahler-Popken complexity, \$C(N)\$, of a positive integer, \$N\$, is the smallest number of ones (\$1\$) that can be used to form \$N\$ in a mathematical expression using only the integer* \$1\$ ...
14
votes
13
answers
1k
views
*Trivial* near-repdigit perfect powers
Task
Output the sequence that precisely consists of the following integers in increasing order:
the 2nd and higher powers of 10 (\$10^i\$ where \$i \ge 2\$),
the squares of powers of 10 times 2 or 3 (...
14
votes
10
answers
1k
views
Enumerate all matches of a regex
related
For this challenge, we'll be using a simplified dialect of regular expressions, where:
A lowercase letter from a to z ...
11
votes
4
answers
2k
views
Output a 1-2-3-5-7... sequence
Follow-up of my previous challenge, inspired by @emanresu A's question, and proven possible by @att (Mathematica solution linked)
For the purposes of this challenge, a 1-2-3-5-7... sequence is an ...
22
votes
15
answers
2k
views
Output a 1-2-3 sequence
For the purposes of this challenge, a 1-2-3 sequence is an infinite sequence of increasing positive integers such that for any positive integer \$n\$, exactly one of \$n, 2n,\$ and \$3n\$ appears in ...
13
votes
12
answers
2k
views
Odds for second smallest prime factor
Given a prime number \$p\$ output the asymptotic density of the set of positive integers which have \$p\$ as their second-smallest distinct prime factor
Input/Output
Input: one of the following ...
2
votes
3
answers
258
views
Rank poker High Card hands [closed]
In the poker game there are 1277 unique 'High Card' ranks. It's 1287 (13 over 5) if we include all straights.
The challenge is to write a function which returns an integer value corresponding to the ...
14
votes
7
answers
2k
views
How quickly can you type this unary string?
If I want to type the string aaa, the least keystrokes I can type it in is 3: a a a. But if I want to type the string ...
15
votes
16
answers
1k
views
Pretty Palintiples
Imagine you have a positive integer number \$n\$. Let \$m\$ be the number obtained by reversing \$n\$'s digits. If \$m\$ is a whole multiple of \$n\$, then \$n\$ is said to be a reverse divisible ...