partition numbers in four terms

P

Pascal

hello all

I try to find a class able to store in an array or a collection or something
like that (I don't know what will be the best practice) all the different
combinations of the partitions of any integer in four terms :
exemple :

8= (5 + 1 + 1 + 1)
= ( 4 + 2 + 1 + 1)
= ( 3 + 2 + 2 + 1 )
= ( 3 + 3 + 1 +1) etc.

( 4 + 2 + 1 + 1) is not different of ( 2 + 1 + 4 + 1)

I found a code on the net but in java :
http://bytes.com/topic/c/answers/869529-print-all-combinations-number-n-sum-positive-integers
Does someone knows something in java and vb, so he could translate it for
me.... I am not very handy in programmation, just make some stuff for my
young pupils.

Thanks in advance


public class Partition {

private static void printPartition(int[] p, int n) {
if (n != 4) return; // bail out
for (int i= 0; i < n; i++)
System.out.print(p+" ");
System.out.println();
}

private static void partition(int[] p, int n, int m, int i) {

if (n == 0)
printPartition(p, i);
else
for (int k= m; k > 0; k--) {
p= k;
partition(p, n-k, n-k, i+1);
}
}

public static void main(String[] args) {

partition(new int[6], 6, 6, 0);
}
}
--
 
I

imuaplease

hello all

I try to find a class able to store in an array or a collection or something
like that (I don't know what will be the best practice) all the different
combinations of the partitions of any integer in four terms :
exemple :

8= (5 + 1 + 1 + 1)
= ( 4 + 2 + 1 + 1)
= ( 3 + 2 + 2 + 1 )
= ( 3 + 3 + 1 +1) etc.

( 4 + 2 + 1 + 1) is not different of ( 2 + 1 + 4 + 1)

I found a code on the net but in java :http://bytes.com/topic/c/answers/869529-print-all-combinations-number...
Does someone knows something in java and vb, so he could translate it for
me.... I am not very handy in programmation, just make some stuff for my
young pupils.

Thanks in advance

public class Partition {

    private static void printPartition(int[] p, int n) {
  if (n != 4) return; // bail out
        for (int i= 0; i < n; i++)
            System.out.print(p+" ");
        System.out.println();
    }

    private static void partition(int[] p, int n, int m, int i) {

        if (n == 0)
            printPartition(p, i);
        else
            for (int k= m; k > 0; k--) {
                p= k;
                partition(p, n-k, n-k, i+1);
            }
    }

    public static void main(String[] args) {

        partition(new int[6], 6, 6, 0);
    }}

--


Simply that is an order partition
 
I

imuaplease

hello all

I try to find a class able to store in an array or a collection or something
like that (I don't know what will be the best practice) all the different
combinations of the partitions of any integer in four terms :
exemple :

8= (5 + 1 + 1 + 1)
= ( 4 + 2 + 1 + 1)
= ( 3 + 2 + 2 + 1 )
= ( 3 + 3 + 1 +1) etc.

( 4 + 2 + 1 + 1) is not different of ( 2 + 1 + 4 + 1)

I found a code on the net but in java :http://bytes.com/topic/c/answers/869529-print-all-combinations-number...
Does someone knows something in java and vb, so he could translate it for
me.... I am not very handy in programmation, just make some stuff for my
young pupils.

Thanks in advance

public class Partition {

    private static void printPartition(int[] p, int n) {
  if (n != 4) return; // bail out
        for (int i= 0; i < n; i++)
            System.out.print(p+" ");
        System.out.println();
    }

    private static void partition(int[] p, int n, int m, int i) {

        if (n == 0)
            printPartition(p, i);
        else
            for (int k= m; k > 0; k--) {
                p= k;
                partition(p, n-k, n-k, i+1);
            }
    }

    public static void main(String[] args) {

        partition(new int[6], 6, 6, 0);
    }}

--


Simply that is an order partition
 
C

Cor Ligthert[MVP]

Pascal,

Your code is done in the program language C# here it is about VB

Cor
 
C

Cor Ligthert[MVP]

Pascal,

Your code is done in the program language C# here it is about VB

Cor
 
P

Pascal

C# OR JAVA ?

--
http://www.scalpa.info
http://scalpa98.blogspot.com/
http://scalpa-production.blogspot.com/

Cor Ligthert said:
Pascal,

Your code is done in the program language C# here it is about VB

Cor

Pascal said:
hello all

I try to find a class able to store in an array or a collection or
something like that (I don't know what will be the best practice) all the
different combinations of the partitions of any integer in four terms :
exemple :

8= (5 + 1 + 1 + 1)
= ( 4 + 2 + 1 + 1)
= ( 3 + 2 + 2 + 1 )
= ( 3 + 3 + 1 +1) etc.

( 4 + 2 + 1 + 1) is not different of ( 2 + 1 + 4 + 1)

I found a code on the net but in java :
http://bytes.com/topic/c/answers/869529-print-all-combinations-number-n-sum-positive-integers
Does someone knows something in java and vb, so he could translate it for
me.... I am not very handy in programmation, just make some stuff for my
young pupils.

Thanks in advance


public class Partition {

private static void printPartition(int[] p, int n) {
if (n != 4) return; // bail out
for (int i= 0; i < n; i++)
System.out.print(p+" ");
System.out.println();
}

private static void partition(int[] p, int n, int m, int i) {

if (n == 0)
printPartition(p, i);
else
for (int k= m; k > 0; k--) {
p= k;
partition(p, n-k, n-k, i+1);
}
}

public static void main(String[] args) {

partition(new int[6], 6, 6, 0);
}
}

 
P

Pascal

C# OR JAVA ?

--
http://www.scalpa.info
http://scalpa98.blogspot.com/
http://scalpa-production.blogspot.com/

Cor Ligthert said:
Pascal,

Your code is done in the program language C# here it is about VB

Cor

Pascal said:
hello all

I try to find a class able to store in an array or a collection or
something like that (I don't know what will be the best practice) all the
different combinations of the partitions of any integer in four terms :
exemple :

8= (5 + 1 + 1 + 1)
= ( 4 + 2 + 1 + 1)
= ( 3 + 2 + 2 + 1 )
= ( 3 + 3 + 1 +1) etc.

( 4 + 2 + 1 + 1) is not different of ( 2 + 1 + 4 + 1)

I found a code on the net but in java :
http://bytes.com/topic/c/answers/869529-print-all-combinations-number-n-sum-positive-integers
Does someone knows something in java and vb, so he could translate it for
me.... I am not very handy in programmation, just make some stuff for my
young pupils.

Thanks in advance


public class Partition {

private static void printPartition(int[] p, int n) {
if (n != 4) return; // bail out
for (int i= 0; i < n; i++)
System.out.print(p+" ");
System.out.println();
}

private static void partition(int[] p, int n, int m, int i) {

if (n == 0)
printPartition(p, i);
else
for (int k= m; k > 0; k--) {
p= k;
partition(p, n-k, n-k, i+1);
}
}

public static void main(String[] args) {

partition(new int[6], 6, 6, 0);
}
}

 
M

Michael Williams

Your code is done in the program language C# here it is about VB

Not the real VB of course, the final version of which was VB6, but the
"pretend" VB, the imposter called VB.Net in which the "VB" part is a lie.
Tell it like it is, Ligthert :)

Mike
 
M

Michael Williams

Your code is done in the program language C# here it is about VB

Not the real VB of course, the final version of which was VB6, but the
"pretend" VB, the imposter called VB.Net in which the "VB" part is a lie.
Tell it like it is, Ligthert :)

Mike
 
T

Tom Shelton

Not the real VB of course, the final version of which was VB6, but the
"pretend" VB, the imposter called VB.Net in which the "VB" part is a lie.
Tell it like it is, Ligthert :)

Mike, are you mean that toy from the ancient past? LOL.
 
T

Tom Shelton

Not the real VB of course, the final version of which was VB6, but the
"pretend" VB, the imposter called VB.Net in which the "VB" part is a lie.
Tell it like it is, Ligthert :)

Mike, are you mean that toy from the ancient past? LOL.
 
A

Armin Zingler

Tom said:
Mike, are you mean that toy from the ancient past? LOL.

Mike can't recognize his wife if she's wearing a new dress and starts to
dance. Then he thinks she is an animal. }:->


