How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the ERRE programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the ERRE programming language

Table of Contents

Problem Statement

Solve Dinesman's multiple dwelling problem but in a way that most naturally follows the problem statement given below. Solutions are allowed (but not required) to parse and interpret the problem text, but should remain flexible and should state what changes to the problem text are allowed. Flexibility and ease of expression are valued. Examples may be be split into "setup", "problem statement", and "output" sections where the ease and naturalness of stating the problem and getting an answer, as well as the ease and flexibility of modifying the problem are the primary concerns. Example output should be shown here, as well as any comments on the examples flexibility.

Baker, Cooper, Fletcher, Miller, and Smith live on different floors of an apartment house that contains only five floors.

Where does everyone live?

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the ERRE programming language

Source code in the erre programming language

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

  

You may also check:How to resolve the algorithm ABC problem step by step in the Simula programming language
You may also check:How to resolve the algorithm Comments step by step in the Io programming language
You may also check:How to resolve the algorithm Deconvolution/2D+ step by step in the Julia programming language
You may also check:How to resolve the algorithm O'Halloran numbers step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Plasma effect step by step in the XPL0 programming language