Questions tagged [integer-partition]

In number theory and combinatorics, a partition of a positive integer n, also called an integer partition, is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition. (If order matters, the sum becomes a composition.)

In number theory and combinatorics, a partition of a positive integer n, also called an integer partition, is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition. (If order matters, the sum becomes a composition.)

References:

47 questions
0
votes
2 answers

Integer Partition in Java

Here is my code to do this. It works for the string representation, but not the ArrayList> one. public static void partition(int n) { partition(n, n, "", new ArrayList>(), new…
soandos
  • 4,978
  • 13
  • 62
  • 96
0
votes
0 answers

Is it possible to explicitly and minimally index all integer solutions to x + y + z = 2n?

For example, the analogous two dimensional question, x + y = 2n is easy to solve: one can simply consider pairs (i,2n-i) for i=1,2,...,n and thus index every solution, exactly once. We note that we have n such pairs solving x + y = 2n, for every…
0
votes
1 answer

Integer partition N into M parts in parallel

I am trying to randomly generate integer partitions (N into M parts) in pytorch with a minimum partition size of 1. For example, (3, 1, 1) and (4, 1, 0) are both partitions of 5 into 3 parts but (4, 1, 0)'s minimum partition size is 0 so this should…
Tom Huntington
  • 2,260
  • 10
  • 20
0
votes
0 answers

How are recursive partition numbers found step by step on the program?

The "recursive partition numbers" code written using GAP 4.10.2 are as follows. For example, could you explain the working steps of the GAP programming for nrparts(15)? How did we get nrparts (15) = 176 step by step in the program? nrparts:=…
0
votes
1 answer

How to improve integer partitioning with n,m,k?

My program counts the integer partitions of n, which have k distinct partition elements, each is smaller or equal to m. How can I improve the performance? I already cache intermediate results. public long q(int n, int m, int k) { return q1(n, m,…
0
votes
1 answer

Count subsets consisting strictly k elements

I want to count the subsets of a with k subset elements which sum to n. The possible subset elements are defined through a given array a with distinct positive elements. Possible subset elements can be just choosen once per subset. How Can i do…
0
votes
1 answer

BigQuery: How to create integer partitioned table via DML?

I try to understand how the integer partitioned tables work. So far however, I could not create one. What is wrong with this query: #standardSQL CREATE or Replace TABLE temp.test_int_partition PARTITION BY RANGE_BUCKET(id,…
Ilja
  • 993
  • 2
  • 17
  • 36
0
votes
2 answers

Python and Number Theory: How can we create the generating function for q(n) (the number of partitions of n into distinct parts)?

From https://en.wikipedia.org/wiki/Partition_%28number_theory%29#Restricted_partitions, we know that the number of partitions of an integer p(n) is given by Can be written in python as: def partitions(n, I=1): yield(n,) for i in range(I,…
0
votes
2 answers

Fastest way for the computer to find combinations of non-negative integers x_1<=x_2<=...<= x_n and sum to 100

I want to find an efficient way for computer to handle LARGE NUMBER OF VARIABLES (say 50: x1, ... , x50) that do something like this: find ALL combinations [x1,x2,x3] satisfying: 0 <= x1 <= x2 <= x3 x1 + x2 + x3 = 100 Here is an example of finding…
lrh09
  • 557
  • 4
  • 13
0
votes
0 answers

How to convert to a Definite Clause Grammar

I'm trying to write a definite clause grammar that outputs the partitions of a number. For example ?- w(3,L,[]) should output : [1,1,1] [2,1] [1,2] [3] My code looks as follows: w(PosNumber) -->…
J.M
  • 15
  • 3
0
votes
1 answer

Integer partitioning in Java

I'm trying to implement a program that returns the number of existing partitions of an integer n as part of an assignment. I wrote the code below, but it returns the wrong number (Partitions n returns the result of Partitions n-1). I don't get why…
0
votes
1 answer

Integer partition iterative code optimization

I have been working on code to iteratively partition integers and use previous results to fully partition the numbers, with the idea that using previous partitions can increase speed. So far, I have gotten performance 22x slower than recursively…
0
votes
1 answer

Return value for recursive function with two arguments

Considering the following code for Integer Partition: int p (int n, int m) { if (n == m) return 1 + p(n, m - 1); if (m == 0 || n < 0) return 0; if (n == 0 || m == 1) return 1; return p(n, m - 1) + p(n - m,…
Monte San
  • 135
  • 2
  • 12
0
votes
1 answer

Algorithm to find the number of ways a number can be written as a sum of two or more positive numbers

It's a homework question and has to be solved using Dyanmic Programming approach. What I've managed to do so far is that: Let f(x) denote the number of times x can be written: Then f(x) = f(x - 1) + 1 ; f(5) = f(4) + 1 (5 = 4 + 1) But I don't think…
0
votes
1 answer

Get n in exact k parts. Recursion and partition algorithm. p(n,k)

I'm looking to enumerate all the partitions of n in k parts. So for p(5,3) i'd get 2 partitions of k = 3 => (3,1,1), (2,2,1). Here's what I found from searching and looking through stackoverflow : def p(n,k): lst = [] if n < k: …
Pobe
  • 364
  • 3
  • 13