Skip to main content

Questions tagged [permutations]

A permutation is a particular ordering of some list of objects. Problems tagged with permutation usually involve finding or generating permutations, including anagrams of text.

Filter by
Sorted by
Tagged with
11 votes
7 answers
620 views

This was originally a question from interviewstreet.com over a decade ago You are given an array (or whatever - your choice of input) of positive integers \$y_1,\ldots,y_n\$ that represents \$n\$ line ...
Henry's user avatar
  • 219
15 votes
4 answers
932 views

A popular method for solving Rubik's cube consists of: solving its first two layers, by convention starting with the white side orienting the last layer's pieces so they face the same direction with ...
ngn's user avatar
  • 15.6k
23 votes
15 answers
3k views

Your task is to write two programs/functions, in the same language. Program 1: Verify that two inputs are anagrams of each other. Program 2: Verify that two inputs differ from each other at every ...
Steve Bennett's user avatar
9 votes
4 answers
674 views

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 ...
Domenico's user avatar
  • 2,463
12 votes
9 answers
1k views

Given a permutation of {1,2,...,n} named A, do each swap of form swap A[i], A[j] exactly once, where ...
l4m2's user avatar
  • 32.7k
12 votes
8 answers
735 views

Given the height, \$h\$, and width, \$w\$, describing a rectangle of the first \$hw\$ natural numbers in row-major order produce the numbers in the order they are encountered by repeatedly removing a ...
Jonathan Allan's user avatar
13 votes
13 answers
2k views

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 ...
Sophia Antipolis's user avatar
8 votes
6 answers
1k views

Let N = [0,1,2,...n-1] be the initial segment of the natural numbers of length n, then all permutations of N can be sorted lexicographically, starting with the identity. The index into this sorted ...
Sophia Antipolis's user avatar
6 votes
3 answers
651 views

Each of a regular dodecahedron's 12 faces can be painted either red or blue. Your task is to implement a function \$f\$ that takes a painted dodecahedron (as 12 booleans, in whatever order and format ...
Karl's user avatar
  • 871
7 votes
12 answers
821 views

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 ...
Peter Thomas's user avatar
3 votes
4 answers
620 views

There are 251610 6 by 6 binary matrices that are inequivalent. We say two matrices are equivalent if there is some permutation of their rows and/or columns that makes them equal. For example: ...
Simd's user avatar
  • 3,167
5 votes
9 answers
371 views

