Questions tagged [combinatorics]
Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.
501 questions
4
votes
1
answer
226
views
Use z3py to solve one logic constraint puzzle
I decided to practice by modeling some simple, hand-solvable problems using z3py. Below is an example:
...
0
votes
0
answers
15
views
Demonstration of the Power Contamination Problem on Grids Revisited in Mathematica
The implementation successfully demonstrates all key findings from the research paper arXiv:2509.12756, including the disproof of the original conjecture and the establishment of the correct formula ...
0
votes
0
answers
18
views
Mathematica implementation of Lempel method for constructing Costas arrays
I ported C++ implementation of Lempel method for constructing Costas arrays to Mathematica.
How to fix my code? Thanks in advance.
...
4
votes
1
answer
192
views
The Permutations Algorithm using BubbleSort and stack in PicoBlaze assembly language - attempt #2
So, this is improved code from my previous attempt to implement the permutations algorithm in PicoBlaze assembly language.
You can see it live here:
...
2
votes
1
answer
194
views
Java program for calculating probabilities of die combinations in Yatzy
Yatzy
Yatzy is a dice rolling game where players aim to get particular die combinations.
This program counts probability of each such combinations. They are:
All five ones,
All five twos,
Same for ...
3
votes
1
answer
102
views
<Programming in Lua - 4th> exercise 2.2 - place 8 queens
About exercise 2.2
Place N queens on N*N board, 1 queen per line, so that all queens are safe.
Use permutation to improve the provided implementation from book.
The ...
3
votes
2
answers
235
views
Find the join of two set partitions
Two partitions of a set have a greatest lower bound (meet) and a least upper bound (join).
See here: Meets and joins in the lattice of partitions (Math SE)
The meet is easy to calculate. I am trying ...
4
votes
1
answer
149
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 ...
1
vote
0
answers
75
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 ...
6
votes
2
answers
121
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 ...
3
votes
1
answer
189
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
...
1
vote
1
answer
154
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-...
8
votes
2
answers
976
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 ...
2
votes
0
answers
131
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 ...
1
vote
1
answer
109
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. ...
1
vote
3
answers
163
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 ...
2
votes
2
answers
831
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) ...
1
vote
1
answer
165
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 ...
5
votes
2
answers
291
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 ...
2
votes
1
answer
179
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 ...
1
vote
1
answer
194
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 ...
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']):
...
2
votes
1
answer
268
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 ...
3
votes
3
answers
1k
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 ...
4
votes
1
answer
628
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'...