Hi All,
I'm having a little math problem (logic really) which goes a little something like this.
I have an array. This array has a known number of items of numerical value. Some of these items are numerical, and some are null. I also have a seperate value which tells me the total sum of these values, whether or not they are null. ie:
Array(null, null, null, null, 10);
Total = 90;
With this, I know that the first four items must equal 80, so I can divide 80 by the number of null items and assign each one the value 20. Simple.
However, theres more. I have a second array. This array can contain items that specify that multiple items may equal a certain amount. ie
Values = Array(null, null, null, null, 10);
modifier = Array();
modifier(0)(80 with length of 3, null, null, null, null); // I've set this up using bitwise values!
modifier(1)(null, null, null, 20 with length of 2, null);
modifier(2)(null, null, 80 with length of 3, null, null);
Total = 100;
With this, I know that the 4th item must be 10 (because that and the next item must equal 20), the third item must equal 60 (because the last two equal 20 and the sum of the last three must equal 80) and the first to must total 20, so I can average them to 10 a piece, meaning I now have an array like this...
Array(10,10,60,10,10); // equals 100!!!
So... My question now is "How do I represent this problem in code?"
Before this is tackled, though, imagine the following example...
Values = Array(null, null, null, null, 50, null, null, null, null);
modifier = Array();
modifier(0)(600 with length of 4, null, null, null, null, null, null, null, null); // I've set this up using bitwise values!
modifier(1)(null, null, null, null, null, null, null, null, null);
modifier(2)(null, 350 with length of 2, null, null, null, null, null, null, null);
modifier(3)(null, null, null, null, null, null, null, null, null);
modifier(4)(null, null, null, null, null, null, null, null, null);
modifier(5)(null, null, null, 350 with length of 5, null, null, null, null, null);
Total = 850;
(equals Array(100, 100, 250, 150, 50, 50, 50, 50, 50); - easy to work out in your head, but how in code?)
I've been trying to tackle this problem for over a week with little joy
Thanks millions in advance,
Hard Up Coder