elbehh
Programmer
- Oct 25, 2006
- 5
Hello
It was given array "Obj"[/color blue] (number of objects what I must extract from ...) array "Box"[/color blue] (number of objects in this box).
I must select Objects in the following conditions ("Rez" the rezult how it looks like)
| Obj | Box | dif | Rez
---------------------------------------------------
1 | 4 | 7 | 3 | 4
2 | 3 | 9 | 6 | 3
3 | 2 | 7 | 5 | 2
4 | 2 [/color red]| 6 | 4 | 3[/color red]
5 | 3 | 2 | -1 | 2[/color red]
6 | 1 | 3 | 2 | 1
7 | 2 | 2 | 0 | 2
8 | 1 | 1 | 0 | 1
---------------------------------------------------
Sum | 18 | 37 | | 18
[/color blue]
The problem
I have 8 boxes … 7 objects in the first, 9 objects in the second, 6 in the third ... and so on...
I will start from the end, to extract objects - from Box8 to extract 1 object, from Box7 - 2 objects ...
But from the Box5[/color red] I cannot extract 3[/color red] objects because I have only 2 !!![/color red]
That means from Box4[/color red] I have to extract 2[/color red] objects, plus the difference from Box5, 1[/color red] object, total 3[/color red] objects
Details
I must extract around half of the number of objects.
Usually, the distribution of the objects is - less number of objects in Box8 and it is growing up to Box1
I mean - I can not have 36 objects in Box8 and nothing in the others.
The same it' s the distribution of objects what I have to extract - it is growing up from the end to the beginning.
To extract objects starting with Box1, I think it’s not so good because on the other way round I’m sure that I have ob-jects - the number of objects is growing up
I tried to make it simply but I finished with big-big algorithm.[/color red]
I show it bellow, only a portion ...
IF A8-B8 < 0 THEN
IF A7-B7-A8+B8 < 0 THEN
IF A6-B6-A7+B7+A8-B8 < 0 THEN
IF A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A2-B2-A3+B3+A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A1-B1-A2+B2+A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
TextBox ("it is imposible")
ELSE
C1=A1
………….
ELSE
C2=A2
………….
ELSE
C3=A3
………….
ELSE
C4=A4
………….
ELSE
C5=A5
ELSE
C6=A6
ELSE
C7=A7
ELSE
C8=A8
IF A7-B7-A8+B8 < 0 THEN
IF A6-B6-A7+B7+A8-B8 < 0 THEN
IF A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A2-B2-A3+B3+A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A1-B1-A2+B2+A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
TextBox ("it is imposible")
ELSE
C1=A1
ELSE
C2=A2
ELSE
C3=A3
[/color blue]
Thank you
It was given array "Obj"[/color blue] (number of objects what I must extract from ...) array "Box"[/color blue] (number of objects in this box).
I must select Objects in the following conditions ("Rez" the rezult how it looks like)
| Obj | Box | dif | Rez
---------------------------------------------------
1 | 4 | 7 | 3 | 4
2 | 3 | 9 | 6 | 3
3 | 2 | 7 | 5 | 2
4 | 2 [/color red]| 6 | 4 | 3[/color red]
5 | 3 | 2 | -1 | 2[/color red]
6 | 1 | 3 | 2 | 1
7 | 2 | 2 | 0 | 2
8 | 1 | 1 | 0 | 1
---------------------------------------------------
Sum | 18 | 37 | | 18
[/color blue]
The problem
I have 8 boxes … 7 objects in the first, 9 objects in the second, 6 in the third ... and so on...
I will start from the end, to extract objects - from Box8 to extract 1 object, from Box7 - 2 objects ...
But from the Box5[/color red] I cannot extract 3[/color red] objects because I have only 2 !!![/color red]
That means from Box4[/color red] I have to extract 2[/color red] objects, plus the difference from Box5, 1[/color red] object, total 3[/color red] objects
Details
I must extract around half of the number of objects.
Usually, the distribution of the objects is - less number of objects in Box8 and it is growing up to Box1
I mean - I can not have 36 objects in Box8 and nothing in the others.
The same it' s the distribution of objects what I have to extract - it is growing up from the end to the beginning.
To extract objects starting with Box1, I think it’s not so good because on the other way round I’m sure that I have ob-jects - the number of objects is growing up
I tried to make it simply but I finished with big-big algorithm.[/color red]
I show it bellow, only a portion ...
IF A8-B8 < 0 THEN
IF A7-B7-A8+B8 < 0 THEN
IF A6-B6-A7+B7+A8-B8 < 0 THEN
IF A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A2-B2-A3+B3+A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A1-B1-A2+B2+A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
TextBox ("it is imposible")
ELSE
C1=A1
………….
ELSE
C2=A2
………….
ELSE
C3=A3
………….
ELSE
C4=A4
………….
ELSE
C5=A5
ELSE
C6=A6
ELSE
C7=A7
ELSE
C8=A8
IF A7-B7-A8+B8 < 0 THEN
IF A6-B6-A7+B7+A8-B8 < 0 THEN
IF A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
IF A2-B2-A3+B3+A4-B4-A5+B5+A6-B6-A7+B7+A8-B8 < 0 THEN
IF A1-B1-A2+B2+A3-B3-A4+B4+A5-B5-A6+B6+A7-B7-A8+B8 < 0 THEN
TextBox ("it is imposible")
ELSE
C1=A1
ELSE
C2=A2
ELSE
C3=A3
[/color blue]
Thank you