ios - Generate random Numbers with Specific need -


i developing cocos 2d game. please mention below arrangement.

---------------------------------|       |       |          |       |       |       |          |       | ---------------------------------|       |       |          |       |       |       |          |       | ---------------------------------|       |       |          |       |       |       |          |       | ---------------------------------|    ---------------------------------|       |        |          |      |       |        |          |      | ---------------------------------| 

now, need generate numbers between 1-99 in upper block so, when user touch numbers dropped below block. , have check numbers make combination of operation(i.e. +,-, *,/) divided 10 or not?

for example if user choose numbers 3,2,7,8 have internally calculated (3 +2 +7 +8 = 20 20%10 == 0 number divisible 10 increase score), same thing -, *,/. math operator same have decide code user has think dragging numbers.

so question how generate numbers in upper block support calculation(any 1 of +,-,*,/) combinations of them give dividability 10?

numbers not such combinations(either +, -, * ,/) of them did not give answer have modulo 0 10.

any appreciated.

you try inefficient algorithm. repeatedly generating numbers testing see if pass condition

do {    = random();    b = random();    c = random();    d = random();  } while( !test(a,b,c,d) ); 

this simplifies logic. need ensure @ least combination work or infinite loop.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -