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.
162
questions
101
votes
32answers
11k views
What are the five most powerful characters in your language?
Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 ...
85
votes
133answers
11k views
Determine whether strings are anagrams
Challenge
Given two strings, work out if they both have exactly the same characters in them.
Example
Input
word, wrdo
This returns true because they are the ...
74
votes
11answers
11k views
The 9 Billion Names of God
The 9 Billion Names of God is a short story by Arthur C. Clarke. It's about a group of Tibetan monks whose order is devoted to writing down all the possible names of God, written in their own alphabet....
45
votes
20answers
4k views
Greater than less than greater than something fishy
Given a length N string of less-than and greater-than signs (<, >), insert the integers 0 through N at the start and end ...
45
votes
19answers
5k views
Shotgun Numbers
The Shotgun numbers are a sequence with a rather simple definition but some interesting structure. Start with the natural numbers:
...
44
votes
12answers
2k views
Scramble words while preserving their outlines
This is much more advanced than How to randomize letters in a word and Cambridge Transposition because of the rule about which letters may be swapped with which. A simple regex will not suffice here.
...
42
votes
26answers
3k views
41
votes
11answers
4k views
Find a binary needle in a decimal haystack
The challenge
You're given:
a non-empty, unsorted list h of positive integers (the haystack)
a positive integer n (the needle)
Your task is to return the list of all unique decimal concatenations ...
37
votes
23answers
2k views
Antsy permutations
Introduction
Suppose you have a ruler with numbers from 0 to r-1.
You place an ant between any two of the numbers, and it starts to crawl erratically on the ruler.
The ruler is so narrow that the ant ...
36
votes
21answers
3k views
The Original Number
Guidelines
Scenario
John has an important number, and he doesn't want others to see it.
He decided to encrypt the number, using the following steps:
His number is always a non-decreasing sequence (...
35
votes
32answers
2k views
Manage Trash So
It's become somewhat of a tradition in PPCG that some users temporarily change their names by an anagram (a new name formed by reordering the letters of the old).
Sometimes it gets difficult to find ...
35
votes
35answers
6k views
Random Golf of the Day #1: Shuffle an Array
About the Series
I will be running a little series of code-golf challenges revolving around the theme of randomness. This will basically be a 9-Hole Golf Course, but spread out over several questions....
35
votes
17answers
3k views
Hidden Inversions (Cops' Thread)
This is a cops-and-robbers puzzle the robbers' thread can be found here.
Your task will be two write two programs (or functions) such that they are anagrams of each other and one performs the left ...
34
votes
6answers
2k views
Can you reach this number by doubling and rearranging?
Inspired by this question on Math.SE.
Starting with 1 you can repeatedly perform one of the following two operations:
Double the number.
or
Rearrange its digits ...
31
votes
20answers
2k views
Faro shuffle an array
A Faro shuffle is a technique frequently used by magicians to "shuffle" a deck. To perform a Faro shuffle you first cut the deck into 2 equal halves then you interleave the two halves. For example
<...
30
votes
21answers
2k views
Generate a random derangement
Challenge description
A "derangement" of a sequence is a permutation where no element appears in its original position. For example ECABD is a derangement of ...
29
votes
21answers
3k views
Levi-Civita symbol
The three-dimensional Levi-Civita symbol is a function f taking triples of numbers (i,j,k) each in ...
28
votes
29answers
5k views
Output an Anagram! No Not That One!
Given a list of unique strings that are anagrams of each other, output an anagram of those words that is different from each word in the list.
The strings will be alphanumeric, and there is ...
28
votes
27answers
2k views
Bit-Reversal Permutations
Your goal is to create a function or a program to reverse the bits in a range of integers given an integer n. In other words, you want to find the bit-reversal permutation of a range of 2n items, zero-...
27
votes
29answers
2k views
Alphabetically permute a string
Task
Your goal, should you choose to accept it, is to write a program, that, given an input string (or array of characters), outputs every possible permutation of the letters in that string. I'm ...
27
votes
5answers
581 views
Bubble the brackets!
There are a few questions on this site about balancing brackets, and checking whether brackets are balanced. I propose it's now time to use those balanced brackets for something!
In mathematics and ...
26
votes
11answers
1k views
Anagram Quines (Cops' Thread)
This is a cops-and-robbers challenge the Robbers' Thread can be found here
Your challenge is to write a program that outputs an anagram of its source code but not the original source code itself.
...
26
votes
13answers
2k views
Superpermutations
Introduction
You're a criminal tasked with stealing some secret plans from the new tech startup Dejavu. You sneak in over the back wall, but find a door that requires a pin to open it. You recognize ...
25
votes
24answers
2k views
Deranged !Combinatorics: Compute the Subfactorial
The subfactorial or rencontres numbers (A000166) are a sequence of numbers similar to the factorial numbers which show up in the combinatorics of permutations. In particular the nth subfactorial !n ...
25
votes
8answers
2k views
The Permutation Pigeon-hole Principle
In the game of sudoku, many players like to "pencil in" possible numbers that can go in each square:
The above row can be represented as an array:
...
24
votes
38answers
2k views
Golf an Anagram Quine
In this question I asked you to guess an anagram quine based on its output. However it looks like we don't have a question asking to golf an anagram quine yet. So your task will be to make the ...
24
votes
20answers
2k views
Imitate an ordering
Given two lists of numbers, a source and a pattern, reorder the source to match the relative ordering of the pattern. Any two entries of the reordered source should compare the same way as the entries ...
23
votes
27answers
2k views
List all ordered partitions of n
The challenge is to list all ordered partitions (composition (combinatorics)) of a given positive integer n. These are the lists of numbers from ...
23
votes
36answers
4k views
Reliably Broken Sort
Given a list of positive integers that contains at least 3 distinct entries, output a permutation of that list that isn't sorted in ascending or descending order.
Examples
...
23
votes
27answers
2k views
Rearranging the sequence
Introduction
Let's observe the following sequence (non-negative integers):
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...
For example, let's take the ...
23
votes
23answers
3k views
Encode - Shuffle - Decode
Challenge
Your task is to encode an integer as a string of ASCII characters, then successfully decode it after said string has been randomly shuffled.
You will write two programs/functions, which ...
23
votes
12answers
2k views
Number of cycles of a permutation
Consider a permutation of the integers 1, ..., n, such as this one for n = 6:
...
23
votes
26answers
2k views
Find The Rank Of A Word
Definition
The rank of a word is defined as the position of the word when all the possible permutations (or arrangements) of its letters are arranged alphabetically, like in a dictionary, no matter ...
23
votes
16answers
1k views
Random Golf of the Day #8: Shuffle an infinite list
About the Series
First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You ...
22
votes
25answers
2k views
Quine Anagrams! (Cops' Thread)
This is the cops' thread. For the robbers' thread, click here.
Cops' Task
First, write a quine in a language of your choosing.
Next, scramble the quine. Make sure to do this well as the robbers will ...
22
votes
13answers
2k views
Codegolf the Hafnian
The challenge is to write codegolf for the Hafnian of a matrix.
The Hafnian of an 2n-by-2n symmetric matrix ...
22
votes
12answers
3k views
Color me a Pole
Lets say your job is to paint poles, and a client asks you to paint a pole with 4 red sections and 3 yellow sections. You can do that pretty easily as follows:
...
22
votes
3answers
813 views
Loop It
Note: The title of this question should be "Loop It", but because title needs to be at least 15 characters, there are some invisible spaces. This note is such that the challenge can be searched for.
...
21
votes
25answers
2k views
Code-Golf: Permutations
Write a function that takes as input a set of integers (can be a list, array or any other container with distinct numbers), and outputs the list of all its permutations.
Python (95 chars):
...
21
votes
10answers
1k views
Prime factors buddies
Given an integer N > 1, output all other numbers which prime decompositions have the same digits as the prime decomposition of ...
21
votes
13answers
1k views
Every Possible Cycle Length
A function (or program) which takes inputs and provides outputs can be said to have a cycle if calling the function on its own output repeatedly eventually reaches the original number. For instance, ...
21
votes
12answers
2k views
All possible ways to interleave two strings
I recently saw this question on stackoverflow. It's a great question, but there's one fatal problem with the question. They are asking for the best way to do it. E.g, easiest to read, most idiomatic, ...
21
votes
8answers
1k views
Build this pyramid
Your pyramid
The pyramid I want you to build is made entirely of cubes. It has 24 layers, and the Nth layer from the top contains N2 cubes arranged in an N by N square. The pyramid looks like this:
...
21
votes
5answers
7k views
Sort a List With Swaps and Pops
Consider a randomized list of the integers 1 to N. You want to sort it using only the following actions:
Swap the first and last list elements. (S)
Pop off the first element and append it to the end ...
21
votes
9answers
2k views
I see your BIDMAS and raise you a BADMIS
I see your BIDMAS and raise you a BADMIS
Challenge
Given a set of numbers with operators between them: "5 + 4 * 9 / 3 - 8", return all the possible results of the expression for every permutation of ...
21
votes
3answers
395 views
Permutation Square Root
In math, a permutation σ of order n is a bijective function from the integers 1...n to itself. This list:
2 1 4 3
represents the permutation σ such that σ(1) = 2,...
20
votes
16answers
2k views
I give you Nth permutation, you give me N
Input: a sequence of uppercase letters (ASCII [65;90]) which is the Nth* lexicographical permutation of the multiset of its characters
*permutations are numbered from 0 or 1 upwards
Output: base-10 ...
20
votes
2answers
1k views
The Combinatorics of Transistor
The video game Transistor features a very interesting ability system. You collect 16 "Functions" which you can use in 16 different slots. What's interesting is that there are 3 types of slots and ...
20
votes
3answers
1k views
Anagramming Stack Exchange question titles into programs
Stack Exchange currently has 134 question and answer sites. This includes all beta sites (such as PPCG) but not Area 51 proposals nor any meta sites, except for the "mother meta".
To answer this ...
20
votes
9answers
1k views
Garble that string!
Given a string as input, output one or more variants of the string such that:
No character is in it's original position
No character is adjacent to a character that it was originally adjacent to
You ...