5 Girls (named Alice, Betty, Carol, Diane, Emily) visit a mall to shop. They come upon a clothing shop and they decide to buy clothing.
But, for some strange reason, different colored shirts cost different amounts, which now came in increments of 10 dollars. (Every shirt of the same color costs the same amount.) This store doesn't carry very many shirts; the most expensive one is 50 dollars, and they only come in red, green, blue, yellow, and orange.
Each girl goes into the store and finds two different shirts. No two girls got the same pair of shirts, and no girl got a shirt for free. It ended up that each color shirt was bought exactly twice.
Using the following clues, can you figure out the two colors of shirts each girl bought, and how much each color bought, as well as how much each girl spent?
1) When the 5 girls were comparing their purchases, they found that Diane spent the most money, 2 girls tied for second most money spent, and the other 2 girls spent the same amount of money as well.
2) When Carol bought the blue shirt, she was mad that the it was more expensive than the 10dollar price it was last week, and didn't buy the green shirt because of this.
3) Diane's and Emily's different styles resulted in them not buying any shirts the same color as each other's.
4) Alice and Emily both decided not to buy the orange shirt, but instead, Alice went with Carol to pick out the same color shirt to buy, noting that it didn't cost 20 dollars like last week.
5) As Betty was waiting to buy a red shirt (which she did end up buying), she saw Carol buy a shirt that cost 40 dollars.
This program:
DECLARE SUB varyGirl (which!)
DECLARE SUB permute (a$)
CLS
DIM SHARED colr$, gs$(2, 5), total(5)
colr$ = "rgbyo"
OPEN "shirts.txt" FOR OUTPUT AS #2
FOR costs = 1 TO 120
varyGirl 1
permute colr$
NEXT
CLOSE
SUB permute (a$)
DEFINT AZ
x$ = ""
FOR i = LEN(a$) TO 1 STEP 1
l$ = x$
x$ = MID$(a$, i, 1)
IF x$ < l$ THEN EXIT FOR
NEXT
IF i = 0 THEN
FOR j = 1 TO LEN(a$) \ 2
x$ = MID$(a$, j, 1)
MID$(a$, j, 1) = MID$(a$, LEN(a$)  j + 1, 1)
MID$(a$, LEN(a$)  j + 1, 1) = x$
NEXT
ELSE
FOR j = LEN(a$) TO i + 1 STEP 1
IF MID$(a$, j, 1) > x$ THEN EXIT FOR
NEXT
MID$(a$, i, 1) = MID$(a$, j, 1)
MID$(a$, j, 1) = x$
FOR j = 1 TO (LEN(a$)  i) \ 2
x$ = MID$(a$, i + j, 1)
MID$(a$, i + j, 1) = MID$(a$, LEN(a$)  j + 1, 1)
MID$(a$, LEN(a$)  j + 1, 1) = x$
NEXT
END IF
END SUB
DEFSNG AZ
SUB varyGirl (which)
DIM t(5)
FOR shirt1 = 1 TO 4
gs$(1, which) = MID$(colr$, shirt1, 1)
FOR shirt2 = shirt1 + 1 TO 5
gs$(2, which) = MID$(colr$, shirt2, 1)
total(which) = shirt1 + shirt2
SELECT CASE which
CASE 1
IF gs$(1, which) = "o" OR gs$(2, which) = "o" THEN GOTO notThis
CASE 2
IF gs$(1, which) <> "r" AND gs$(2, which) <> "r" THEN GOTO notThis
CASE 3
IF gs$(1, which) <> "b" AND gs$(2, which) <> "b" THEN GOTO notThis
IF gs$(1, which) = "b" AND shirt1 = 1 OR gs$(2, which) = "b" AND shirt2 = 1 THEN GOTO notThis
IF gs$(1, which) = "g" OR gs$(2, which) = "g" THEN GOTO notThis
IF gs$(1, which) <> gs$(1, 1) AND gs$(1, which) <> gs$(2, 1) AND gs$(2, which) <> gs$(1, 1) AND gs$(2, which) <> gs$(2, 1) THEN GOTO notThis
IF gs$(1, which) = gs$(1, 1) OR gs$(1, which) = gs$(2, 1) THEN
IF shirt1 = 2 THEN GOTO notThis
ELSE
IF shirt2 = 2 THEN GOTO notThis
END IF
IF shirt1 <> 4 AND shirt2 <> 4 THEN GOTO notThis
CASE 5
IF gs$(1, which) = "o" OR gs$(2, which) = "o" THEN GOTO notThis
END SELECT
FOR j = 1 TO which  1
IF gs$(1, j) = gs$(1, which) AND gs$(2, j) = gs$(2, which) THEN GOTO notThis
NEXT
IF which < 5 THEN
varyGirl which + 1
ELSE
GOSUB evaluate
END IF
notThis:
NEXT
NEXT
EXIT SUB
evaluate:
IF total(4) > total(1) AND total(4) > total(2) AND total(4) > total(3) AND total(4) > total(5) THEN
t(1) = total(1): t(2) = total(2): t(3) = total(3): t(4) = total(5)
DO
fl = 0
FOR i = 1 TO 3
IF t(i) > t(i + 1) THEN SWAP t(i), t(i + 1): fl = 1
NEXT
LOOP UNTIL fl = 0
gs1$ = gs$(1, 1) + gs$(1, 2) + gs$(1, 3) + gs$(1, 4) + gs$(1, 5)
gs2$ = gs$(2, 1) + gs$(2, 2) + gs$(2, 3) + gs$(2, 4) + gs$(2, 5)
IF t(3) = t(4) AND t(1) = t(2) THEN
IF gs$(1, 4) <> gs$(1, 5) AND gs$(1, 4) <> gs$(2, 5) AND gs$(2, 4) <> gs$(1, 5) AND gs$(2, 4) <> gs$(2, 5) THEN
PRINT #2,
PRINT #2, colr$
PRINT #2, gs1$
PRINT #2, gs2$
FOR g = 1 TO 5
PRINT #2, 10 * total(g);
NEXT
PRINT #2,
END IF
END IF
END IF
RETURN
END SUB
seems to produce 21 solutions:
rgybo
grrbg
boboy
60 60 50 90 50
rygbo
rryby
bobog
50 60 60 90 50
rygbo
yrrby
bobog
60 60 50 90 50
yorbg
yoory
brbbg
50 50 60 70 60
yrgbo
grybr
bobog
70 70 50 90 50
yrobg
yrroy
bobbg
50 50 60 70 60
yrobg
yryor
gobgb
60 50 50 80 60
yrobg
rryoy
bobbg
60 50 50 70 60
gorby
goorg
brbby
50 50 60 70 60
grbyo
grbyr
yoyob
50 70 70 90 50
grbyo
rrbbg
boyoy
50 70 70 80 50
groby
grrog
bobby
50 50 60 70 60
grybo
grybr
boboy
50 70 70 90 50
grybo
rryyg
yobob
50 70 70 80 50
ogybr
goobg
brbry
60 60 50 90 50
ogybr
ygobg
brbry
70 70 50 90 50
orgby
grobr
bybyg
70 70 50 90 50
orybg
yrobr
bgbgy
70 70 50 90 50
oygbr
yooby
brbrg
60 60 50 90 50
oygbr
gyoby
brbrg
70 70 50 90 50
rbgyo
rrbyb
yoyog
50 60 60 90 50

where the first line of each group indicates the colors in order of increasing price, from $10 to $50. The second line shows each girls less expensive shirt (Alice to Emily order) and the third line shows each girls more expensive shirt (same order). The bottom line shows the total each girl spent (Alice to Emily again).
Spot checking, I don't see any discrepancies with the clues.

Posted by Charlie
on 20031107 15:43:05 