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
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 ...
15
votes
17answers
2k views

Plain Hunt Bell-Ringing

Your task is to create a plain hunt (a bell ringing pattern) with n bells. An example with 6 bells: ...
13
votes
11answers
766 views

Output Distinct Factor Cuboids

Output Distinct Factor Cuboids Today's task is very simple: given a positive integer, output a representative of each cuboid formable by its factors. Explanations A cuboid's volume is the product ...
17
votes
23answers
1k views

Enumerate Derangements

Given some positive integer \$n\$ generate all derangements of \$n\$ objects. Details A derangement is a permutation with no fixed point. (This means in every derangement number \$i\$ cannot be in ...
16
votes
14answers
1k views

Permutations in Disguise

Given a \$n\$-dimensional vector \$v\$ with real entries, find a closest permutation \$p\$ of \$(1,2,...,n)\$ with respect to the \$l_1\$-distance. Details If it is more convenient, you can use ...
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 ...
19
votes
12answers
2k views

Calculate Landau's function

Landau's function \$g(n)\$ (OEIS A000793) gives the maximum order of an element of the symmetric group \$S_n\$. Here, the order of a permutation \$\pi\$ is the smallest positive integer \$k\$ such ...
14
votes
15answers
2k views

Generate combinations that add up to a target value

Challenge Suppose you have a list of numbers, and a target value. Find the set of all combinations of your numbers which add up to the target value, returning them as list indices. Input and Output ...
8
votes
4answers
610 views

Leading and Suffering Numbers

Introduction: In Dutch, the words leading and suffering, being 'leiden' and 'lijden' respectively, are pronounced the same way. One is written with a "short ei", and one with a "long ij", as we ...
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, ...
14
votes
16answers
640 views

Dihedral group D4 composition with custom labels

The dihedral group \$D_4\$ is the symmetry group of the square, that is the moves that transform a square to itself via rotations and reflections. It consists of 8 elements: rotations by 0, 90, 180, ...
8
votes
7answers
675 views

9erilous 9ermutations

Note: This is an attempt at recycling guest271314's permutation question(s) There's an interesting pattern that forms when you find the differences between lexographically sorted permutations of base ...
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 ...
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-...
14
votes
17answers
954 views

Code Golf: Forwards sdrawkcaB sdrawkcaB Forwards Forwards sdrawkcaB

Task The user inputs a sentence - words only. Any input other than letters or spaces, including integers and punctuation, should throw an exception: "Sentence must only use letters". The output has a ...
14
votes
11answers
898 views

Source permutation

A permutation of a set \$S = \{s_1, s_2, \dotsc, s_n\}\$ is a bijective function \$\pi: S \to S\$. For example, if \$S = \{1,2,3,4\}\$ then the function \$\pi: x \mapsto 1 + (x + 1 \mod 4)\$ is a ...
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 ...
18
votes
14answers
1k views

The Strange Unsorting Machine for Nefarious Purposes

Good Evening Golfers! Your challenge is to completely unsort a series of numbers. Input Exactly 100 integers will be fed to your program. Your program may accept the input either as a file, or via ...
3
votes
3answers
848 views

Words hidden in my phone number [closed]

Telephones in the United States (and perhaps some other places) have letters associated with some of the numbers. ...
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 ...
13
votes
6answers
316 views

Unique Brick Tilings Within A Rectangle

I was browsing Stackoverflow and saw this question about tiling an MxN rectangle, and I thought it would be great for golfing. Here is the task. Given the dimension M and N, write a program that ...
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): ...
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 ...
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 ...
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 ...
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 <...
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....
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 ...
15
votes
9answers
1k views

Hide the buildings

Shorter version of Skyscrapers Challenge Task Given an array of building heights and a positive integer k, find all the permutations(without duplicates) of the ...
-2
votes
3answers
142 views

Doce logf a string swapper [closed]

Challenge Take an input string \$s\$, and split it into words \$w_1, w_2, ..., w_n\$. If the amount of words is odd, then return \$s\$. Otherwise, for each word: Take the second last letter, and swap ...
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 ...
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 ...
9
votes
6answers
601 views

Output all distinct permutations of a vector

Challenge: Output all distinct permutations of a, potentially long, list of positive integers. You may assume that the vector has less than 1,000 numbers when testing, but the process should in ...
10
votes
5answers
379 views

Amidakuji (阿弥陀籤) simplification

If you have ever had any exposure to Japanese or East Asian culture you will have surely encountered the Amidakuji game: As Wikipedia explains, it is a type of lottery drawn on paper and used to ...
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 ...
7
votes
4answers
482 views

Permutation Encoding

Write a program which can encode text to avoid reusing characters, and convert back. Both normal and encoded forms are restricted to a particular character set: the space character ...
6
votes
0answers
291 views

What is the simplest reversible circuit that computes conjugacy of transpositions?

Reversible computation refers to computation in which little or no information is deleted. Reversible computation a major component of quantum computation, and reversible computation is potentially ...
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, ...
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 ...
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 ...
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....
14
votes
8answers
446 views

Deranged Rearrangements

Your task is to write a computer program such that when it is cut up into lines (split on the newline character) every arrangement of the lines will output a different number between 1 and n! (where n ...
14
votes
9answers
1k views

Block Rearrangement

So your task is to take a 3x3 block where -'s mean blank spaces, and *'s mean filled spaces, for example: ...
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 ...
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 ...
42
votes
26answers
3k views

Sheffle tho vawols ureund!

Given an input string, output that string with all vowels a, e, i, ...
2
votes
11answers
416 views

Noah's (upgraded) ark

As preparation for the nth Exodus, Noah decides to write a program that will decide If he will let animals on his ark. However, Noah wants to go back to grass roots. Thus he decides that the program ...
14
votes
12answers
1k views

Stitch Together a Palindrome from Palindromic Substrings

Given a string l, find all palindromic substrings p of l (including duplicates and single ...
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 ...
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 ...