Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #59514 > unrolled thread

Rosetta Code: Dinesman's multiple-dwelling problem

Started by"Robert L." <No_spamming@noWhere_7073.org>
First post2017-05-18 19:24 +0000
Last post2017-05-18 21:57 +0000
Articles 2 — 1 participant

Back to article view | Back to comp.lang.forth


Contents

  Rosetta Code: Dinesman's multiple-dwelling problem "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-18 19:24 +0000
    Re: Rosetta Code: Dinesman's multiple-dwelling problem "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-18 21:57 +0000

#59514 — Rosetta Code: Dinesman's multiple-dwelling problem

From"Robert L." <No_spamming@noWhere_7073.org>
Date2017-05-18 19:24 +0000
SubjectRosetta Code: Dinesman's multiple-dwelling problem
Message-ID<ofkse0$1smi$1@gioia.aioe.org>
> The problem
> 
>   Baker, Cooper, Fletcher, Miller, and Smith live on different
>   floors of an apartment house that contains only five floors.
> 
>   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. 
> 
> Where does everyone live?

(use srfi-1)

(define (any. lst fun) (any fun lst))

(let* ((floors '(0 1 2 3 4))
       (b (delete 4 floors))
       (c (delete 0 floors))
       (f (lset-difference = floors '(0 4)))
       (m floors)
       (s floors)
       (answer
         (any. b (lambda(B)
           (any. m (lambda(M)
             (any. c (lambda(C)
               (any. f (lambda(F)
                 (any. s (lambda(S)
                   (and
                     (> M C)
                     (< 1 (abs (- S F)))
                     (< 1 (abs (- C F)))
                     (let ((result (list B C F M S)))
                       (and
                         (equal? (delete-duplicates result) result)
                         result)))))))))))))))
  (for-each
    print
    '(Baker Cooper Fletcher Miller Smith) (circular-list ": ") answer))

Baker: 2
Cooper: 1
Fletcher: 3
Miller: 4
Smith: 0

In Forth?

-- 
When the Israeli bombers and torpedo-planes were sent to attack and destroy the
ship, the Jewish commander, seeing that it was an American vessel, had
misgivings and reported to the High Command, which simply repeated the orders
to attack and sink the Liberty. www.revilo-oliver.com/rpo/Bit_of_Good_News.html

[toc] | [next] | [standalone]


#59520

From"Robert L." <No_spamming@noWhere_7073.org>
Date2017-05-18 21:57 +0000
Message-ID<ofl5bq$bnq$1@gioia.aioe.org>
In reply to#59514
On 5/18/2017, Robert L. wrote:

> > The problem
> > 
> >   Baker, Cooper, Fletcher, Miller, and Smith live on different
> >   floors of an apartment house that contains only five floors.
> > 
> >   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. 
> > 
> > Where does everyone live?
> 
> (use srfi-1)
> 
> (define (any. lst fun) (any fun lst))
> 
> (let* ((floors '(0 1 2 3 4))
>        (b (delete 4 floors))
>        (c (delete 0 floors))
>        (f (lset-difference = floors '(0 4)))
>        (m floors)
>        (s floors)
>        (answer
>          (any. b (lambda(B)
>            (any. m (lambda(M)
>              (any. c (lambda(C)
>                (any. f (lambda(F)
>                  (any. s (lambda(S)
>                    (and
>                      (> M C)
>                      (< 1 (abs (- S F)))
>                      (< 1 (abs (- C F)))
>                      (let ((result (list B C F M S)))
>                        (and
>                          (equal? (delete-duplicates result) result)
>                          result)))))))))))))))
>   (for-each
>     print
>     '(Baker Cooper Fletcher Miller Smith) (circular-list ": ") answer))
> 
> Baker: 2
> Cooper: 1
> Fletcher: 3
> Miller: 4
> Smith: 0
> 
> In Forth?

(use gauche.sequence :only (sequence-contains))
(use util.combinations :only (permutations))
(use srfi-1 :only (first))

(remove
  (lambda(xs)
    (or
      (eq? 'Baker (last xs))
      (eq? 'Cooper (first xs))
      (eq? 'Fletcher (last xs))
      (eq? 'Fletcher (first xs))
      (sequence-contains xs '(Smith Fletcher))
      (sequence-contains xs '(Fletcher Smith))
      (sequence-contains xs '(Cooper Fletcher))
      (sequence-contains xs '(Fletcher Cooper))
      (member 'Cooper (member 'Miller xs))))
  (permutations '(Baker Cooper Fletcher Miller Smith)))

 ===>
((Smith Cooper Baker Fletcher Miller))


-- 
He has nothing but kind sentiments for those who would destroy his home and
family....  He is universally tolerant....  If he has any principles, he keeps
them well concealed....  He is, to the extent of his abilities, exactly like
the next citizen, who, he trusts, is trying to be exactly like him: a faceless,
characterless putty-man. --- Father Feeney; "Should Hate Be Outlawed?"

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web