Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures.
0
votes
0answers
54 views
4
votes
2answers
58 views
all combinations of all sizes less than N
I want to generate all possible combinations (without duplicates) of all sizes less or equal than \$N\$, so for example if \$N=3\$ I want to generate the following
\$\{1\},\{2\},\{3\},
...
1
vote
1answer
55 views
Permutations with repetitions algorithm in R
Given a string of length n, print all permutation of the given string.
The code bellow generates all permutations (with repetitions) for the given string and stores them in object ...
2
votes
1answer
71 views
2
votes
1answer
45 views
3D bin packing in Java
I made some changes to the first code here I wrote and I want to know which one is more correct logically (before the changes or after the changes).
It's really hard to manually test these kind of ...
3
votes
1answer
40 views
3D bin packing algorithm using Java?
I wrote a 3D bin packing algorithm but I am still not sure if it is correct or not.
I did not follow any code or pseudo-code that's why I would like to know if it is an efficient algorithm for the 3D ...
9
votes
2answers
106 views
Finding all contiguous sublists such that each member appears an even number of times
The program needs to find all contiguous sublists of numbers where the number of occurrences of every member in the contiguous sublist is divisible by 2.
The first line of input is N (the number of ...
5
votes
2answers
131 views
Java 8 Stream to produce all permutations of an array using recursion
I want to write a class that returns a Stream of permutations of an int[].
...
9
votes
5answers
238 views
Pizza Hut math problem #1 in Haskell
I'm currently attempting to learn Haskell after a fair history of imperative programming. When I saw the Pizza Hut Pi Day math problems, I thought the first one would be a good candidate for my ...
2
votes
1answer
51 views
1
vote
1answer
49 views
Finding Kth Permutation Sequence
I have written a program to display the kth permutation sequence of a string made up of letters 'O' and 'Z' . I tried optimizing it but my code have not passed test cases due to timeout issues.Looking ...
1
vote
1answer
93 views
Characters set permutations with repetitions
The code bellow generates all the permutation(with repetitions) for given character set. Is there any better(simpler, more performant) way to do that?
...
5
votes
1answer
93 views
Finding ways to achieve a target sum using recursion
I need your review and suggestions how to make this code better. I'm just learning recursion and sure that this solution is not ideal.
Question:
Write a function that given an input array of ...
6
votes
3answers
69 views
Korean word segmentation using frequency heuristic
This a continuation of a previous question. I want to thank Joe Wallis for his help with increasing the readability of my code. Although the changes made by Joe Wallis did increase the speed of the ...
2
votes
1answer
93 views
5
votes
2answers
48 views
Making the same amount from different combinations of coins (top-down approach)
I was reading a typical interview question found here. Given an amount and a list of denominations, count the number of possible ...
3
votes
1answer
63 views
Improving Speeds of Tokenisation of large word list for distinct combinations
I'm having trouble with a current algorithm I'm writing that takes a corpa, a list of characters in sets (1 one or larger) with a frequency number attached to it. Against another list of character ...
6
votes
1answer
54 views
All possible ways of merging two lists while keeping their order
I am writing a function gives all possible ways of merging two ordered lists such that in the merged list, the elements are still ordered according to the elements in their respective starting list.
...
6
votes
2answers
88 views
An iterator returning all possible partitions of a list in Java
Given a list of \$n\$ objects and an integer \$k \in \{ 1, 2, \dots, n \}\$, this iterator generates all possible ways of partitioning the elements in the list into exactly \$k\$ disjoint, non-empty ...
5
votes
0answers
102 views
An iterator returning all possible permutations of a list in Java
I have this class that iterates over all permutations of an input list:
PermutationIterable.java:
...
2
votes
0answers
54 views
Generate Subsets Of K Elements From A Set Of Strings
This is the task:
Write a recursive program, which prints all subsets of a given set of N words.
Example input:
words = {'test', 'rock', 'fun'}
...
1
vote
2answers
76 views
Combination generator in Java - 2nd iteration
I have refactored the previous combination generator, and now it is an iterator returning combinations as lists. It hides larger constant factors as the previous version, yet it is really easy to use:
...
1
vote
2answers
33 views
multirange iterator
I'm doing some boring math with lot of sums over lot of variables. So, instead of nesting for loops I have decided to use something like this:
...
7
votes
5answers
791 views
Generate a dictionary of passwords
I have a Python script that generates a dictionary of all possible 3 digit password combinations. It essentially works by just nesting for loops. This is fine, but ...
0
votes
0answers
437 views
Solution to King Kohima problem in Python
King Kohima problem:
King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to ...
4
votes
1answer
91 views
Combination generator in Java
(See the next iteration.)
Given a positive \$N\$, the following class generates all possible non-empty sets \$A \in \mathcal{P}(\{0, 1, \dots, N - 1\})\$ in lexicographic order. Also, it provides a ...
8
votes
1answer
83 views
Scala implementation of @rolfl's integer-partitioning algorithm
While reviewing @Martijn's Distinct sums of integers (finding all combinations of positive integers that sum to a given number), I proposed the following solution:
...
2
votes
2answers
60 views
C permutation generator
I am making a permutation generator in c. Any ideas how I can make it faster?
...
3
votes
3answers
83 views
Searching a string for any permutation of words
Given a string and an array of words, return all indexes in string for which a concatenation of all words in the array,
in any order (so ["eensie", "weensy", "spider"] has six orderings) can be ...
7
votes
1answer
87 views
Recursive program for generating and printing all permutations of the numbers 1, 2, …, n for given integer number n
I've just written code for generating all permutations of the numbers from 1 to n in Java. It seems to work, but I think it's a bit more complex than it needs to be.
...
4
votes
1answer
98 views
Permutation function in C#
One thing lead to another and eventually I wanted to know the "proper" way of writing the permutation generating function in C#. Below is my code for generating permutations. This will go into an ...
11
votes
5answers
564 views
isPermutation method
I wrote an isPermute method. Can I get some tips and advice on better coding style?
...
14
votes
4answers
927 views
Printing all possible sums of two n-sided dice rolls
For my CS class, we were tasked with writing a program that calculates all the possible results from rolling two n-sided dice. For example, the input of 4 would ...
3
votes
3answers
60 views
Finding tuples of numbers subject to constraints
I just watched the video from "Think Like a Programmer, Episode 2: Puzzles & Problems".
The problem is:
Assign number 1-7 to three departments in a city: Fire, Police,
Sanitation.
...
7
votes
1answer
134 views
Finding permutations of a word
This was a basic anagram problem. Take an input word, find all its permutations, then check a dictionary file to see what if any of those are real words.
Dictionary file
My input data:
...
11
votes
1answer
130 views
Counting paths in an n-dimensional grid that stay within the boundaries
Problem Statement
You are situated in an N dimensional grid at position (x1, x2, …, xN).
The dimensions of the grid are (D1, D2, …, DN). In one step, you can
walk one step ahead or behind in ...
10
votes
1answer
238 views
Programming Challenge from Kattis: Apparatus
I am trying to solve apparatus problem, paraphrased below.
There is an apparatus with n on/off switches with a one-to-one correspondence to n lights (but with an unknown permutation).
We have ...
7
votes
0answers
101 views
Permuting a typelist
Given a typelist, return a typelist of all the permutations of it. For example:
...
3
votes
1answer
64 views
`r` permutations of `n`
I have written this snippet to find r-permutations of n, i.e. if I have an array of n=3 {0,1,2}, then r=2 permutations will be {{0, 1}, {0, 2}, {1, 0}, {1, 2}, {2, 0}, {2, 1}}.
Can somebody review it ...
6
votes
2answers
113 views
Generate all combinations of certain digits
Related to another answer of mine on Project Euler 35, I found the need to calculate all combinations of certain digits, i.e. 1, 3, 7 and 9, below a given n. I ...
3
votes
2answers
56 views
Find unique variants of a product
I am writing a piece of code that returns all the unique variants that a product is available in for an ecommerce app. For example, a shirt product can be available in different colors, sizes, and ...
1
vote
1answer
29 views
Coins problem in Erlang
How many different ways can 200 be made using any number of coins? The possible denominations are 1, 2, 5, 10, 20, 50, 100, 200.
...
2
votes
2answers
100 views
17
votes
2answers
277 views
Calculate all possible distributions of n objects to k containers
Let's say I have \$5\$ apples, thus \$n = 5\$. I have three bags (\$k = 3\$), each having the capacities of \$4\$, \$4\$ and \$2\$:
$$c = { \{4, 4, 2 \}}$$
I'd like to calculate the number of ways ...
4
votes
1answer
159 views
Counting ways to fit bottles in crates
I'm calculating how many possibilities there are to fit \$n\$ identical bottles inside \$k\$ crates of various capacities.
n = Number of bottles
k = Number of crates
K = List of the number of ...
2
votes
2answers
176 views
Non-Contiguous Substrings
Problem:
A non-contiguous substring of string \$s\$ is a sequence of \$k \geq 0\$ characters in \$s\$, in the order in which they occur in \$s\$. For instance, the set of all non-contiguous ...
8
votes
3answers
249 views
4
votes
2answers
186 views
Find co-occurrence of elements
My input consists of a list of lists (not necessary of the same length), like
...
7
votes
2answers
289 views
Generating 3 combinations in Python
I have been experimenting around with generating all the n-combinations of an array. This code quickly generates all \$\text{k-combinations}\$ of a given array. I am testing my own implementation ...
2
votes
2answers
64 views
Method for finding all classes
This was inspired by a Stack Overflow question about getting all the classes of an application and I took it a little too seriously (or perhaps not seriously enough).
It's rather silly to do it this ...