Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <v8rgi7$13t0c$1@dont-email.me>
Deutsch   English   Français   Italiano  
<v8rgi7$13t0c$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp
Subject: Re: Non-determinism
Date: Mon, 5 Aug 2024 21:35:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <v8rgi7$13t0c$1@dont-email.me>
References: <v7pboq$1d67r$1@dont-email.me> <v7peea$1djes$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 05 Aug 2024 23:35:07 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4d0da7ed839683006bcf3d49bfd7bbbd";
	logging-data="1176588"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18wqP9CBQrp6JY0QsGteakb"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:e6YmaX7l7uWQ61kgFrPKqg/Pz38=
Bytes: 2478

B. Pym wrote:

> Problem 4.42 in SICP
> 
> Five school girls took an exam. As they think thattheir
> parents are too much interested in their score, they promise
> that they write one correct and one wrong informations to
> their parents. Followings are parts of their letters
> concerning their result:
> 
> Betty: 	Kitty was the second and I third.
> Ethel: 	I won the top and Joan the second.
> Joan: 	I was the third and poor Ethel the last.
> Kitty: 	I was the second and Mary the fourth.
> Mary: 	I was the fourth. Betty won the top.
> 
> Guess the real order of the five school girls. 

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 (xor a b) (if a (not b) b))

(define (find* x xs) (+ 1 (find x xs)))

(define (either a m  b n  lst)
  (xor (= m (find* a lst))
       (= n (find* b lst))))

(define (check answer)
  (if
    (and
      (either 'kitty 2  'betty 3  answer)
      (either 'kitty 2  'mary 4  answer)
      (either 'mary 4  'betty 1  answer)
      (either 'ethel 1  'joan 2  answer))
    (println answer)))

(permute '(kitty betty ethel joan mary) check)
  ===>
(kitty joan betty mary ethel)