RosettaCodeData/Task/Dinesmans-multiple-dwelling.../BBC-BASIC/dinesmans-multiple-dwelling...

49 lines
1.8 KiB
Plaintext

REM Floors are numbered 0 (ground) to 4 (top)
REM "Baker, Cooper, Fletcher, Miller, and Smith live on different floors":
stmt1$ = "Baker<>Cooper AND Baker<>Fletcher AND Baker<>Miller AND " + \
\ "Baker<>Smith AND Cooper<>Fletcher AND Cooper<>Miller AND " + \
\ "Cooper<>Smith AND Fletcher<>Miller AND Fletcher<>Smith AND " + \
\ "Miller<>Smith"
REM "Baker does not live on the top floor":
stmt2$ = "Baker<>4"
REM "Cooper does not live on the bottom floor":
stmt3$ = "Cooper<>0"
REM "Fletcher does not live on either the top or the bottom floor":
stmt4$ = "Fletcher<>0 AND Fletcher<>4"
REM "Miller lives on a higher floor than does Cooper":
stmt5$ = "Miller>Cooper"
REM "Smith does not live on a floor adjacent to Fletcher's":
stmt6$ = "ABS(Smith-Fletcher)<>1"
REM "Fletcher does not live on a floor adjacent to Cooper's":
stmt7$ = "ABS(Fletcher-Cooper)<>1"
FOR Baker = 0 TO 4
FOR Cooper = 0 TO 4
FOR Fletcher = 0 TO 4
FOR Miller = 0 TO 4
FOR Smith = 0 TO 4
IF EVAL(stmt2$) IF EVAL(stmt3$) IF EVAL(stmt5$) THEN
IF EVAL(stmt4$) IF EVAL(stmt6$) IF EVAL(stmt7$) THEN
IF EVAL(stmt1$) THEN
PRINT "Baker lives on floor " ; Baker
PRINT "Cooper lives on floor " ; Cooper
PRINT "Fletcher lives on floor " ; Fletcher
PRINT "Miller lives on floor " ; Miller
PRINT "Smith lives on floor " ; Smith
ENDIF
ENDIF
ENDIF
NEXT Smith
NEXT Miller
NEXT Fletcher
NEXT Cooper
NEXT Baker
END