find distances on a grid

Discussion in 'Programming' started by drewbe121212, Sep 12, 2006.

  1. #1
    Hello all, I am trying to figure out a solution to this. The problem is in my math.

    I have a grid layout IE.


    A1 A2 A3 A4 A5
    B1 B2 B3 B4 B5
    C1 C2 C3 C4 C5
    D1 D2 D3 D4 D5
    E1 E2 E3 E4 E5

    of course, the letters correspond to a number for doing the math IE A=1; B=2; C=3; D=4; E=5;

    Now,
    lets pretend I am currently at C3 and I want to move to any given location.
    Each space counts as 1 place so if i move to B5 it will account for 3 spaces, and from B5 to A1 would be 5.

    I can get this to work, but only part of the time. Obviously their need to be certain conditions that are met when doing the math (sometimes it needs added, sometimes it needs subtracted etc).

    Does anyone know the correct alogrithm for this?

    I am going to guess that their are 4 conditions (depending on the direction we are moving). My attempts, however, have been futile :/

    Any help will be appreciated!

    Thanks,
    drew
     
    drewbe121212, Sep 12, 2006 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,826
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #2
    You want us to do your homework for you?

    You should have the basic skills from classwork.
     
    sarahk, Sep 12, 2006 IP
  3. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #3
    What?!?!?
    Heh, no homework. This is just something I have been playing with.

    I think you misunderstood my statement "The problem is in my math."

    By that, I meant not math class, but math as in the arithmatic that I am using to try to find out correct answer. Trust me, the classes I am taking right now have no relation to this what so ever,

    unless you can find that in COBOL, ASP.NET, Career Development, Database management, or Contemporary history. I could see how It could relate to a couple of these, but sorry... it doesn't :/

    This is just me having free time and trying to figure out the math between grid movement.

    Now, back to the original question.
    Any suggestions or ideas in the alogorithm would be greatly appreciated :)
     
    drewbe121212, Sep 12, 2006 IP
  4. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #4
    Alright, it seems I have figured it out.

    The biggest problem I was having with it is that at some point in time sometimes the numbers were negative (as in moving from the right to the left).

    I thought the answer was indeed in the math, but rather something else proved much more useful, and no math is required.

    First I figure out what the difference is between the current position, and the next position in the columns and the rows, assuming all grids count as +/- 1.

    Now, I have two numbers (either of which can be positive/negative) and ABSOLUTE them to be positive. I now have a positive integer that represents how many rows/cols the moveTo position is at, and simply add them together for the tally'ing result. :)

    SO
    distance = [currCol - moveToCol] + [currRow - moveToRow]

    SarahK, the thing that upsets me the most is that you assumed I was asking someone to do it for me :/ I was working on it as this thread set idling, I just needed a push in the right direction...

    Thanks for the input anyways though...


    ****SOLVED*****
     
    drewbe121212, Sep 12, 2006 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,826
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #5
    Toughen up. It's not uncommon for students to ask for help in doing assignments.

    I couldn't see the business problem you were trying to solve so lept to the wrong conclusion. That's my mistake, sure, but no reason to be upset.
     
    sarahk, Sep 12, 2006 IP