Hi folks,
sorry I must be getting a little bit rusty ... :-(
Could you help me out with the following:
I have 5 Variables (A B C D E).
Each Variable is starting with a value of 1 and can count up to 2000.
I want to start with A=1 B=1 C=1 D=1 E=1 and first count up E up to 2000.
As soon as it reaches 2000 the value D shall be increased to 2 and E shall run up from 1 to 2000 again and so on until D also reaches 2000. If so C shall be increased to 2, D back to 1 and E count up from 1 to 2000 again ...
So what I want is to run all possible combinations where A B C D E can become something between 1 and 2000.
For each combination I want to perform some calculations and if the result I'm looking for (Which is: The combination where all my calculations will have the same result) is found the script shall stop and report me the current values for A B C D E ...
I started with the following lines but somehow I got stuck and my mind refuses to think any further even though it's not such a huge programming problem ... :-(
Could you help me out with that ?
Regards,
Thomas
sorry I must be getting a little bit rusty ... :-(
Could you help me out with the following:
I have 5 Variables (A B C D E).
Each Variable is starting with a value of 1 and can count up to 2000.
I want to start with A=1 B=1 C=1 D=1 E=1 and first count up E up to 2000.
As soon as it reaches 2000 the value D shall be increased to 2 and E shall run up from 1 to 2000 again and so on until D also reaches 2000. If so C shall be increased to 2, D back to 1 and E count up from 1 to 2000 again ...
So what I want is to run all possible combinations where A B C D E can become something between 1 and 2000.
For each combination I want to perform some calculations and if the result I'm looking for (Which is: The combination where all my calculations will have the same result) is found the script shall stop and report me the current values for A B C D E ...
I started with the following lines but somehow I got stuck and my mind refuses to think any further even though it's not such a huge programming problem ... :-(
Code:
#!/usr/bin/ksh
A=1
B=1
C=1
D=1
E=1
while [ $A -lt 2000 ];
do
while [ $B -lt 2000 ];
do
while [ $C -lt 2000 ];
do
while [ $D -lt 2000 ];
do
while [ $E -lt 2000 ];
do
RA=$(($A+$B))
RB=$(($C-$A))
RC=$(($A*$D))
RD=$(($A/$E))
if [ $RA -eq $RB -a $RB -eq $RC -a $RC -eq $RD ];
then
echo $A $B $C $D $E
echo $RA $RB $RC $RD
echo "That's it !"
exit 1;
fi
E=`expr $E + 1`
done
D=`expr $D + 1`
done
C=`expr $C + 1`
done
B=`expr $B + 1`
done
A=`expr $A + 1`
done
Could you help me out with that ?
Regards,
Thomas