Questions tagged [sequence]

For challenges involving sequences, typically of numbers following some pattern.

Filter by
Sorted by
Tagged with
11 votes
18 answers
491 views

Count the number of compositions of \$n\$ in which the greatest part is odd

A composition of an integer \$n\$ is a representation of \$n\$ as a sum of positive integers. For example the eight compositions of 4 are as follows: ...
  • 1,101
15 votes
28 answers
2k views

Calculating Pi using the Gregory Leibniz series until n terms

based off my previous challenge, this wikipedia article, and a Scratch project Your task: given i, calculate \$\pi\$ till i ...
20 votes
16 answers
2k views

Calculate Pi unto a point using the Nilakantha series

Your task: given a nonzero positive number i, calculate pi using the Nilakantha series unto i terms. The Nilakantha series is as ...
14 votes
10 answers
1k views

IMO Question Six with a difference

In 1988, the International Mathematical Olympiad (IMO) featured this as its final question, Question Six: Let \$a\$ and \$b\$ be positive integers such that \$ab + 1\$ divides \$a^2 + b^2\$. Show ...
-2 votes
3 answers
157 views

Find the GCD and LCM of a list of numbers [duplicate]

Note: most of the questions that are already in existence about this topic only deal with two numbers as inputs. This question deals with any number (>1) of inputs. GCD The GCD (greatest common ...
15 votes
14 answers
4k views

The "Fly straight, dammit" sequence

Background "Fly straight, dammit" (OEIS A133058) is a sequence of integers, which has these rules: \$a_0 = a_1 = 1\$ \$a_n = a_{n-1}+n+1\$ if \$gcd(a_{n-1}, n) = 1\$ Otherwise, \$a_n = \...
6 votes
13 answers
1k views

Number of ways to make an amount with coins

This is not a duplicate of Sum of combinations with repetition. This question considers 1+2 to be the same as 2+1. The other ...
11 votes
18 answers
1k views

Find the nth Mersenne Prime

A number is a Mersenne Prime if it is both prime and can be written in the form 2m-1, where m is a positive integer. For example: 7 is a Mersenne Prime because it is 23-1 11 is not a Mersenne Prime ...
12 votes
12 answers
333 views

Runs of Ones (What Fun!) [duplicate]

Suppose you have an array with some known set of values (e.g. a string of \$0\$ and \$1\$) and you want to get all the locations of \$1\$s. Instead of storing a list of all the indices, if the \$1\$s ...
13 votes
6 answers
798 views

Exponential transform of an integer sequence

The exponential generating function (e.g.f.) of a sequence \$a_n\$ is defined as the formal power series \$f(x) = \sum_{n=0}^{\infty} \frac{a_n}{n!} x^n\$. When \$a_0 = 0\$, we can apply the ...
  • 37.5k
19 votes
15 answers
2k views

Infinite quote escaping sequence

Related We start with the string a, and forever append to the string a comma followed by the string quote-escaped, where quote-escaping means doubling all quotes in ...
12 votes
16 answers
2k views

Squash it ... again!

If you place the positive integers together and read each set of two adjacent digits at the same time, you get: (A136414) ...
  • 4,871
16 votes
14 answers
926 views

Number of binary partitions

We all know that any positive integer can be represented as the sum of powers of two. This is how binary representations work. However there's not just one way to do this. The canonical method, ...
  • 90.4k
18 votes
16 answers
2k views

Fibonacci polynomials

The Fibonacci polynomials are a polynomial sequence defined as: \$F_0(x) = 0\$ \$F_1(x) = 1\$ \$F_n(x) = x F_{n-1}(x) + F_{n-2}(x)\$ The first few Fibonacci polynomials are: \$F_0(x) = 0\$ \$F_1(x) ...
  • 37.5k
17 votes
13 answers
1k views

Enumerate all pure sets

In set theory, a set is an unordered group of unique elements. A pure set is either the empty set \$\{\}\$ or a set containing only pure sets, like \$\{\{\},\{\{\}\}\}\$. Your challenge is to write a ...
  • 31.9k
17 votes
15 answers
2k views

Concatenatable numbers

Given a list of positive integers such as [69, 420], your challenge is to generate the sequence of numbers that can be formed by concatenating numbers from the ...
  • 31.9k
15 votes
13 answers
773 views

Count alternating permutations

An alternating permutation is a permutation of the first \$ n \$ integers \$ \{ 1 ... n \} \$, such that adjacent pairs of values in the permutation alternate between increasing and decreasing (or ...
  • 22.6k
18 votes
13 answers
2k views

Straighten my corners... diagonally

We can arrange the positive integers like this: 1_| 2 | 5 | 10 4___3_| 6 | 11 9___8___7_| 12 16 15 14 13 That is, in L-shaped brackets expanding down and right ...
  • 31.9k
7 votes
24 answers
2k views

Find the nth Fibonacci number, where n is the mth Fibonacci number

Introduction If \$\newcommand{\fib}{\operatorname{fib}}\fib(x)\$ calculates the \$x\$th Fibonacci number, write a program that calculates \$\fib(\fib(m))\$ for any integer value of \$m \ge 0\$. (Of ...
  • 195
6 votes
1 answer
567 views

Irradiated Polyglots

Design a function or program that, when run normally, outputs the triangular numbers. However, when any single character is deleted, the program/function should not function in the original ...
  • 1,306
4 votes
18 answers
2k views

Palindromic Powers

Powers We define an important power as a number that can be represented as \$ x^y \$ where \$ x ≥ 2 \$ and \$ y ≥ 2 \$. Palindrome We define an ...
12 votes
17 answers
2k views

Infinite Candle Sequence

I have a cake shop that specialises in birthday cakes. The cakes that I sell must have candles placed in a circle. You would probably think I can just divide 360° by the number of candles, but the ...
22 votes
9 answers
973 views

Sequence of integers not the sum of powers of earlier terms

Starting with 1, output the sequence of integers which cannot be represented as the sum of powers of earlier terms. Each previous term can be used at most once, and the exponents must be non-negative ...
  • 420
15 votes
24 answers
2k views

The Binary Eyes

A binary eye is an odd set of digits, with all of its digits except the center one set to 1 or 0, and the center one set to the opposite of the others. Thus, there are two binary eyes for a given odd ...
  • 420
18 votes
15 answers
3k views

Join my exclusive friendly club!

Two or more positive integers are said to be "friendly" if they have the same "abundancy". The abundancy of an positive integer \$n\$ is defined as $$\frac {\sigma(n)} n,$$ where \$...
22 votes
12 answers
2k views

How many Sieve of Eratosthenes hits?

Sieve of Eratosthenes is a method for finding prime numbers: take the sequence of all positive integer numbers starting from 2 then for each remaining number drop all its multiples. ...
  • 9,856
10 votes
7 answers
299 views

Maximum population of a \$n \times n\$ still life in Conway's Game of Life

This is OEIS sequence A055397. In Conway's Game of life, a still life is a pattern that does not change over time. We can see from the rules of Conway's Game of life that, a pattern is a still life if ...
  • 37.5k
10 votes
11 answers
1k views

Smallest numbers whose square has even number of digits

...
  • 9,856
18 votes
15 answers
1k views

Long period primes

A long period prime is a prime number \$p\$ such that decimal expansion of \$1/p\$ has period of length \$(p-1)\$. Your task is to output this number sequence. For purposes of this challenge we will ...
  • 12.3k
22 votes
17 answers
990 views

Pairs of integers ordered by their exponentiation

Output the infinite list of pairs of integers (a, b), where both \$ a > 1 \$ and \$ b > 1 \$, ordered by the value of \$ a^b \$. When there are multiple pairs ...
  • 22.6k
29 votes
16 answers
2k views

How-many-bonacci-like is this sequence?

Inspired by @emanresu A's Is it a fibonacci-like sequence? Make sure to upvote that challenge as well! We say a sequence is Fibonacci-like, if, starting from the third term (\$1\$-indexed), each term ...
  • 37.5k
16 votes
26 answers
1k views

Sum of the first n elements of the sequence of 9's complement

Let's consider the following sequence: $$9,8,7,6,5,4,3,2,1,0,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71...$$ This is the sequence of \$9\$'s complement of a number: that is, \$ a(x) = 10^...
  • 1,805
14 votes
15 answers
1k views

How many blocks make a "truncated square-pyramid garden"?

A truncated square-pyramid of height \$h\$ has \$h\$ square layers where each layer has a side \$1\$ greater than the one above it, apart from the top layer which is a square of blocks with a given ...
12 votes
8 answers
801 views

All sequences as substrings

Make a program that outputs a sequence of integers so that every finite sequence of positive integers is a substring (continuous subsequence) of the output. For example, the following sequence ...
  • 6,775
16 votes
4 answers
578 views

Probability breaking sequences

If we have a finite list of elements we can determine the probability of any one element being drawn at random as the number of times it occurs divided by the total number of elements in the list. For ...
  • 90.4k
16 votes
13 answers
1k views

Square-free words of a length

A square-free word is a word consisting of arbitrary symbols where the pattern \$XX\$ (for an arbitrary non-empty word \$X\$) does not appear. This pattern is termed a "square". For example, ...
21 votes
13 answers
2k views

Output every sublist ... eventually

You will be given as input an infinite stream of positive integers. Your task is to write a program which outputs an infinite sequence of lists with two requirements: All lists in the output are ...
  • 90.4k
9 votes
1 answer
346 views

Universal Command Sequence

Universal Command Sequence Definition An \$n\$-maze is a \$n\times n\$ chessboard which has "walls" on some edges, and a "king" on the board that can move to the 4 adjacent cells, ...
6 votes
10 answers
772 views

Generate Fmbalbuena Numbers

My user id is 106959 How to check if the number is Fmbalbuena number? First Step: Check if the number of digits is a multiple of 3: ...
  • 2,555
18 votes
16 answers
1k views

Slater-Velez permutation

Let's build a sequence of positive integers. The rule will be that the next number will be the smallest number which: It hasn't already appeared in the sequence Its absolute difference from the ...
  • 90.4k
-6 votes
4 answers
152 views

Indices of square numbers that are also pentagonal [closed]

First 15 numbers of the A046173: ...
  • 3,049
17 votes
6 answers
751 views

Mutually recursive lists

Let's define a simple function \$f\$ which takes an integer and produces a list: \$ f(n) = [g(1),g(2),\dots,g(n)] \\ g(n) = [f(0),f(1),\dots,f(n-1)] \$ We can then calculate the first couple of values ...
  • 90.4k
23 votes
27 answers
2k views

Next Greater Number

Given an integer n, find the next number that follows the following requirements The next greater number is a number where each digit, from left to right, is ...
  • 3,049
16 votes
13 answers
1k views

Number of complete rhyme schemes

A rhyme scheme is the pattern of rhymes at the end of the lines in a poem. They are typically represented using letters, like ABAB. We consider two rhyme schemes ...
  • 22.6k
18 votes
2 answers
633 views

Counting universal n-ary logic gates

Background A classical logic gate is an idealized electronic device implementing a Boolean function, i.e. one that takes a certain number of Boolean inputs and outputs a Boolean. We only consider two-...
  • 66.1k
29 votes
20 answers
2k views

An ASCII self-referential sequence

The sequence A109648 starts with the following numbers ...
  • 66.1k
12 votes
7 answers
221 views

Multiplicity of Shared Totients

Euler's totient function, \$\varphi(n)\$, counts the number of integers \$1 \le k \le n\$ such that \$\gcd(k, n) = 1\$. For example, \$\varphi(9) = 6\$ as \$1,2,4,5,7,8\$ are all coprime to \$9\$. ...
14 votes
4 answers
471 views

The Most Wanted Prime Numbers

Output a sequence of all the primes that are of the following form: 123...91011...(n-1)n(n-1)..11109...321. That is, ascending decimal numbers up to some ...
  • 6,775
29 votes
12 answers
1k views

Nth FizzBuzz Number

Introduction Everyone knows the FizzBuzz sequence. It goes something like this: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz . . . In case you don't ...
  • 3,129
12 votes
9 answers
589 views

AoCG2021 Day 17: Langton's Hexa-Virus

The story continues from AoC2017 Day 22, Part 2. The damn virus that was infecting a grid computing cluster now has jumped to a hexagonal computing cluster! In this cluster, the computers are ...
  • 66.1k

1
2 3 4 5
18