Jump to content

I need some help guys :P

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Nille

Nille

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Ok allof you super programmers i need your help yet again.
I need to make a program where you first input the size of the array (<10) and then you will input numbers in each of the array "slots" or watever its called :P but here is the tricky part i need the program to calculate if there is any way you could divide the numbers in to either 2,3,4 or 6 different arrays (witch is pre-desided) and then output how it is done.

example:

input how many numbers you want to input: 5

input how many arrays you want it split in: 2

now input your 5 numbers: 7 5 4 4 4

It is possible to split in 2 arrays:
array 1: 4,4,4
array 2: 7,5

and if it is not possible to split it even i want the program to do it as even as possible and in the same way show how.


Thanks in forehand for any help and if i have missed something or have been lacking in the explanaton plz tell me and ill try to fix it :P

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Without knowing the rules for a "pile" it's a little tough to help out.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
hoser2001

hoser2001

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
Ya, if you have 5 numbers, and 2 arrrays, then there are way more than 2 "unique" ways to split them up... You need to be more specific

#4
Nille

Nille

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Well it dosent have to be 2 arrays and 5 numbers it can be either 2,3,4,6 arrays and 1-9 numbers the problem is that i dont know a way to make the program check if it is possible to split it even and in that case show how example if u have 6 arrays this time and 9 numbers 6,4,6,2,1,5,4,2,6 it would be possible to spit it even on 6 arrays
array 1: 6
array 2: 4,2
array 3: 1,5
array 4: 4,2
array 5: 6
array 6: 6

but if u change one of the sixes to a five it would not be possible to divide it evenly.

I dont know how to explain it any better then this but if u have any more questions add me on my msn nille890718@hotmail.com and i will try my best again to explain it

#5
hoser2001

hoser2001

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
Oh, now I understand what it is you are attempting.

From what I can tell, to figure out if it is possible to divide evenly, just take the sum of your numbers, and divide it by the number of arrays.

For example, you gave us 9 numbers and 6 arrays.
6+4+6+2+1+5+4+2+6 = 36
36/6 = 6
6 is a whole number so the division is possible.

Then, if any of your numbers are equal to the division answer, assign those to the arrays first.
array 1: 6
array 2: 6
array 3: 6

then for each number remaining, loop through the others and stop when you get a sum of 6, then add them to the arrays.

#6
Nille

Nille

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Yea that is a greate idea but wat if u have numbers like 143,315,352,452,245,685,675,456,345 and u have to check every single possibility to see if it is devidable :( ive been going around thinking about a way for about a week or so and i cant think of a way to make that kind of loop :P

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You may have to do some work where you attempt a division, and if it doesn't work by the initial method, back up and try a different combination. You can have numbers where the divisibility test suggests it is possible, but where the division cannot actually occur. This is actually a somewhat tricky type of problem (a partitioning problem).
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog