RosettaCodeData/Task/Dinesmans-multiple-dwelling.../FutureBasic/dinesmans-multiple-dwelling...

38 lines
1.2 KiB
Plaintext

// Dinesmans multiple-dwelling problem
//https://rosettacode.org/wiki/Dinesman%27s_multiple-dwelling_problem
short Baker,Cooper,Fletcher,Miller,Smith
short LoopCount
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 Baker <> 4 && Cooper <> 0 && Miller <> Cooper
IF Fletcher <> 0 && Fletcher <> 4 && ABS(Smith-Fletcher)<>1 && ABS(Fletcher-Cooper)<>1
IF Baker<>Cooper and Baker<>Fletcher && Baker<>Miller and ¬
Baker<>Smith and Cooper<>Fletcher and Cooper<>Miller and ¬
Cooper<>Smith and Fletcher<>Miller and Fletcher<>Smith and ¬
Miller<>Smith
LoopCount ++
if LoopCount = 4
PRINT "Baker lives on floor " ; Baker + 1
PRINT "Cooper lives on floor " ; Cooper + 1
PRINT "Fletcher lives on floor " ; Fletcher + 1
PRINT "Miller lives on floor " ; Miller + 1
PRINT "Smith lives on floor " ; Smith + 1
end if
END IF
END IF
END IF
NEXT Smith
NEXT Miller
NEXT Fletcher
NEXT Cooper
NEXT Baker
handleevents