Armin
 
A

Armin Zingler

Tom said:
Mike, are you mean that toy from the ancient past? LOL.

Mike can't recognize his wife if she's wearing a new dress and starts to
dance. Then he thinks she is an animal. }:->


Armin
 
M

Michael Williams

Mike can't recognize his wife if she's wearing a new
dress and starts to dance. Then he thinks she is an
animal.

That doesn't even make sense, Zingler. Perhaps its a Germanic thing? You
Germans certainly are a weird bunch. No real sense of humour at all. By the
way, I would probably recognise your wife, although not if she's wearing a
dress of course ;-)

Mike
 
M

Michael Williams

Mike can't recognize his wife if she's wearing a new
dress and starts to dance. Then he thinks she is an
animal.

That doesn't even make sense, Zingler. Perhaps its a Germanic thing? You
Germans certainly are a weird bunch. No real sense of humour at all. By the
way, I would probably recognise your wife, although not if she's wearing a
dress of course ;-)

Mike
 
F

Family Tree Mike

Pascal said:
hello all

I try to find a class able to store in an array or a collection or
something like that (I don't know what will be the best practice) all the
different combinations of the partitions of any integer in four terms :
exemple :

8= (5 + 1 + 1 + 1)
= ( 4 + 2 + 1 + 1)
= ( 3 + 2 + 2 + 1 )
= ( 3 + 3 + 1 +1) etc.

( 4 + 2 + 1 + 1) is not different of ( 2 + 1 + 4 + 1)

I found a code on the net but in java :
http://bytes.com/topic/c/answers/869529-print-all-combinations-number-n-sum-positive-integers
Does someone knows something in java and vb, so he could translate it for
me.... I am not very handy in programmation, just make some stuff for my
young pupils.

Thanks in advance


public class Partition {

private static void printPartition(int[] p, int n) {
if (n != 4) return; // bail out
for (int i= 0; i < n; i++)
System.out.print(p+" ");
System.out.println();
}

private static void partition(int[] p, int n, int m, int i) {

if (n == 0)
printPartition(p, i);
else
for (int k= m; k > 0; k--) {
p= k;
partition(p, n-k, n-k, i+1);
}
}

public static void main(String[] args) {

partition(new int[6], 6, 6, 0);
}
}


This is what I came up with:

Module Module1
Sub printPartition(ByVal p As Integer(), ByVal n As Integer)
If (n <> 3) Then Return
Dim i As Integer
For i = 0 To n
Console.Write("{0} ", p(i))
Next
Console.WriteLine()
End Sub

Sub partition(ByVal p As Integer(), ByVal n As Integer, _
ByVal m As Integer, ByVal i As Integer)
If (n = 0) Then
printPartition(p, i)
Else
Dim k As Integer
For k = m To 1 Step -1
p(i) = k
partition(p, n - k, n - k, i + 1)
Next
End If

End Sub

Sub Main()
Dim p() As Integer
ReDim p(6)

partition(p, 6, 6, 0)

Console.WriteLine("Done...")
Console.ReadLine()
End Sub

End Module
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top