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

19 lines
1.0 KiB
Plaintext

for baler = 1 to 4 ' can not be in room 5
for cooper = 2 to 5 ' can not be in room 1
for fletcher = 2 to 4 ' can not be in room 1 or 5
for miller = 1 to 5 ' can be in any room
for smith = 1 to 5 ' can be in any room
if baler <> cooper and fletcher <> miller and miller > cooper and abs(smith - fletcher) > 1 and abs(fletcher - cooper) > 1 then
if baler + cooper + fletcher + miller + smith = 15 then ' that is 1 + 2 + 3 + 4 + 5
rooms$ = baler;cooper;fletcher;miller;smith
print "baler: ";baler;" copper: ";cooper;" fletcher: ";fletcher;" miller: ";miller;" smith: ";smith
end
end if
end if
next smith
next miller
next fletcher
next cooper
next baler
print "Can't assign rooms" ' print this if it can not find a solution