Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Need help solving a problem

Name: Anonymous 2010-10-03 15:59

Hey

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…

Answer:
10 10

Name: Anonymous 2010-10-03 16:11

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.

Name: Anonymous 2010-10-03 16:13

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.

>>2-chan probably should too.

Name: Anonymous 2010-10-03 16:27

Yeah if the parts were entered in an order then it should be trivial.
They are entered randomly.

And I'm not giving up programming just cuz of one assigment I couldn't figure out.

Name: Anonymous 2010-10-03 16:28

This has to be a troll.

Just add up every second number and divide it by two to get the width. Then do the same for the height using the remaining numbers.

Name: Anonymous 2010-10-03 16:39

>>5
No and your method doesn't work.

Name: Anonymous 2010-10-03 16:44

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: Anonymous 2010-10-03 16:47

>>7
They are correct. Think more. You can rotate and push those rectangular parts anyway you want.

Name: Anonymous 2010-10-03 16:49

Lemme give you another example.
Keyboard:
1
5 2 4 2 5 3 4 3
Answer:
9 5

Name: Anonymous 2010-10-03 16:50

>>8
Each sheet is divided by two lines, though. This is skewing my interpretation of width and height.

Name: Anonymous 2010-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.

Name: Anonymous 2010-10-03 17:00

>>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]).

Name: Anonymous 2010-10-03 17:01

>>12
Maybe you should stop being a moron and read >>3.

Name: Anonymous 2010-10-03 17:01

Hello there, greenname.

Name: Anonymous 2010-10-03 17:07

>>12
You're an idiot.

Name: >>13 2010-10-03 17:10

I obviously meant to reply to >>11.

Name: Anonymous 2010-10-03 17:11

>>15
Agreed.
Dammint we are supposed to do this in less than 2 hours. As far as I know, nobody else done their assigments. How fucking hard can it be?

Also I gave ALL the instructions. Nothing less.

Name: Anonymous 2010-10-03 17:14

>>17
Considering that you got your answer by the second reply, your continued bafflement confuses me.

Name: Anonymous 2010-10-03 17:42

#!/usr/bin/python

for i in xrange(int(raw_input())):
    l = map(int, raw_input().split())
    cdr = [(l.pop(), l.pop()) for _ in range(4)]
    car = cdr.pop()

    print filter(None, [a == x and b + y or b == x and a + y or 0 for (a, b) in cdr for (x, y) in (car, car[::-1])])


You're welcome.

Name: Anonymous 2010-10-03 17:46

>>19
FIOC + LITHP? Pig disgusting.

Name: Anonymous 2010-10-03 20:09

>>19
But Guido doesn't want you to use functional programming!!!

Name: Anonymous 2010-10-03 21:12

>>19

what if
1
4 4 4 4 4 4 4 4

;D

Name: Anonymous 2010-10-03 21:14

>>1
>>9

1

I'm curious as to what the first line of the input does, if anything.

Name: Anonymous 2010-10-03 21:22

>>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.

Name: Anonymous 2010-10-04 0:30

Can't you see that we all use fucking sage, you shit-for-brains? It's a hint telling you to sage too.

Name: Anonymous 2010-12-10 10:21

<

Don't change these.
Name: Email:
Entire Thread Thread List