Skip to main content

Questions tagged [combinatorics]

Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.

Filter by
Sorted by
Tagged with
-1 votes
0 answers
32 views

Efficient way to solve word scramble

I wrote this code below to automatically find all possible arrangements of letters of a word whose letters are randomly mixed up. All letters of the word are stored in an array. For example, when the ...
John's user avatar
  • 47
4 votes
1 answer
121 views

Repetition-Limited Multiset Coefficient function

This is a simple multiset coefficient calculator in python, that will calculate both standard multiset coefficients, as well as multiset coefficients with repetition limits, used initially as part of ...
Lee Davis-Thalbourne's user avatar
2 votes
1 answer
100 views

Combinations of elements in array

I wrote this code to get all possible arrangements for an array containing 3 elements: ...
John's user avatar
  • 47
0 votes
0 answers
71 views

1d profile cutting optimization

I wanted to make a VBA that creates self-renewing combinations and I actually did it, but Excel was crashing when the combinations increased, unfortunately Excel does not work in multi-item lists. ...
ömür tokman's user avatar
0 votes
0 answers
42 views

Video Poker with luck modifier

While grinding for coins on the GTA San Andreas casino poker machines I started to wonder how exactly one might implement a luck modifier to a video poker game without it being completely obvious to ...
TorbenPutkonen's user avatar
1 vote
0 answers
94 views

Generating group permutations: an extended Heap's algorithm in Java

Suppose we have a sequence of sequences <1, 2> <3, 4>. There, we have two groups: <1, 2> and ...
coderodde's user avatar
  • 28.3k
6 votes
2 answers
102 views

Schedule a series of 1:1 contests so that each entrant plays against every other

My sister is organizing a Majong tournament. She wants to set up a set of round-robin rounds. There will be 16 players at 4 tables; 4 players per table. Players will play 5 rounds. She wants every ...
JDT's user avatar
  • 81
0 votes
0 answers
36 views

An Array of x Elements, Max Entry = y, Total of Elements = z

In working on something else, I have come across this little brain-burner. I want to return an array of all the arrays that satisfy this. There are elArr elements ...
Rewind's user avatar
  • 115
2 votes
1 answer
128 views

Find the list of combination (with repetition) given rank and number of items. (Lexicographic ordering)

The problem involves the fastest possible method to generate a list of combinations which repeats from all the possible combinations with repetition allowed. I know there needs to be a way to ...
Reptorian's user avatar
3 votes
1 answer
150 views

String Permutation Implemention

The objective is simple: List all possible permutations for a given a String. I looked at some implementations from popular sources. I decided to build this to the flow: The Code for Review ...
Amal Krishnan's user avatar
1 vote
1 answer
201 views

Creates all possible permutations of a string and its substrings

