Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp Subject: New Scientist Puzzle Date: Tue, 11 Jun 2024 08:51:08 -0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Tue, 11 Jun 2024 10:51:08 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d2ae20237df250ddceb677ab00583f50"; logging-data="1035368"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189/aGiNtdRpnZJwaKuA1e6" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:phZ+CupMI1PFRt8Z1mXgDU0yeuw= Bytes: 2017 VIER and NEUN represent 4-digit squares, each letter denoting a distinct digit. You are asked to find the value of each, given the further requirement that each uniquely determines the other. The "further requirement" means that of the numerous pairs of answers, choose the one in which each number only appears once in all of the pairs. Gauche Scheme (use srfi-13) ;; string-map (use srfi-42) ;; list-ec (define squares4d (map (lambda (n) (number->string (square n))) (lrange 32 100))) (define alphabet (map integer->char (lrange 65 91))) (define (->pattern str) (let ((table (map cons (delete-duplicates (string->list str)) alphabet))) (string-map (cut assoc-ref table <>) str))) (define possibles (let ((pat (->pattern "NEUNVIER"))) (list-ec (:list n squares4d) (:list v squares4d) (if (equal? pat (->pattern (string-append n v)))) (list n v)))) (define (count* f xs) (count (lambda(ys) (equal? (f xs) (f ys))) possibles)) (find (lambda(nv) (= 1 (count* car nv) (count* cadr nv))) possibles) ===> ("9409" "6241")