|
Re: While statements
[Re: Icarni]
#320412
04/21/10 16:34
04/21/10 16:34
|
Joined: Sep 2009
Posts: 496
Progger
Senior Member
|
Senior Member
Joined: Sep 2009
Posts: 496
|
try this
while((x_1 == x_2) || (x_2 == x_3) || (x_3 == x_4) || (x_4 == x_5) || (x_5 == x_6) || (x_6 == x_7) || (x_7 == x_8) || (x_8 == x_9) || (x_9 == x_10) || (x_1 == x_3) || (x_2 == x_4) || (x_3 == x_5) || (x_4 == x_6) || (x_5 == x_7) ||
(x_6 == x_8) || (x_7 == x_9) || (x_8 == x_10) || (x_1 == x_4) || (x_2 == x_5) || (x_3 == x_6) || (x_4 == x_7) ||
(x_5 == x_8) || (x_6 == x_9) || (x_7 == x_10) || (x_1 == x_5) || (x_2 == x_6) || (x_3 == x_7) || (x_4 == x_8) ||
(x_5 == x_9) || (x_6 == x_10) || (x_1 == x_6) || (x_2 == x_7) || (x_3 == x_8) || (x_4 == x_9) || (x_5 == x_10) ||
(x_1 == x_7) || (x_2 == x_8) || (x_3 == x_9) || (x_4 == x_10) || (x_1 == x_8) || (x_2 == x_9) || (x_3 == x_10) ||
(x_1 == x_9) || (x_2 == x_10) || (x_1 == x_10))
You just frogot two brackets WFG Progger 
|
|
|
Re: While statements
[Re: Icarni]
#320418
04/21/10 16:59
04/21/10 16:59
|
Joined: Oct 2007
Posts: 5,211 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,211
İstanbul, Turkey
|
you may also try to use an array.
void main(){
video_screen = 0;
var vx[10];
int i = 0;
int j = 0;
while(i<10){
vx[i] = integer(random(192)+1);//create random number
//check if that number generated before
j = 0;
while(j<10){
//loop thru all numbers
if(i!=j)if(vx[i]==vx[j]) break;
j++;
}
if(j==10) i++;//if j is 10 at this point it means loop is not broken, therefore same number not encountered, start generating nex number
}
//print all numbers
i = 0;
while(i<10){
printf("%d \n",vx[i]);
i++;
}
}
3333333333
|
|
|
Re: While statements
[Re: Icarni]
#320419
04/21/10 17:07
04/21/10 17:07
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
creating a list actually is a bit cumbersome with a low level language like lite-c. but you could also try something like that instead:
int array[192]; // fill it with 1..192
int numbers[10];
int n;
for(n=0; n<10; n++)
{
index = random(191-n);
numbers[n] = array[index];
array[index] = array[191-n]; // remove the number from the array by replacing it with the last one in the array (the last one won't be accessed anymore)
}
it's not tested. probably it needs some small corrections (integer(),...) but you should get the idea. edit: didn't see quadraxas' solution before doing my post. i think mine is better and more elegant.  quadraxas' solution also has random runtime. i think it's better than the original huge while clause though.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|