There are three families each with two sons and two daughters. In how many ways can these young people be married so that each couple includes one member of each gender, no couple is brother and sister, and there are no singles left over?
If we number the boys from 1 - 6, so that 1 & 2 are in the same family, 3 & 4 in a second family and 5 & 6 in the last family, and similarly number the girls from 1 - 6 in the same fashion, the following program tracks all the possible ways of assigning the girls to the boys:
OPEN "noincest.txt" FOR OUTPUT AS #2
FOR b1 = 3 TO 6
taken(b1) = 1
FOR b2 = 3 TO 6
IF taken(b2) = 0 THEN
taken(b2) = 1
FOR b3 = 1 TO 6
IF taken(b3) = 0 AND b3 <> 3 AND b3 <> 4 THEN
taken(b3) = 1
FOR b4 = 1 TO 6
IF taken(b4) = 0 AND b4 <> 3 AND b4 <> 4 THEN
taken(b4) = 1
FOR b5 = 1 TO 4
IF taken(b5) = 0 THEN
taken(b5) = 1
FOR b6 = 1 TO 4
IF taken(b6) = 0 THEN
taken(b6) = 1
ct = ct + 1
PRINT #2, b1; b2; b3; b4; b5; b6
taken(b6) = 0
END IF
NEXT b6
taken(b5) = 0
END IF
NEXT b5
taken(b4) = 0
END IF
NEXT b4
taken(b3) = 0
END IF
NEXT b3
taken(b2) = 0
END IF
NEXT b2
taken(b1) = 0
NEXT b1
PRINT ct
It lists a count of 80, and produces a file of the assignments (choices?) of the 6 boys in turn:
3 4 5 6 1 2
3 4 5 6 2 1
3 4 6 5 1 2
3 4 6 5 2 1
3 5 1 6 2 4
3 5 1 6 4 2
3 5 2 6 1 4
3 5 2 6 4 1
3 5 6 1 2 4
3 5 6 1 4 2
3 5 6 2 1 4
3 5 6 2 4 1
3 6 1 5 2 4
3 6 1 5 4 2
3 6 2 5 1 4
3 6 2 5 4 1
3 6 5 1 2 4
3 6 5 1 4 2
3 6 5 2 1 4
3 6 5 2 4 1
4 3 5 6 1 2
4 3 5 6 2 1
4 3 6 5 1 2
4 3 6 5 2 1
4 5 1 6 2 3
4 5 1 6 3 2
4 5 2 6 1 3
4 5 2 6 3 1
4 5 6 1 2 3
4 5 6 1 3 2
4 5 6 2 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