Results 1 to 8 of 8

Math Help - Simple pre-algebra help needed

  1. #1
    Newbie
    Joined
    Jan 2009
    Posts
    3

    Simple pre-algebra help needed

    Okay, this will be pretty elementary, I'm sure. But for some reason, I am having trouble. I am trying to write a program and I am using the following formula:

    Offset = Y * 160 + X * 2

    This formula works great for what I'm doing. My question is, what is the formula I use to retrieve X and Y, assuming I know Offset. For example, if Offset = 1500, what is the value of X and Y?

    If it helps, what this is is X and Y coordinates for video memory. Video memory is broken down into 80x25 characters and each character takes 2 spaces.....So if I want to write to Y=10 and X=5, using my formula above, the offset to write to would be 1610.

    So my question is, given 1610 as an Offset, what formula do I use to make Y=10 and X=5?

    Hope this makes sense and thanks in advance

    Alan
    Last edited by mr fantastic; January 2nd 2009 at 08:30 PM. Reason: Deleted potentially offensive language
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member
    Joined
    Dec 2008
    From
    Scotland
    Posts
    901
    Quote Originally Posted by icemanind View Post
    Okay, this will be pretty elementary, I'm sure. But for some reason, I am having trouble. I am trying to write a program and I am using the following formula:

    Offset = Y * 160 + X * 2

    This formula works great for what I'm doing. My question is, what is the formula I use to retrieve X and Y, assuming I know Offset. For example, if Offset = 1500, what is the value of X and Y?

    If it helps, what this is is X and Y coordinates for video memory. Video memory is broken down into 80x25 characters and each character takes 2 spaces.....So if I want to write to Y=10 and X=5, using my formula above, the offset to write to would be 1610.

    So my question is, given 1610 as an Offset, what formula do I use to make Y=10 and X=5?

    Hope this makes sense and thanks in advance

    Alan
    So you're asking us to solve an equation with 2 variables? Unfortunately it's not possible to solve for 2 unknowns unless you have 2 equations.

    However, if X and Y are restricted to integer values then your equation is a linear diophantine equation (ax+by=c), and these can be solved using the Euclidean Algorithm if c is the greatest common divisor of a and b (or indeed a multiple of the greatest common divisor!) Do you know the algorithm?
    Last edited by mr fantastic; January 3rd 2009 at 01:17 AM. Reason: Edited quote to match edit of OP
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jan 2009
    Posts
    3
    Quote Originally Posted by Mush View Post
    So you're asking us to solve an equation with 2 variables?

    Well, if X and Y are restricted to integer values then your equation is a linear diophantine equation, and these can be solved using the Euclidean Algorithm. Do you know the algorithm?


    X and Y are both integer. And no, I don't know that algorithm. Please explain it!
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Super Member
    Joined
    Dec 2008
    From
    Scotland
    Posts
    901
    Quote Originally Posted by icemanind View Post
    X and Y are both integer. And no, I don't know that algorithm. Please explain it!
    Extended Euclidean algorithm - Wikipedia, the free encyclopedia

    Knock yourself out
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jan 2009
    Posts
    3
    Quote Originally Posted by Mush View Post

    I'm sorry man. The answer to this cannot possibly be this complex. Please let me explain this a different way. Imagine you have a piece of paper. And this piece of paper has 160 squares across and 25 rows of these squares going down. Now lets say you write your letters kind of fat and to write one letter on the piece of paper, it will occupy 2 squares. That means you can have 80x25 letters on this paper. Now lets say we give this paper axises. X goes across and Y goes down. Now lets say I want you to draw a letter at coordinate 10,5. But instead of counting 10 squares across and 5 down, just count each individual square. Remember that 1 letter = 2 squares. So you would count to 1610 and make your letter (cause our formula is Offset(1610)=Y * 160 + X * 5).

    Now what I'm trying to do is opposite. What if I said, make a letter at offet 1610. Would you count 1610 spaces? the 1610th space is 10 boxes over and 5 down. Does this make sense?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Flow Master
    mr fantastic's Avatar
    Joined
    Dec 2007
    From
    Zeitgeist
    Posts
    16,948
    Thanks
    5
    Quote Originally Posted by icemanind View Post
    Okay, this will be pretty elementary, I'm sure. But for some reason, I am having trouble. I am trying to write a program and I am using the following formula:

    Offset = Y * 160 + X * 2

    This formula works great for what I'm doing. My question is, what is the formula I use to retrieve X and Y, assuming I know Offset. For example, if Offset = 1500, what is the value of X and Y?

    If it helps, what this is is X and Y coordinates for video memory. Video memory is broken down into 80x25 characters and each character takes 2 spaces.....So if I want to write to Y=10 and X=5, using my formula above, the offset to write to would be 1610.

    So my question is, given 1610 as an Offset, what formula do I use to make Y=10 and X=5?

    Hope this makes sense and thanks in advance

    Alan
    I'm afraid that the answer given by Mush appears to be how your question needs to be answered.

    You could always write (or find) a computer program to implement this algorithm.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Super Member
    Joined
    Dec 2008
    From
    Scotland
    Posts
    901
    It might be interesting to note, OP, that even if there was a simpler method for finding X and Y in your equation, that there is not one unique solution. There are in fact INFINITELY many solutions. You may use the regular euclidian algorithm to find one solution.

     ax+by = c

    If you use the regular algorithm, and get a solution(x,y). Then there are other solutions of the form (x+\frac{kb}{gcd(a,b)},y+\frac{ka}{gcd(a,b)}) where k is a member of the integers. There are in fact infinitely many integers, and hence there are infinitely many solutions so such an equation.

    Hence, even if there was a simpler method, it might take you infinitely many recursions until you got to your desired answer. In your example: (y=10,x=5). Although I do realise that your grid limits the solutions such that the integers are confined to your grid, so perhaps it's not such an impractical endeavour.

    If you would like further explanation on how to solve you problem using the regular euclidian algorithm, then just ask.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    MHF Contributor

    Joined
    Apr 2005
    Posts
    15,545
    Thanks
    1394
    Quite frankly, the simplest way to write a program to find integers X and Y such that Offset = Y * 160 + X * 2 for a given "offset" is first to write X= (Offset- 160Y)/2 and then step through integer values for Y until you find one that gives X integer also.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 4
    Last Post: December 3rd 2010, 05:17 PM
  2. [SOLVED] Help with simple equation needed.
    Posted in the Algebra Forum
    Replies: 4
    Last Post: October 27th 2010, 03:17 PM
  3. Simple linear algebra question - opinion needed
    Posted in the Advanced Algebra Forum
    Replies: 1
    Last Post: February 3rd 2010, 09:29 AM
  4. Simple formula needed?
    Posted in the Geometry Forum
    Replies: 4
    Last Post: August 3rd 2009, 12:09 PM
  5. Help needed on simple algebra
    Posted in the Algebra Forum
    Replies: 1
    Last Post: May 13th 2007, 11:58 AM

Search Tags


/mathhelpforum @mathhelpforum