Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #59514
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta Code: Dinesman's multiple-dwelling problem |
| Date | 2017-05-18 19:24 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ofkse0$1smi$1@gioia.aioe.org> (permalink) |
> 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
Back to comp.lang.forth | Previous | Next — Next in thread | Find similar | Unroll thread
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
csiph-web