RosettaCodeData/Task/Dinesmans-multiple-dwelling-problem/ERRE/dinesmans-multiple-dwelling-problem.erre
2016-12-05 23:44:36 +01:00

48 lines
2 KiB
Text

PROGRAM DINESMAN
BEGIN
! Floors are numbered 0 (ground) to 4 (top)
! "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"
! "Baker does not live on the top floor":
stmt2$="Baker<>4"
! "Cooper does not live on the bottom floor":
stmt3$="Cooper<>0"
! "Fletcher does not live on either the top or the bottom floor":
stmt4$="Fletcher<>0 AND Fletcher<>4"
! "Miller lives on a higher floor than does Cooper":
stmt5$="Miller>Cooper"
! "Smith does not live on a floor adjacent to Fletcher's":
stmt6$="ABS(Smith-Fletcher)<>1"
! "Fletcher does not live on a floor adjacent to Cooper's":
stmt7$="ABS(Fletcher-Cooper)<>1"
FOR Baker=0 TO 4 DO
FOR Cooper=0 TO 4 DO
FOR Fletcher=0 TO 4 DO
FOR Miller=0 TO 4 DO
FOR Smith=0 TO 4 DO
IF Baker<>4 AND Cooper<>0 AND Miller>Cooper THEN
IF Fletcher<>0 AND Fletcher<>4 AND ABS(Smith-Fletcher)<>1 AND ABS(Fletcher-Cooper)<>1 THEN
IF 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 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)
END IF
END IF
END IF
END FOR ! Smith
END FOR ! Miller
END FOR ! Fletcher
END FOR ! Cooper
END FOR ! Baker
END PROGRAM