r/prolog • u/Healthy-Policy-8400 • Jun 11 '21
geometric prolog problem
Given n rectangular parallelograms with dimensions a1 x b1, a2 x b2, ..., an x bn (all dimensions are positive integers) and a positive integer A, an interesting problem is to decide whether it is possible to place the n rectangular parallelograms inside a square box A x A, without overlaps. The rectangular parallelograms are allowed to rotate. It is easy to see that if there is such a placement, then there is one in which the sides of all the rectangles and the square frame are either perpendicular to each other or parallel to each other. Therefore the rotations that may be required are only 90 degrees.
Write a program in Prolog to solve the above problem. In particular, define a predicate rectanglePacking(L,A), which will hold true if L is a list consisting of terms of the form ai * bi, where ai, bi are positive integers representing the dimensions of a rectangular parallelogram, A is also a positive integer representing the length of the side of the square frame, and the rectangular parallelograms corresponding to the elements of the list L can be placed in the square frame A x A without overlapping. For example, p([2*2, 1*2, 1*1, 1*2], 3) is true
(
2
4
u/rpiirp Jun 11 '21
What's the difference between a rectangular parallelogram and a rectangle?