help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

missing Lisp world (was: Re: puzzle with string permutations [photo])


From: Emanuel Berg
Subject: missing Lisp world (was: Re: puzzle with string permutations [photo])
Date: Wed, 08 Jun 2022 04:52:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

This code BTW illustrates the strategic weakness we have had
for a long time, since day one actually from my perspective
anyway, namely that we've had and have an Emacs world which
contains Lisp (Elisp), but what we should have is a Lisp world
and Emacs would be one of many components of that world!

> (require 'cl-lib)
>
> (defun cl-faculty (n)
>   (cl-loop with prod = 1
>     for i from 2 to n do
>     (setq prod (* i prod))
>     finally return prod) )
> ;; (cl-faculty  5) ;       120
> ;; (cl-faculty 10) ; 3 628 800
>
> (defun count (e l)
>   (seq-count (lambda (elem) (= elem e)) l) )
> ;; (count ?o '(?d ?g ?o ?o)) ; 2
>
> (defun product-string (str)
>   (let*((str-list         (string-to-list str))
>         (str-list-no-dups (cl-remove-duplicates str-list))
>         (prod 1) )
>     (dolist (e str-list-no-dups)
>       (setq prod (* prod (cl-faculty (count e str-list)))) )
>     prod ))
> ;; (product-string "ogod") ; 2
>
> (defun perms-string-num (str)
>   (let ((n (cl-faculty (length str)))
>         (r (product-string str)) )
>     (/ n r) ))
> ;; (perms-string-num "ogod")   ;  12
> ;; (perms-string-num "kudtce") ; 720

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]