This was given at Rosetta Code as a problem similar to Zebra Puzzle but it's a pretty straight forward check all possible see what sticks.
Only one solution sticks, Smith gets the dreaded first floor.
The other related problem, 12 Statements, is giving me more trouble but it was past my bedtime. Maybe today I can figure it out.
https://rosettacode.org/wiki/Twelve_statements
Dinesman Multi-Dwelling
Code: (Select All)
_Title "Dinemans Multi_Dwelling - Rosetta Code" ' b+ found 2022-10-30 too easy
' ref: https://rosettacode.org/wiki/Dinesman%27s_multiple-dwelling_problem
'Baker does not live on the top floor.
'Cooper does not live on the bottom floor.
'Fletcher does not live on either the top or the bottom floor.
'Miller lives on a higher floor than does Cooper.
'Smith does not live on a floor adjacent to Fletcher's.
'Fletcher does not live on a floor adjacent to Cooper's
' nim soln same as Ada:
'Baker lives on floor 3
'Cooper lives on floor 2
'Fletcher lives on floor 4
'Miller lives on floor 5
'Smith lives on floor 1
' b <> 5 ' 1 to 4
' c <> 1 ' 2 to 5
' f <> 1 and f <> 5 ' 2 to 4
' m > c then c <> 5 m <> 1
' s <> f + 1 and s <> f - 1
' f <> c + 1 and f <> c - 1
'everyone seems to go from 1 to 5 is there another solution going from 5 to 1? no because the other codes dont quit when one is found
For b = 4 To 1 Step -1
For c = 4 To 2 Step -1
If c <> b Then
For f = 4 To 2 Step -1
If (f <> c) And (f <> b) Then
For m = 5 To 2 Step -1
If (m <> f) And ((m <> c) And (m <> b)) Then
For s = 5 To 1 Step -1
If ((s <> m) And (s <> f)) And ((s <> c) And (s <> b)) Then
If (f <> c + 1) And (f <> c - 1) Then
If s <> f + 1 And s <> f - 1 Then
If m > c Then
Print "Baker ="; b
Print "Cooper ="; c
Print "Fletcher ="; f
Print "Miller ="; m
Print "Smith ="; s
End If
End If
End If
End If
Next
End If
Next
End If
Next
End If
Next
Next
Print " End of Run"
Only one solution sticks, Smith gets the dreaded first floor.
The other related problem, 12 Statements, is giving me more trouble but it was past my bedtime. Maybe today I can figure it out.
https://rosettacode.org/wiki/Twelve_statements
b = b + ...