Given a binary string \$s\$ of length \$2^n\$ and a permutation \$\sigma\$ of \$\{1,\dots,n\}\$, generate the binary string \$u\$ of length \$2^n\$ which is a reordering of \$s\$ such that \$u[i^\...
Karl's user avatar
  • 871
13 votes
8 answers
1k views

The challenge is simple: Reorder the first integers {0, 1, 2, ..., n} into an ordered list so that the following three conditions are met: If k is the last element in the list, then all of its prime ...
Carl's user avatar
  • 251
4 votes
18 answers
795 views

Challenge Given two lists of equal length, find if one of them is a permutation of the other. Output truthy or falsy values, or 1 or 0. Test case Examples ...
Andy Liu's user avatar
  • 251
8 votes
8 answers
1k views

Select any word from https://websites.umich.edu/~jlawler/wordlist with length greater than 1. For each letter on that word, remove it and check if any rearrangement of the remaining letters is present ...
enzo's user avatar
  • 2,153
10 votes
16 answers
2k views

Write a program or function that outputs all positive integers with distinct decimal digits (OEIS: A010784) Examples: ...
bsoelch's user avatar
  • 6,095
15 votes
18 answers
2k views

Your task is to find out how often you need to "shuffle" a given list with the following operation until you get back the original list. ...
bsoelch's user avatar
  • 6,095
16 votes
17 answers
1k views

Given a sequence of integers with length \$L\$ and an integer \$1 \le N \le L\$, an "\$N\$-rich" permutation is one whose the longest strictly increasing contiguous subsequence has length ...
EmilyR's user avatar
  • 1,533
21 votes
8 answers
1k views

Below on the left is a picture of a sorting network that can sort 4 inputs. On the right you can see it sorting the input 3,2,4,1. A sorting network of size ...
AnttiP's user avatar
  • 8,048
20 votes
27 answers
3k views

Challenge Description: An anagram is a word or phrase formed by rearranging the letters of another word or phrase. For example, "listen" and "silent" are anagrams. In this ...
cold10's user avatar
  • 303
0 votes
1 answer
436 views

This is my first codegolf post so let me know if I have missed anything. Thanks :) Description You are given a list of numbers with 2 < n <= 6 length i.e. [1, ...
Kyle Sharp's user avatar
13 votes
14 answers
795 views

Given a permutation, we can define its high-water marks as the indices in which its cumulative maximum increases, or, equivalently, indices with values bigger than all previous values. For example, ...
Command Master's user avatar
12 votes
18 answers
693 views

Objective Given a permutation of 4 distinct items, classify the permutation by the normal subgroup(s) it belongs. Input/Output Format You gotta choose the followings as the hyperparameters for your ...
Dannyu NDos's user avatar
  • 7,381
15 votes
9 answers
1k views

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. On the flight to Hawaii for vacation, I'm playing with a deck of cards numbered from 1 to \$n\$. Out of curiosity, ...
Bubbler's user avatar
  • 79.3k
19 votes
15 answers
2k views

You know those letterboards outside old-style cinemas which show upcoming films - perhaps you have a miniature one in your home? If you've operated one, you'll know that you can normally add letters ...
FlipTack's user avatar
  • 14.7k
0 votes
3 answers
377 views

Given a positive input \$n\$, output all permutations of either \$\{0,1,\ldots,n-1\}\$ or \$\{1,2,\ldots,n\}\$. Examples Outputting permutations of \$\{1,2,\ldots,n\}\$. Input Output ...
97.100.97.109's user avatar
11 votes
7 answers
1k views

Inspired by this question. Challenge Let L be a list of n distinct elements. Let P be the ...
Pavgran's user avatar
  • 467
11 votes
12 answers
1k views

Given an integer \$N\$ consider a permutation \$p=p_1,p_2,p_3,\ldots\$ of \$1,\ldots,N-1\$. Let \$P = p_1 , p_1+p_2 \bmod N, p_1+p_2+p_3 \bmod N, \ldots\$ be its prefix sums modulo \$N\$. Sometimes \$...
Albert.Lang's user avatar
  • 6,044
11 votes
14 answers
855 views

For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left ...
Wheat Wizard's user avatar
  • 103k
16 votes
13 answers
1k views

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 ...
pxeger's user avatar
  • 25.3k
20 votes
13 answers
3k views

Given some input array a = [a1, a2, ..., an] and a positive integer k, shuffle the input array ...
flawr's user avatar
  • 44.1k
8 votes
17 answers
1k views

Given an array of integers as input(including negative integers), find all (can include duplicates) permutations that do not have the same number next to each other, then print them all out. If no ...
Joao-3's user avatar
  • 2,090
10 votes
20 answers
1k views

Task Given a finite permutation output its inverse. You may take input and output in any reasonable format equivalent to a list of natural numbers. You may choose to use 0 indexing or 1 indexing. ...
Wheat Wizard's user avatar
  • 103k
15 votes
8 answers
747 views

A finite-permutation is a function which takes an \$n\$-tuple and produces an \$n\$-tuple such that every element of the input is present in the output, and the ordering does not rely on the values of ...
Wheat Wizard's user avatar
  • 103k
23 votes
25 answers
1k views

Your input is an array of numbers: a permutation of \$\{1, 2 \dots n\}\$ for some integer \$n \geq 2\$. How many times must you repeat this list before you can "pick out" the numbers \$[1, 2 ...
lynn's user avatar
  • 69.7k
19 votes
16 answers
1k views

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 ...
Wheat Wizard's user avatar
  • 103k
28 votes
30 answers
3k views

Inspired by this StackOverflow post Given a list where each element appears a maximum of 2 times, we can define it's "sortedness" as the sum of the distances between equal elements. For ...
caird coinheringaahing's user avatar
8 votes
17 answers
1k views

Let's say I've got a list (or array) of: l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] I want to get the third Cartesian power of the above list, where we take every ...
U13-Forward's user avatar
  • 2,031
10 votes
4 answers
264 views

The word "levencycle" is inspired by cyclic levenquine challenge. Definitions A 1-dup permutation of order \$n\$ is some permutation of \$1, \cdots, n\$ plus one duplicate number in the ...
Bubbler's user avatar
  • 79.3k
40 votes
70 answers
4k views

Input a non-empty array with \$n\$ positive integers. Test if the input array contains every integer in \$1\cdots n\$. In case you prefer 0-indexed numbers, you may choose to input an array of non-...
tsh's user avatar
  • 36.2k
21 votes
16 answers
3k views

Inspired by the problem with the same name on Puzzling SE by our very own Dmitry Kamenetsky. You are to find the largest number that only uses every digit pair once, in a given base. For example, in ...
AviFS's user avatar
  • 2,211
15 votes
14 answers
1k views

From Codidact with permission. Description APL trains are a series of functions, that get applied to an argument in this way: (f g) x = f g x here ...
Adám's user avatar
  • 31.8k
9 votes
4 answers
547 views

This fastest-code challenge is based partly on this MSE question and exists to extend some OEIS sequences, and create others. If I extend or create sequences based on this challenge, I'll link to this ...
Peter Kagey's user avatar
  • 8,175
2 votes
0 answers
86 views

For example, given 3 sets of parenthesis, you have: ()()() ((())) ()(()) (())() (()()) = 5 possible combinations. Challenge Program must: • Take 1 number as an ...
camila314's user avatar
  • 129
3 votes
0 answers
203 views

I am looking for a more efficient way of computing the following. Let A and B be two vectors of non-negative integers of length <...
Per Alexandersson's user avatar
22 votes
20 answers
2k views

A superpermutation on n symbols is a string which contains every permutation of n symbols in its body. For instance, 123121321 is a superpermutation on three ...
golf69's user avatar
  • 2,059
18 votes
20 answers
5k views

Background You may be aware that periods in between letters in gmail addresses are ignored. Email sent to [email protected], [email protected], and [email protected] all end up in the same ...
Conor James Thomas Warford Hen's user avatar
9 votes
6 answers
709 views

Definitions: A palindrome is a string which reads the same backward or forward (not counting spaces or special characters), such as "madam" or "Sorel Eros". A date is said to be a palindrome when ...
Regis Portalez's user avatar
3 votes
7 answers
305 views

Print the biggest-size subset of strings in the input that are all permutations of each other. If there are ties, any one will do. If no strings are permutations of each other (for example, only one ...
Nohl's user avatar
  • 57
21 votes
22 answers
3k views

Super permutations Input: A string The program should loop through all lengths of the input (decrementing one each time), generate all combinations with replacement of the string, then make ...
InxaneNinja's user avatar

1
2 3 4 5