(In reply to
Solution by Penny)
While Visual Basic is great for making GUI applications, and it is good programming practice to declare all your variables, sometimes this can be a hindrance to an easy understanding of the programs. I think QuickBasic comes closer to what I think someone has asked for: pseudocode. And in DOS, the following QB program goes through all the possibilities in less than 4/10 of a second:
timeStart = TIMER
FOR d = 1 TO 9
FOR e = 1 TO 9
IF e <> d THEN
FOR f = 1 TO 9
IF f <> d AND f <> e THEN
t = d MOD 2 + e MOD 2 + f MOD 2
IF t = 0 OR t = 3 THEN
FOR g = 1 TO 9
IF g <> d AND g <> e AND g <> f THEN
FOR h = 1 TO 9
IF h <> d AND h <> e AND h <> f AND h <> g THEN
FOR i = 1 TO 9
IF i <> d AND i <> e AND i <> f AND i <> g AND i <> h THEN
t = g MOD 2 + h MOD 2 + i MOD 2
IF t = 0 OR t = 3 THEN
FOR a = 1 TO 9
IF a <> d AND a <> e AND a <> f AND a <> g AND a <> h AND a <> i THEN
FOR b = 1 TO 9
IF b <> d AND b <> e AND b <> f AND b <> g AND b <> h AND b <> i AND b <> a THEN
c = 45 - a - b - d - e - f - g - h - i
IF a + b + c = 2 * (d + e + f) THEN
IF a + d + g = 2 * (b + e + h) THEN
IF c + f + i + 2 * (g + h + i) = 45 THEN
PRINT a, b, c
PRINT d, e, f
PRINT g, h, i
END IF
END IF
END IF
END IF
NEXT b
END IF
NEXT a
END IF
END IF
NEXT i
END IF
NEXT h
END IF
NEXT g
END IF
END IF
NEXT f
END IF
NEXT e
NEXT d
PRINT TIMER - timeStart
The results being:
9 5 8
3 1 7
4 2 6
.390625
the decimal fraction being the clock execution time in seconds.
|
Posted by Charlie
on 2004-05-15 15:47:09 |