Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rosetta Code Challenges
#5
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.

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 + ...
Reply


Messages In This Thread
Rosetta Code Challenges - by bplus - 04-26-2022, 09:17 PM
RE: Rosetta Code Challenges - by SierraKen - 04-27-2022, 04:36 AM
RE: Rosetta Code Challenges - by bplus - 04-27-2022, 01:38 PM
RE: Rosetta Code Challenges - by bplus - 10-30-2022, 04:41 AM
RE: Rosetta Code Challenges - by bplus - 10-31-2022, 05:40 PM
RE: Rosetta Code Challenges - by SpriggsySpriggs - 10-31-2022, 07:24 PM
RE: Rosetta Code Challenges - by bplus - 10-31-2022, 09:09 PM
RE: Rosetta Code Challenges - by MasterGy - 10-31-2022, 09:33 PM
RE: Rosetta Code Challenges - by bplus - 10-31-2022, 09:43 PM
RE: Rosetta Code Challenges - by bplus - 11-01-2022, 02:07 AM
RE: Rosetta Code Challenges - by bplus - 11-01-2022, 12:19 PM
RE: Rosetta Code Challenges - by bplus - 11-05-2022, 04:57 AM
RE: Rosetta Code Challenges - by CharlieJV - 11-05-2022, 03:10 PM
RE: Rosetta Code Challenges - by bplus - 11-05-2022, 04:02 PM
RE: Rosetta Code Challenges - by bplus - 09-10-2023, 02:40 PM
RE: Rosetta Code Challenges - by bplus - 04-29-2024, 03:03 AM



Users browsing this thread: 2 Guest(s)