CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Posts
    3

    rectangle problem using loops - alternating between intervals given a pt

    Hi. I'm trying to solve this problem below. It seems really difficult. The purpose of this problem from http://www.cs.duke.edu/courses/cps14...6/allprobs.pdf is not to use recursion, but make use of loops.

    A rectangle with sides parallel to the x-y axes and its left-lower corner at (0, 0) is being painted. The rectangle may be thought of as a flat-screen display with almost infinite resolution; initially the entire rectangle is black. Two numbers are given 0 < h < 1, 0 < v < 1 and then
    1)A vertical line is drawn dividing the horizontal sides of the rectangle in proportion h:1−h from the left.
    2)A horizontal line is drawn dividing the vertical sides of the rectangles in proportion v:1−v from the bottom up.
    3)These two lines divide the rectangle into four smaller rectangles.
    4)The upper left and the lower right sub-rectangles remain intact.
    5)The color of the other two rectangles is flipped (from black to white or from white to black) and now each of them is subject to the operation just performed on the bigger rectangle.
    6)This process continues (in principle) forever.

    Given a point in the original rectangle but not on the boundary of any rectangle that turns up in the process of painting, determine the color of the point.

    If anyone can please help. Thanks

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: rectangle problem using loops - alternating between intervals given a pt

    Quote Originally Posted by showtime3000 View Post
    If anyone can please help. Thanks
    Alright, what kind of help do you need? This is a school assignment, which we do not do "for" you here. We'll be glad to "help" once we know exactly what kind of help you need.

  3. #3
    Join Date
    Apr 2009
    Posts
    3

    Re: rectangle problem using loops - alternating between intervals given a pt

    I just need to know if there is a mathematical formula to solve this or just a logical formula (using if statements) to solve it. Is it possible to use a for loop within a while loop or just one or the other. Thanks

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: rectangle problem using loops - alternating between intervals given a pt

    The point of the exercise is that you have to work out how to do it. I suggest working a few examples by hand on paper to get a good understanding of the steps involved. Then you can decide the most appropriate loops to use.

    Whether you use a 'for' loop or a 'while' loop doesn't really make a great deal of difference - a 'for' loop is logically equivalent to a 'while' loop. Use whichever you are most comfortable with, but work out exactly how to do it by hand first.

    I cannot teach anybody anything, I can only make them think...
    Socrates
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured