# Connect the Pipes

Each pipe shown on the left (A through I) connects to exactly one pipe on the right.

To hide the answer, I have put a curtain over the pipe crossings and grayed out the pipe colors on the right side.

When behind the curtain, each pipe travels straight to the leftmost side of its associated numbered gray pipe. In other words, the pipes have no bends or curves, other than the possible single bends just inside either side of the curtain.

Using the clues below, can you figure out where each pipe is connected? Note, there is only 1 possible solution.

1. Pipe A crosses either 2,3,4,5, or 6 pipes.
2. Pipe B crosses either 3,4,5, or 6 pipes.
3. Pipe C crosses at least 2 pipes.
4. Pipe D crosses at least 5 pipes.
5. Pipe E crosses at least 6 pipes.
6. Pipe F crosses at least 5 pipes.
7. Pipe G crosses at most 4 pipes.
8. Pipe H crosses at most 3 pipes.
9. Pipe I crosses at most 4 pipes.
10. There are at least 19 pipe crossings in total. *see bullet below
• Remember: When counting pipe crossings, be careful not to count each one twice. More specifically, if you add up Pipe A's crossings + Pipe B's crossings + ... + Pipe I's crossings, the sum you get will be double the actual total number of pipe crossings, since each crossing would be counted twice.

Answers can be in the form of

A-->1 B-->2 C-->3 D-->4 E-->5 F-->6 G-->7 H-->8 I-->9

Or, even better, assuming the left side is ordered A through I, just

123456789

If you solve this puzzle using only logic, and without using computer code, and then convince me of that using a detailed explanation, then I will award you 300 rep points, on top of the +10 up-vote and +15 for the accepted answer.

However, I doubt that it's feasible to solve without code, but I have been surprised many times before, so who knows.

• Does each pipe have a straight connection from letter to number? Or could a pipe have a bend in it, theoretically being able to cross another pipe twice? – JonTheMon May 21 '15 at 15:10
• 300 rep is a lot, someone will somehow manage to get it from you. It should be logically feasible! – ghosts_in_the_code May 21 '15 at 16:30
• @randal'thor i am slowly and methodically going through your explanation and bailey's explanation now. i am slowed down because i am at work, and multi-tasking. quite frankly, so far, i understand your logic better and quicker, as it is articulated better, but if hers is logically correct (I'm not done checking either yet), then I feel like I must put this forth to the community to decide. What do you think? – JLee May 21 '15 at 17:45
• @randal'thor Bailey was definitely first to answer correctly, and first to give a detailed solution, which does count for something. Also, both solutions seem logically correct to me, although a couple parts of hers are not 100% clear (but I think that is because her understanding is better than mine). She will get the check mark, but I will leave it up to the community to vote on which detailed explanation is better. But I guess I have to wait 2 days to put a bounty on it. – JLee May 21 '15 at 17:58
• Hope you don't mind I've edited out the computer tag. It might scare off people like me who know nothing about programming (I only looked at this question on the off-chance it might be something interesting, then realised it was doable without a computer). Also, maybe you could edit in what you said in comments that there's a unique solution? – Rand al'Thor May 21 '15 at 20:09

Okay, I've once again solved the problem, using only logic and Microsoft Paint! The acceptable solution I found is:

$482971356$

The following is a count of crossings per pipe and total:

Pipe A crosses $3$ pipes.
Pipe B crosses $6$ pipes.
Pipe C crosses $3$ pipes.
Pipe D crosses $5$ pipes.
Pipe E crosses $6$ pipes.
Pipe F crosses $5$ pipes.
Pipe G crosses $4$ pipes.
Pipe H crosses $3$ pipes.
Pipe I crosses $3$ pipes.
There are $19$ total pipe crossings.

Here are the logical steps to solving this problem.

Step 1: Pipes C and F

ghosts_in_the_code did a great job explaining why C and F are the only pipes that can connect to 1 and 2. Since their order doesn't matter in terms of crossing other pipes, and we're trying to maximize crossings, we attach F to 1 and C to 2 such that the pipes cross.

Step 2: Pipes G, H, and I

Since we're still trying to maximize for crossings, we want each of these pipes to have as many crossings as they can. Since these pipes have an "at-most" amount of crossings, there is a max point we can place them on the right side. We know that C and F are already in spots 1 and 2, and therefore can't possibly cross G, H, or I, so the two with an "at-most" of 4 crossings can be put in their highest possible spots as this setup would have none of the three crossing each other (leaving a maximum of four possible crossing pipes - A, B, D and E). For G, the highest point would be spot 3. For I, the highest point would be spot 5. However, H can't be placed at spot 4, since it has an "at-most" of 3 crossings, not 4. We can't place H at spot 6 or lower, or pipe I would cross pipe H and pipe I would have too many crossings. Because of this, we have to shift I down one spot so that H can be in spot 5 (which is its highest possible spot based on the above restrictions). Pipe I will therefore end up in spot 6.

Step 3: Pipe E

E needs to cross 6 pipes total. It already can't cross pipe C. If it were put at spot 8, it wouldn't cross pipe A either, and putting it at spot 7 would mean that pipe A would have to travel too far (a max of 6 crossings). This means that it can't cross pipe A either. There are only 6 pipes left, so pipe E has to cross all 6 of them, which it can't do in spots 4, 8, or 9, leaving only spot 7 (as B and D can travel to the two spots below it).

Step 4: The remainders

A can only go into one spot now, or else it would be above its maximum crossings (6). This connects A to 4. B can now only go in one spot, or else it would be above its maximum crossings (also 6). This means that B connects to 6. D is the remaining pipe, and it connects to the last remaining spot, which is 9.

• I've fixed my solution to properly answer the question! – Bailey M May 21 '15 at 16:17
• That is correct. I am looking forward to seeing how you did this using just logic. I am sure I will learn something! – JLee May 21 '15 at 16:20
• Let me see if I can clear it up! – Bailey M May 21 '15 at 17:06
• Microsoft Paint - how modern of you! I just used pen and paper ;-) – Rand al'Thor May 21 '15 at 17:38
• Uh-oh! I'm not sure I'm prepared to pick a fight with rand, especially on his home turf. :) – Bailey M May 21 '15 at 19:14