I want to improve this code to efficiently create all possible permutations/combinations of a string. For example, if I have the string "abc", the result would be the list [ab, ac, ba, bc, ...
themightye's user avatar
0 votes
0 answers
196 views

Program to generate a tree of permutations

There is a computation I'm doing with permutations (permutations of varying length of an entire interval [1,N] for some N) in python that I feel could be faster. ...
Matt Samuel's user avatar
0 votes
1 answer
106 views

Effective encoding-decoding chain determination (time optimization)

Could you please help with speeding-up this code? Input: UTF-8 text (encoded 1-3 times from known pool of encodings). Every time was encoded and decoded by random encoding from pool. Original was koi8-...
Kir S's user avatar
  • 1
7 votes
2 answers
1k views

Find all combinations of length 3 whose sum is divisible by a given number

I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size. The problem: Given a list ...
NFeruch - FreePalestine's user avatar
8 votes
2 answers
940 views

Print all "balanced" sequences of 'A' and 'B'

the aim of the code below is to print all balanced sequences with equal number of 'A' and 'B'. A sequence is balanced if every prefix of length \$\geqslant 4\$ is balanced. A prefix is balanced if the ...
kodkod's user avatar
  • 441
3 votes
0 answers
55 views

Check if two semistandard Young tableaux are compatible

I have a question about how to check if two tableaux are compatible (will define below). Here we only consider tableaux of rectangular shape. A tableau is called semistandard if its rows are weakly ...
Jianrong Li's user avatar
2 votes
0 answers
115 views

Iterating over all simple unique cycles in an undirected graph in Java - brute-force approach

This post is about an Iterator iterating over simple loops of an undirected graph. In the above graph, the cycle \$\langle 1, 2, 3, 4, 5, 3, 1 \rangle\$ is not ...
coderodde's user avatar
  • 28.3k
0 votes
1 answer
65 views

Query for sequential column permutations in SQLite

For dummy's sake, let's say that I have a database with columns text, ind and sentid. You ...
Bram Vanroy's user avatar
0 votes
1 answer
85 views

An algorithm that minimizes the number of ingredients necessary

I am working on a code that will minimize the number of ingredients necessary to make some dishes. Each dish can be prepared in an arbitrary large number of ways, with combinations of two ingredients. ...
adrienlucca.net's user avatar
2 votes
1 answer
145 views

Boolean evaluation

Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the number of ways ...
Andrei Rost's user avatar
1 vote
0 answers
33 views

Scheme Procedure for Permuting Characters in a String

The following is a Scheme procedure to permute the characters in an input string. It outputs permutations of all lengths from 1 character up to the number of characters in the input string. ...
clartaq's user avatar
  • 257
1 vote
0 answers
643 views

Recursive combinations with subsets in Elixir

...
Glutexo's user avatar
  • 111
0 votes
3 answers
120 views

A more elegant way to uniformly sample from non-negative integers with a fixed sum

Given a positive integer n, I would like to randomly output n non negative integers that sum to ...
Simd's user avatar
  • 191
1 vote
1 answer
333 views

Printing subarrays ⚡

I was trying to to print all subarrays of an array in quadratic time. Here is my code: ...
Vaibhav Vishal Singh's user avatar
2 votes
2 answers
775 views

Subarrays with length

You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
Vaibhav Vishal Singh's user avatar
3 votes
2 answers
448 views

Pascal's triangle solution in Python code

I have solved the pascal's triangle problem. I am not good at writing efficient programs, hence any suggestions/ comments shall be welcomed. ...
Zainab Saad's user avatar
0 votes
1 answer
126 views

Subset Product Algorithm

Subset Product is an NP-complete problem and is my favorite problem. So, I've written a slightly smarter way of solving the problem. Will performance impact matter if I use multi-cpus and my GPU? Do ...
The T's user avatar
  • 431
1 vote
0 answers
44 views

Iterating over de Bruijn sequences in JavaScript

I have just put this code together, it's not quite the most elegant but it seems to get the job done. Does it seem alright? I could not find anywhere a "de Bruijn sequence algorithm", so I ...
Lance's user avatar
  • 351
5 votes
2 answers
2k views

Find non-overlapping pairs of elements in a list whose difference is less than some given threshold

I have the following task: Let us have a list (denoted by L, and for simplicity, the elements come from the interval [0,1]). We are given a parameter (denoted by C), and we want to find as many pairs ...
Atvin's user avatar
  • 153
5 votes
2 answers
246 views

Count five-digit octal numbers with alternating even and odd digits, without repeated digits

I need to find the number of five-digit octal numbers in which all digits are different and no two odd or even digits are adjacent. My code below gives the correct answer, but I'm not satisfied. Can ...
o0o0o's user avatar
  • 53
5 votes
1 answer
226 views

Given a number of points, generates all paths between all points that does not overlap

I wrote this code in 4 days, I want to see if I can optimize this code some more, and have some suggestion on what can I improve. This code takes in any number of points then naming them ...
pockspocky's user avatar
1 vote
1 answer
125 views

Minimum re-labeling to make an array as close as possible to another one

I have an array with integer labels in [0, n-1], say arr1=[1, 0, 3, 2] with n = 3. And then I have another array again with integer labels in [0, n-1], say arr2=[0, 0, 2, 3]. How can I find the ...
ApPs's user avatar
  • 13
1 vote
1 answer
726 views

Calculating all combinations from arrays AND (arrays OR floats)

Context: My question comes from needing to iterate different np.arange arrays. The main motivation is to calculate all the possible combinations between the arrays, ...
nuwe's user avatar
  • 163
1 vote
1 answer
167 views

Absolute Permutation | Hacker Rank: Any way to make this python code faster without changing it's whole logic?

https://www.hackerrank.com/challenges/absolute-permutation/problem I know that if you work out the math and logic first, the algorithm can be simplified greatly (shifting indices), but is that the ...
No Name's user avatar
  • 147
2 votes
1 answer
224 views

Finding possible combinations for n<7 with rust

I am trying to learn rust and as such have been redoing some of the challenges on project Rosalind. This one relates to the challenge Enumerating Gene Orders. ...
mega_creamery's user avatar
1 vote
0 answers
35 views

Mean and variance of element-wise distances in a set of multi-dimensional arrays in Matlab - follow-up

This is a follow-up question for Calculate distances between two multi-dimensional arrays in Matlab and Mean and variance of element-wise distances in a set of multi-dimensional arrays in Matlab. For ...
JimmyHu's user avatar
  • 4,748
4 votes
1 answer
1k views

Generate possible combinations by range and length

I am learning Haskell and I implemented a recursive function that generates possible strings by length and array (e.g. ['a'..'z']): ...
Vlad Havriuk's user avatar
0 votes
1 answer
58 views

Increase speed of lapply function identifying the sum of all existing combinations

I have a dataframe of cases that score 0-1 on a group of binary attributes. What I want to do is extract all possible ombinations of attribute triplets (e.g. A/B/C, A/B/D... out of A-E) and then sum ...
Fnguyen's user avatar
  • 163
2 votes
1 answer
228 views

In how many different ways can a group of 9 people be divided into 3 groups, with each group containing 3 people?

To divide 9 persons into 3 groups, when the ordering of groups is not important can be done in (9C3 * 6C3 * 3C3) / (3!) = 280 ways Here, we divide by (3!) because the ordering of 3 groups is not ...
Prateek Thapa's user avatar
2 votes
0 answers
38 views

Loop through the nearest switch and deletion neighbours of a Boolean assignment

My goal is to look for nearest neighbours in a Boolean-assigned mapping (a Python dictionary). For this purpose I'm looping through the candidates, starting from those with the closest distance. The ...
Felix Emanuel's user avatar
3 votes
3 answers
986 views

Generate all subsets of a set

The goal of the function below is to generate all subsets of a given set, i.e. a collection of sets that contain all possible combinations of the elements in the set. Note that for my application I do ...
Alexandre Bintz's user avatar
3 votes
1 answer
103 views

Building a tree containing all permutations of arithmetic expressions given some numbers

Given any series of numbers, for example 1,2,3,4,5 and given the arithmetic operands + - * / including parenthesis, what would be the most optimal way to build a tree that contains all permutations ...
Mihael Keehl's user avatar
4 votes
1 answer
574 views

Find all combinations of numbers of a set that add up to a given target - avoid for loops

I am thinking about the following problem: Consider a 3-numbers lock, i.e. a lock which has three little number wheels that opens whenever the sum of these three numbers equals 75. I know, this doesn'...
Luk's user avatar
  • 141
0 votes
2 answers
128 views

Get the next bigger number by rearranging the digits of the input integer

...
Edmerson Pizarra's user avatar
4 votes
1 answer
824 views

Rust implementation of next-permutation

I am translating this next permutation algorithm in C++: ...
prehistoricpenguin's user avatar
2 votes
2 answers
1k views

Generate all possible unique combinations of positive numbers these have sum equal to N

This is my function to generate all possible unique combinations of positive numbers these have sum equal to N. For example: If the input is 4 The output should ...
Chau Giang's user avatar
2 votes
1 answer
1k views

Fast brute force numpy array combination

I want to extract the combinations of numpy arrays in this way: ...
snowflake's user avatar
  • 275
1 vote
2 answers
1k views

Find All Permutations of String in Scala

I created the following function, permutations, to produce all permutations of a List[A]. Example: ...
Kevin Meredith's user avatar
0 votes
2 answers
353 views

Next different permutation in C

This is a program which you can get the next "different", i.e. elements in A[] can be identical, permutation at each call. I've written a C++ program for ...
RainningTW's user avatar
0 votes
1 answer
1k views

Generating permutations fast

I run into a performance bottleneck in a program. I have to generate all permutations for a given sequence with size up to n=11. My code: ...
Sandro4912's user avatar
  • 3,076

1
2 3 4 5
10