Since these two rectangles share the same width, the combined rectangle must have 3x the height of the orange one, making the height of the yellow rectangle 9.
This gives a side length of 12 and an area of 144.
This argument thus teaches us even more, namely: the configuration of the four equal-area rectangles orange, yellow, green, pink has the special property that if you widen it to get a square, the extra piece you add also has equal area.
And good sources of such puzzles. I am hoping to get my school age kid interested in these.
Let y be the horizontal width of the bottom-left-most rectangle, and x be the horizontal width of each of the rectangles directly adjacent on the right to the first one, so that the rectangle marked at the top right as having a vertical width of 3 now has a horizontal width of x + y.
Then, the area of each rectangle is 3x + 3y, as all rectangles have the same area.
It follows that the vertical width of the bottom-left-most rectangle is (3x + 3y)/y, and that the vertical width of each of the two stacked rectangles is (3x + 3y)/x.
Note now that the stacked rectangles have the same horizontal width, and therefore must have the same vertical width. Thus, the vertical width of the bottom-left-most rectangle must be 2 times the vertical width of each of these stacked rectangles, so (3x + 3y)/y = 2*(3x + 3y)/x.
From this, we get 1/y = 2/x (noting that 3x + 3y cannot be be zero), so x = 2y.
This means that the vertical width of the bottom-left-most rectangle is then (3(2y) + 3y)/y = (6y + 3y)/y = 9y/y = 9.
Therefore, the entire left side width is 3 + 9, or 12 units. Since the overall shape is a square, the entire square's area must be 144 square units.
> Note now that the stacked rectangles have the same horizontal width, and therefore must have the same vertical width.
This is the most important thing to use and what, were it included in the system in the OP, would simplify it quite a bit with not much more complexity. But the value of the approach I guess is the use of only pre-defined constraints.
Another route is to use that h_1 * (x+y) = 3A = 9 * (x+y) so h_1 = 9
I am not very good at math so I might of done something terribly wrong but the theory is. The rectangles have equal area, area is length * width, items with the same L + W will have the same area(this is where I might have gone wrong), create a structure where all rectangles are forced to have the same L + W.
There are various approaches; Solvespace uses a modified Newton's method and was written in C++ making use of just the Eigen lib.
Unfortunately yeah that’s not right. Think of a 1x3 and a 2x2.
from PIL import Image
from math import ceil
return 200 <= p <= 255 and 100 <= p <= 170 and 0 <= p <= 50
img = Image.open("p9-problem.png")
w, h = img.size
o = (sum(is_orange(img.getpixel((w // 2, y))) for y in range(h)))
T = (sum(p[:3] != (p, p, p) for p in (img.getpixel((w // 2, i)) for i in range(h))))
L = ceil((T/o)*given)
So yeah... complete luck was had here.
Of course for more complicated layouts this method won't work as well, but at least for this simple one this method seems easier.
- if you want to check that a complex system of rules has a solution, then you can translate that into a SAT problem and run a SAT solver (https://codingnest.com/modern-sat-solvers-fast-neat-underuse...)
- if the problem is small enough, you could run an exhaustive search of options - in that case it really doesn't matter how you encode the rules, it could be any function returning a bool
- if you're trying to prove some invariant about the game, look at languages like Coq - they should help you
Fwiw, it’s a social deduction game where each role gains info or has an ability and each night they vote to kill someone and the wherewolfs kill someone. The game ends when the wherewolfs are dead or when they equal the number of villagers left alive. I’m pretty sure at a certain number of players regardless of roles if the villagers act in a certain way they win regardless of input from the wherewolves.
// yellow+pink+green area = 3 x orange)
y * o = 3 (3 * o)
y = 9
Side of square = 9+3 = 12. So area is 144.
e = P[i]-P[j]
e = P[j]-P[i]
That would have made the code more obvious to read I think?
EDIT: Just realized these labels are probably meant to represent areas of the colored shapes ... orange, yellow, pink, blue and green?