I've managed to solve it (without looking at any of the 3 existing answers) using only logic, pen, and paper! Here's the exact argument I used, in order. Note that I've sacrificed brevity for (hopefully!) clarity :-)

## First pass

Pipe A crosses either 2,3,4,5, or 6 pipes.

This is exactly equivalent to saying pipe A goes to 3,4,5,6, or 7 (since the number of pipes crossing A is the number of pipes above the one A goes to).

Pipe B crosses either 3,4,5, or 6 pipes.

So B can't go to 1 or 2 (since then it would only cross A and at most one other pipe), or to 9 (since then it would cross all pipes other than A).

Pipe D crosses at least 5 pipes.
Pipe E crosses at least 6 pipes.

So D/E can't go to 1 or 2 (since then it would cross at most A,B,C, and one/two others).

Pipe F crosses at least 5 pipes.

By symmetry with D, F can't go to 8 or 9.

Pipe G crosses at most 4 pipes.

So G can't go to 1 or 2 (since then it would cross all but at most one of A to F).

Pipe H crosses at most 3 pipes.
Pipe I crosses at most 4 pipes.

So H/I can't go to 1,2,3, or 4 (since then it would cross all but at most three of A to G/H).

Summing up our progress so far:

A goes to one of 3,4,5,6,7
B goes to one of 3,4,5,6,7,8
D goes to one of 3,4,5,6,7,8,9
E goes to one of 3,4,5,6,7
F goes to one of 1,2,3,4,5,6,7
G goes to one of 3,4,5,6,7,8,9
H goes to one of 5,6,7,8,9
I goes to one of 5,6,7,8,9

We notice that

C and F are the only pipes that can go to 1 or 2, so these two pairs must match. If F went to 2, the only pipes it could cross would be A,B,D,E - not at most five, so C goes to 2 and F goes to 1. With this new information, let's see what more we can deduce.

## Second pass

Pipe D crosses at least 5 pipes.
Pipe E crosses at least 6 pipes.

So D/E can't go to 3 or 4 (since then it would cross at most A,B,F, and one/two others - remember we now know C goes to 2).

Summing up again:

A goes to one of 3,4,5,6,7
B goes to one of 3,4,5,6,7,8
C goes to 2
D goes to one of 5,6,7,8,9
E goes to one of 5,6,7
F goes to 1
G goes to one of 3,4,5,6,7,8,9
H goes to one of 5,6,7,8,9
I goes to one of 5,6,7,8,9

We notice that

A,B,G are the only pipes that can go to 3 or 4. So at least one of A,B must go to one of 3,4 and therefore not cross either D or E. This means D/E can't go to 5 or 6 (since then it would cross at most {one of A,B}, F, and two/three others). Now the only place E can go is 7.

If neither A nor B crossed E, then E would cross at most five pipes. Contradiction, so one of A,B must go below E, i.e. to one of 8,9. By the restrictions we found in the first pass,

B goes to 8.

So

A and G pair up with 3 and 4.

Summing up again:

A goes to one of 3,4
B goes to 8
C goes to 2
D goes to one of 7,8,9
E goes to 7
F goes to 1
G goes to one of 3,4
H goes to one of 5,6,7,8,9
I goes to one of 5,6,7,8,9

We notice that

H and I are the only pipes that can go to 5 or 6, so these two pairs must match. If H went to 6, it would cross I and the pipes going to 7,8,9; contradiction, so H goes to 5 and I goes to 6. Now D is the only pipe that can go to 9.

The only pipes left to match up are {A,G} and {3,4}, which we can do using the final constraint: to get at least 19 crossings overall, we need A to go to 4 and G to 3. So the final answer is:

482971356.

382 971 456

So, pipe E is the hardest, since it has to cross all 4 above/below it, and 2 on the other side. We know that GHI don't want many crossings, so let's send C downwards, with 2 spots below it for crossing (7), and bring GHI up above it (456). F needs to cross a lot of pipes, so up to (1).

So, now let's just take the next 2 pipes (CD) and move them down to (89).

Now we have to deal with A and B. With only spots (23) left, A-3 can make it's 2 crossing, but B can't. (See picture 1).

So, since pipe C has a low threshold and B has a high cap, move C-8 to B-8 (6 crossings), and C-2 has 3. (See picture 2)

A - 2 crossings
B - 6 crossings
C - 3 crossings
D - 5 crossings
E - 6 crossings
F - 5 crossings
G - 3 crossings
H - 3 crossings
I - 3 crossings

But we only have 18 crossings. Well, that should be easy to fix, since we can cross A and G easily. (See picture 3)

So, final order:

482 971 356

And crossing counts:
A - 3 crossings
B - 6 crossings
C - 3 crossings
D - 5 crossings
E - 6 crossings
F - 5 crossings
G - 4 crossings
H - 3 crossings
I - 3 crossings

• +1 You got the correct answer, but your logical explanation is not very detailed. Great job, nonetheless. – JLee May 21 '15 at 18:04
• Maybe you can draw an image? It will be far more understandable. – Somnium May 21 '15 at 20:01