ios - 1000 * 256 *4 for loop takes a minute to complete -


i'm trying check winning numbers of simple gambling game. user selects 4 cards of each symbol (diamond, heart etc') , creates 256 combinations specific selection. 4*4*4*4 = 256 combinations. have array of 1000 raffle results. each result contains 4 winning cards , numeric value.

i need check how many winning cards each result contains.

my code looks this:

    for(int=0;i<results;i++) // [results count] = 1000     {          ...          ...         //take 1 results , check against combinations         for(int j=0;j<usercombinations;j++) // [usercombinations count] = 256        {         [self checkwins:[usercombinations objectatindex:j]]        }     }  -(void)checkwins:(nsmutablearray *)myarray {          for(int j=0;j<4;j++)        {         //j=0 -> if heart numeric value equals heart numeric result         //j=1 -> if diamond numeric value equals diamond numeric results         } } 

there may typos in code (wrote memory) basic idea same. question this, processes above takes:

  • a few seconds on i7 mac book pro

  • on old android above, written in java, takes 6-9 seconds.

  • on iphone 4 takes full minute finish process. < - this problem

am doing wrong? can think of better way above? there way speed things up?

thanks

edit:

the user selects these numbers

h  d  c   s 7  8  9  10 10 4  2  11 11 6  5  13 12 5  1  9 

and gets 256 combinations.

first 6 combinations:      current raffle result: 7 4 9 11     h  d  c   s     7  8  9  10    2 matches     7  8  9  11    3 matches     7  8  9  13    2 matches     7  8  9  9     2 matches     7  8  2  10    1 match     7  8  2  11    1 match     etc'...                        total current raffle result 7 4 9 11:                    3 matches - 1 time                    2 matches - 3 times                    1 match - 2 times 

i need pass on 256 combinations created , check them against every winning result. if 1 of combinations contains winning number mark , save in array can display later.

the way i'd represent each raffle result ordered c-string such c5d3h4s6 c5 = 5 of clubs comes before s6 = 6 of spades. order user selection c-string, such c2c3c4c6d1d2d3d4h4h5h6h7s7s8s9s10.

the purpose of no longer need inner loop permuting user selection. each raffle, can 1 pass scan through selection determine if c5d3h4s6 has matched. results should order of magnitude faster.

note not using objective-c method dispatch here, not helpful performance-wise.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -