Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

There is no distinctly native American criminal class except Congress. -- Mark Twain


comp / comp.lang.lisp / Rosetta Code: Dinesman's multiple-dwelling problem

SubjectAuthor
o Rosetta Code: Dinesman's multiple-dwelling problemB. Pym

1
Subject: Rosetta Code: Dinesman's multiple-dwelling problem
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 5 Aug 2024 20:38 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Rosetta Code: Dinesman's multiple-dwelling problem
Date: Mon, 5 Aug 2024 20:38:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <v8rd8g$12juo$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 05 Aug 2024 22:38:44 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4d0da7ed839683006bcf3d49bfd7bbbd";
logging-data="1134552"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18vSJ2Bvlpc69yY4kmstHrq"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:2hWZvBKCIdwG5fjNPJ+XLZ1EKL4=
View all headers

> 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?

newLISP

;; Iterate over all permutations of a list, and
;; call a function on each.
(define (permute permute.seq permute.func (permute.built '()))
(if (null? permute.seq)
(permute.func permute.built)
(let (seq (copy permute.seq))
(dotimes (i (length seq))
(unless (zero? i) (rotate seq -1))
(permute
(rest seq)
permute.func
(cons (first seq) permute.built))))))

(define (adjacent a b lst)
(= 1 (abs (- (find a lst)
(find b lst)))))

(define (check lst)
(if
(and
(< (find 'baker lst) 4)
(> (find 'cooper lst) 0)
(not (member (find 'fletcher lst) '(0 4)))
(> (find 'miller lst) (find 'cooper lst))
(not (adjacent 'smith 'fletcher lst))
(not (adjacent 'cooper 'fletcher lst)))
(println lst)))

(permute '(baker cooper fletcher miller smith) check)
===>
(smith cooper baker fletcher miller)

1

rocksolid light 0.9.8
clearnet tor