Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > Pre-University Math Help > Pre-Algebra and Algebra
Reply
 
Thread Tools Display Modes
  #1  
Old January 2nd, 2009, 09:56 PM
Newbie
 
Join Date: Jan 2009
Posts: 3
Country:
Thanks: 0
Thanked 0 Times in 0 Posts
icemanind is on a distinguished road
Default 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 10:30 PM. Reason: Deleted potentially offensive language
Reply With Quote
Advertisement
 
  #2  
Old January 2nd, 2009, 10:01 PM
Super Member
 
Join Date: Dec 2008
Location: Scotland
Posts: 862
Country:
Thanks: 6
Thanked 341 Times in 319 Posts
Mush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the rough
Default

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 03:17 AM. Reason: Edited quote to match edit of OP
Reply With Quote
  #3  
Old January 2nd, 2009, 10:03 PM
Newbie
 
Join Date: Jan 2009
Posts: 3
Country:
Thanks: 0
Thanked 0 Times in 0 Posts
icemanind is on a distinguished road
Default

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!
Reply With Quote
  #4  
Old January 2nd, 2009, 10:08 PM
Super Member
 
Join Date: Dec 2008
Location: Scotland
Posts: 862
Country:
Thanks: 6
Thanked 341 Times in 319 Posts
Mush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the rough
Default

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
Reply With Quote
  #5  
Old January 2nd, 2009, 10:17 PM
Newbie
 
Join Date: Jan 2009
Posts: 3
Country:
Thanks: 0
Thanked 0 Times in 0 Posts
icemanind is on a distinguished road
Default

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?
Reply With Quote
  #6  
Old January 2nd, 2009, 10:35 PM
mr fantastic's Avatar
Flow Master

 
Join Date: Dec 2007
Location: Zeitgeist
Posts: 12,020
Country:
Thanks: 2,514
Thanked 4,695 Times in 4,132 Posts
mr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond reputemr fantastic has a reputation beyond repute
Default

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.
__________________
There are two things you should never try to prove: the impossible and the obvious.

The greater danger for most of us lies not in setting our aim too high and falling short; but in setting our aim too low and achieving our mark. (Michelangelo Buonarroti)

  • To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  • To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  • To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  • To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  • To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote
  #7  
Old January 5th, 2009, 09:28 PM
Super Member
 
Join Date: Dec 2008
Location: Scotland
Posts: 862
Country:
Thanks: 6
Thanked 341 Times in 319 Posts
Mush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the rough
Default

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.
Reply With Quote
  #8  
Old January 6th, 2009, 05:39 AM
MHF Contributor
 
Join Date: Apr 2005
Posts: 3,301
Thanks: 291
Thanked 1,161 Times in 1,063 Posts
HallsofIvy has much to be proud ofHallsofIvy has much to be proud ofHallsofIvy has much to be proud ofHallsofIvy has much to be proud ofHallsofIvy has much to be proud ofHallsofIvy has much to be proud ofHallsofIvy has much to be proud ofHallsofIvy has much to be proud ofHallsofIvy has much to be proud of
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 11:41 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.