I really need help on my programming assignment. I’ve been thinking about it for hours and just can’t come up with an algorithm to solve it. It’s a mind fuck. Whatever I think of doesn’t work. I also have to give it away in 2 hours.
Here it is:
There are n (1 ≤ n ≤ 100) sheets of paper with various dimensions. Every sheet is divided by 2 lines into 4 rectangular parts. The dimensions (length and width) for those 4 parts are known (entered via console). Find the dimensions of each sheet of paper.
All numbers are integers.
E.g.
From keyboard:
1 // one sheet of paper
3 2 8 3 7 2 8 7 // dimensions for each part. Part1 would be three units long and two units wide ; etc…
Mm, homework. Well I've been away from /prog/ for about a day so I'm feeling generous.
You want (r1.x + r2.x = r3.x + r4.x) && (r1.y + r2.y = r3.y + r4.y)
Just rearrange the rectangles so that happens. It's easy enough to permute through each possible layout of an array.
Not particularly hard. Take any piece (for example, 3 2), find its two neighbours based on the matching sides (8 3 and 7 2), add up the non-matching sides (8 + 2 and 7 + 3) to get the sides you're looking for.
If this is a ``mind fuck'', you should probably give up programming.
Shouldn't it be 3 2 3 8 7 2 7 8? The way you listed the dimensions doesn't make sense if you are taking the first number as the height and the second as the width.
Name:
Anonymous2010-10-03 16:47
>>7
They are correct. Think more. You can rotate and push those rectangular parts anyway you want.
Name:
Anonymous2010-10-03 16:49
Lemme give you another example.
Keyboard:
1
5 2 4 2 5 3 4 3
Answer:
9 5
>>8
Each sheet is divided by two lines, though. This is skewing my interpretation of width and height.
Name:
Anonymous2010-10-03 16:56
>>10
Thats the mind fuck. Maybe I should just do a trivial version of this program and then put on cool face when asked why it doesn't work with other values.
>>8
If that is the case how do I know which ones are the width and which ones are the height? I could make a 5x15 rectangle with the dimensions given (e.g. [2 7], [2 8], [3 7], [3 8]).
>>22
Still gives you the right answer, it just repeats itself a bit. Depending on the input it can return [a, b], [a, a, b, b], or [a, a, a, a, a, a]. If you want it to always return [a, b], you'll need to add some breaks, which will necessarily damage concision and therefore make the code harder to read.