views:

162

answers:

2

Hello

let say that we have an array [5,5]

01,02,03,04,05
06,07,08,09,10
11,12,13,14,15
16,17,18,19,20
21,22,23,24,25

the user should send 2 values to the function (start,searchFOR) for example (13,25) the function should search for that value in this way

07,08,09
12,  ,14
17,18,19

if the value is n't found in this level it will goes a level higher

01,02,03,04,05
06,  ,  ,  ,10
11,  ,  ,  ,15
16,  ,  ,  ,20
21,22,23,24,25

if the array is bigger than this and the value didn't found it will go to a level higher

Thanks for your help

<<<< EDIT >>>> FOR 25

  ,  ,  ,  ,  
  , ,  ,  ,  
  ,  ,  ,  ,  
  ,  ,  ,19,20  
  ,  ,  ,24,  

  ,  ,  ,  ,  
  ,  ,  ,  ,  
  ,  ,13,14,15
  ,  ,18,  ,  
  ,  ,23,  ,  

  ,  ,  ,  ,  
  ,07,08,09,10
  ,12,  ,  ,  
  ,17,  ,  ,  
  ,22,  ,  ,  

01,02,03,04,05
06,  ,  ,  ,  
11,  ,  ,  ,  
16,  ,  ,  ,  
21,  ,  ,  ,  
+2  A: 

Assuming this is homework...

You will notice that in a 5X5 array, you have to add/subtract 5 to move vertically, and add/subtract 1 to move horizontally.

This works regardless of your starting position in the array.

Now you just have to figure out how to know when you're on an edge.


You will need four for loops to get around each square, nested inside an outer loop. The outer loop will work each of the squares. You should be able to use the number generated by the outer loop to help you with your calculations in your inner loops.

Robert Harvey
no this is not a homework :D ... this is a part of my project and i'm trying to find the best way to handle it :P ... Thanks Robert
From.ME.to.YOU
A: 

In your scenario could you change your implementation a bit and start out with something a little different.

int[] lvl1 = [1, 2, 3, 4, 5, 10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 06]
int[] lvl2 = [7, 8, 9, 14, 19, 18, 17, 12, 7]
int[] lvl3 = [13]

Justin
:( no ... thanks for your answer
From.ME.to.YOU