A Professor asked four students how long each of them had been studying.
One of the students replied: “We have all been studying a whole number of years, the sum of our years of studying is equal to the number of years you have been teaching and the product of our years of studying is 180”.
“I’m sorry”, replied the Professor after some thought, “but that doesn’t give me enough information”.
“Yes, you’re right”, agrees another of the students. “But if we told you that one of us were into double figures in our years of study, then you could surely answer your question”.
How long had each of the four been studying ?
(In reply to
solution by Charlie)
The list of ways to factor 180 into 4 factors was produced from sorting the output of the following program by total:
DECLARE SUB factorit (n!, lev!)
DIM SHARED fact(4)
n = 180
OPEN "factors.txt" FOR OUTPUT AS #1
factorit n, 1
CLOSE
END
SUB factorit (n, lev)
IF lev = 1 THEN strt = 1: ELSE strt = fact(lev - 1)
IF lev = 4 THEN
IF strt <= n AND n >= fact(lev - 1) THEN
strt = n:
ELSE
EXIT SUB
END IF
END IF
FOR i = strt TO n
IF n \ i = n / i THEN
fact(lev) = i
IF lev = 4 THEN
tot = 0
FOR j = 1 TO 4
PRINT #1, USING "###"; fact(j);
IF j < 4 THEN PRINT #1, "+"; : ELSE PRINT #1, "=";
tot = tot + fact(j)
NEXT
PRINT #1, tot
ELSE
factorit n / i, lev + 1
END IF
END IF
NEXT
END SUB
|
Posted by Charlie
on 2003-04-28 03:59:00 |