I ended up looking the official answer book and they actually used a similar method. They managed to do it in one while loop by properly working down the exceptions.
I ended up looking the official answer book and they actually used a similar method. They managed to do it in one while loop by properly working down the exceptions.
If you think about it, the string you need to create the sides of a rectangle is always TopWidth - 2 in width(you subtract 2 because it is "up to but not including" the character representing the sides). You can use this to create rectangles of arbitrary dimensions pretty easily (especially if you use a string object to add the spaces in).
Normally in graphical programming, you need at least 4 values to describe a rectangle - x , y , width , height. Some other ways would be - top , right , bottom , left ; or 2 points - (x, y) , (x, y). All these contain the same information as the first, it's just separate ways you can look at it.
If your looking for a challenge (?), a good one would be to work out a way to represent the x and y components of your rectangle. In other words, how would you make the rectangle print anywhere on the console? Just a thought .
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Do you mean simple/ primitive values? I mean technically you could do it with one large value if you just stuffed everything into a 64 bit integer type or something lol, but I'm guessing this doesn't use a trick like that?
Hrm.. Off the top of my head I was thinking you could maybe use something like the hypotenuse formula, but I don't think that's it as you still need 2 values for the coordinates I believe.
I'm stumped, I'll have to think a while on it.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
(x2-x1)/x1, (y2-y1)/y1, (x2-x1)^2+(y2-y1)^2
Does that work? The ratio of each side to its position, and the length of the diagonal (squared). I can't quite work out how you'd get the position from that, but it seems like enough information. You might need an extra bit to differentiate rectangles in quadrant 1 from quadrant 3 and the like, but you can use the sign bit of the last value.
Last edited by King Mir; 09-02-2014 at 08:45 PM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Nope, that's four.
I don't think that gives you what you need to reconstruct it...I tried, but couldn't seem to work out the unknowns.
So there were two methods I was thinking of, specifically. I'll reveal the hardest first. Imagine two circles centered at the origin and of arbitrary radii. Each circle defines a corner of the rectangle. Now rotate a ray (also centered at the origin) some angle and project it past both circles, right through one of the corners. Substending lines in both directions yields the original rectangle. It's convoluted, and the math is expensive, but it does indeed use just three values: r1, r2, t1.
The key thing to realize here is that rectangles have certain properties that might be considered "implicit" information. Like we can assume that the sides will be at right angles, and moreover that the shape won't be rotated from the x and y planes.
As a matter of fact, we can do even better: turns out, it can be done with just two values! Anyone?
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.