* Composing words from acronyms
@ 2023-07-25 18:28 uzibalqa
2023-07-25 18:40 ` Emanuel Berg
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: uzibalqa @ 2023-07-25 18:28 UTC (permalink / raw)
To: uzibalqa via Users list for the GNU Emacs text editor
I would like to compose words from acronyms (e.g. 5-letter words, 4-letter words, etc).
For instance, from the acronym 'Emacs' I can compose 'maces'.
Is this difficult to de in eamcs, and how may I approach this task ?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 18:28 Composing words from acronyms uzibalqa
@ 2023-07-25 18:40 ` Emanuel Berg
2023-07-25 18:50 ` Tassilo Horn
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2023-07-25 18:40 UTC (permalink / raw)
To: help-gnu-emacs
uzibalqa wrote:
> For instance, from the acronym 'Emacs' I can
> compose 'maces'.
Indeed, those are called string permutations and there are
5! = 5 * 4 * 3 * 2 * 1 = 120
for "Emacs" since that string has 5 chars. The exclamation
mark is the faculty operator, and this type of computation is
part of a math field known as Combinatorics.
> Is this difficult to de in eamcs, and how may I approach
> this task ?
For example like this:
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/perm.el
(require 'cl-lib)
(require 'spell)
;; Christoph Conrad @ https://www.emacswiki.org/emacs/StringPermutations
(defun perms (l)
(if l (cl-mapcan (lambda (a)
(cl-mapcan (lambda (p)
(list (cons a p)))
(perms (cl-remove a l :count 1)) )) l)
'(()) ))
(defun string-perms (str)
(let*((chars (string-to-list str))
(char-perms (perms chars)) )
(mapcar (lambda (a)
(concat a) )
char-perms) ))
;; (string-perms "hte") ; ("hte" "het" "the" "teh" "eht" "eth")
(defun string-perms-filter (str)
(let ((strs (cl-remove-duplicates
(cl-remove-if-not (lambda (w) (spell-word w)) (string-perms str))
:test #'string=) ))
(if (= 1 (length strs))
(car strs)
strs) ))
;; eht kudtce pigelsen tagni ogod seot erontuf si ni fo hte
;;
;; (string-perms-filter "ogod") ; good
;; (string-perms-filter "erontuf") ; fortune
;; (string-perms-filter "si") ; is
;; (string-perms-filter "kudtce") ; tucked
;; (string-perms-filter "ni") ; in
;; (string-perms-filter "eth") ; the
;; (string-perms-filter "seot") ; toes
;; (string-perms-filter "fo") ; of
;; (string-perms-filter "hte") ; the
;; (string-perms-filter "pigelsen") ; ("peelings" "sleeping")
;; (string-perms-filter "tagni") ; giant
(defun factorial (n)
(if (> n 1)
(* n (factorial (1- n)))
1))
;; (factorial 5) ; 120
;; (factorial 10) ; 3 628 800
(defun cl-factorial (n)
(cl-loop
with prod = 1
for i from 2 to n
do (setq prod (* i prod))
finally return prod) )
;; (cl-factorial 5) ; 120
;; (cl-factorial 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-factorial (count e str-list)))) )
prod ))
;; (product-string "ogod") ; 2
(defun perms-string-num (str)
(let ((n (cl-factorial (length str)))
(r (product-string str)) )
(/ n r) ))
;; (perms-string-num "ogod") ; 12
;; (perms-string-num "kudtce") ; 720
(provide 'perm)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 18:28 Composing words from acronyms uzibalqa
2023-07-25 18:40 ` Emanuel Berg
@ 2023-07-25 18:50 ` Tassilo Horn
2023-07-25 19:02 ` Emanuel Berg
` (2 more replies)
2023-07-25 18:57 ` Emanuel Berg
2023-07-25 20:02 ` Yuri Khan
3 siblings, 3 replies; 14+ messages in thread
From: Tassilo Horn @ 2023-07-25 18:50 UTC (permalink / raw)
To: uzibalqa; +Cc: help-gnu-emacs
uzibalqa <uzibalqa@proton.me> writes:
> I would like to compose words from acronyms (e.g. 5-letter words,
> 4-letter words, etc). For instance, from the acronym 'Emacs' I can
> compose 'maces'.
>
> Is this difficult to de in eamcs, and how may I approach this task ?
It's a bit cheating but the dash package has a -permutations function
which does the job.
(defun acronyms (word)
(seq-filter
(lambda (acronym)
;; TODO: check if acronym is actually a sensible word.
t)
(mapcar (lambda (lst)
(mapconcat #'char-to-string lst))
(-permutations (string-to-list word)))))
For the TODO, you could probably use some dictionary file.
Bye,
Tassilo
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 18:28 Composing words from acronyms uzibalqa
2023-07-25 18:40 ` Emanuel Berg
2023-07-25 18:50 ` Tassilo Horn
@ 2023-07-25 18:57 ` Emanuel Berg
2023-07-25 20:02 ` Yuri Khan
3 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2023-07-25 18:57 UTC (permalink / raw)
To: help-gnu-emacs
> faculty
Swinglish, should be "factorial", it is correct in the source.
IIRC someone has a blog post on that as well, but he got the
idea from me IIRC ;)
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 18:50 ` Tassilo Horn
@ 2023-07-25 19:02 ` Emanuel Berg
2023-07-25 19:19 ` Emanuel Berg
2023-07-25 19:23 ` Emanuel Berg
2 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2023-07-25 19:02 UTC (permalink / raw)
To: help-gnu-emacs
Tassilo Horn wrote:
> It's a bit cheating but the dash package has a -permutations
> function which does the job.
>
> (defun acronyms (word)
> (seq-filter
> (lambda (acronym)
> ;; TODO: check if acronym is actually a sensible word [...]
You mean like this? :)
(defun string-perms-filter (str)
(let ((strs (cl-remove-duplicates
(cl-remove-if-not (lambda (w) (spell-word w)) (string-perms str))
:test #'string=) ))
(if (= 1 (length strs))
(car strs)
strs) ))
It checks if it is a real word by spellchecking it.
Source:
https://dataswamp.org/~incal/emacs-init/perm.el
https://dataswamp.org/~incal/emacs-init/spell.el
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 18:50 ` Tassilo Horn
2023-07-25 19:02 ` Emanuel Berg
@ 2023-07-25 19:19 ` Emanuel Berg
2023-07-25 19:23 ` Emanuel Berg
2 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2023-07-25 19:19 UTC (permalink / raw)
To: help-gnu-emacs
Tassilo Horn wrote:
> For the TODO, you could probably use some dictionary file.
Oh, so you even suggested that, ha! Great minds ... :D
Here it is used to solve a scramble puzzle I saw on an episode
of US Survivor, with the exact method that you mention.
;; eht kudtce pigelsen tagni ogod seot erontuf si ni fo hte
;;
;; (string-perms-filter "ogod") ; good
;; (string-perms-filter "erontuf") ; fortune
;; (string-perms-filter "si") ; is
;; (string-perms-filter "kudtce") ; tucked
;; (string-perms-filter "ni") ; in
;; (string-perms-filter "eth") ; the
;; (string-perms-filter "seot") ; toes
;; (string-perms-filter "fo") ; of
;; (string-perms-filter "hte") ; the
;; (string-perms-filter "pigelsen") ; ("peelings" "sleeping")
;; (string-perms-filter "tagni") ; giant
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 18:50 ` Tassilo Horn
2023-07-25 19:02 ` Emanuel Berg
2023-07-25 19:19 ` Emanuel Berg
@ 2023-07-25 19:23 ` Emanuel Berg
2023-07-25 19:48 ` uzibalqa
2 siblings, 1 reply; 14+ messages in thread
From: Emanuel Berg @ 2023-07-25 19:23 UTC (permalink / raw)
To: help-gnu-emacs
> For instance, from the acronym 'Emacs' I can
> compose 'maces'.
There are three words according to the method outlined
(permutation plus dictionary check), those are as below
(string-perms-filter "emacs") ; ("emacs" "maces" "acmes")
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 19:23 ` Emanuel Berg
@ 2023-07-25 19:48 ` uzibalqa
2023-07-25 20:02 ` uzibalqa
0 siblings, 1 reply; 14+ messages in thread
From: uzibalqa @ 2023-07-25 19:48 UTC (permalink / raw)
To: Emanuel Berg; +Cc: help-gnu-emacs
Sent with Proton Mail secure email.
------- Original Message -------
On Wednesday, July 26th, 2023 at 7:23 AM, Emanuel Berg <incal@dataswamp.org> wrote:
> > For instance, from the acronym 'Emacs' I can
> > compose 'maces'.
>
>
> There are three words according to the method outlined
> (permutation plus dictionary check), those are as below
>
> (string-perms-filter "emacs") ; ("emacs" "maces" "acmes")
How can I display the results ?
I did the following but nothing got displayed.
(message "%S" (string-perms-filter "emacs"))
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 19:48 ` uzibalqa
@ 2023-07-25 20:02 ` uzibalqa
2023-07-26 12:02 ` Emanuel Berg
0 siblings, 1 reply; 14+ messages in thread
From: uzibalqa @ 2023-07-25 20:02 UTC (permalink / raw)
To: uzibalqa; +Cc: Emanuel Berg, help-gnu-emacs
Sent with Proton Mail secure email.
------- Original Message -------
On Wednesday, July 26th, 2023 at 7:48 AM, uzibalqa <uzibalqa@proton.me> wrote:
>
>
>
>
>
> Sent with Proton Mail secure email.
>
>
> ------- Original Message -------
> On Wednesday, July 26th, 2023 at 7:23 AM, Emanuel Berg incal@dataswamp.org wrote:
>
>
>
> > > For instance, from the acronym 'Emacs' I can
> > > compose 'maces'.
> >
> > There are three words according to the method outlined
> > (permutation plus dictionary check), those are as below
> >
> > (string-perms-filter "emacs") ; ("emacs" "maces" "acmes")
>
>
> How can I display the results ?
>
> I did the following but nothing got displayed.
>
> (message "%S" (string-perms-filter "emacs"))
I could not find the function 'string-perms'.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 18:28 Composing words from acronyms uzibalqa
` (2 preceding siblings ...)
2023-07-25 18:57 ` Emanuel Berg
@ 2023-07-25 20:02 ` Yuri Khan
2023-07-25 20:26 ` uzibalqa
3 siblings, 1 reply; 14+ messages in thread
From: Yuri Khan @ 2023-07-25 20:02 UTC (permalink / raw)
To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor
On Wed, 26 Jul 2023 at 01:29, uzibalqa <uzibalqa@proton.me> wrote:
> I would like to compose words from acronyms (e.g. 5-letter words, 4-letter words, etc).
> For instance, from the acronym 'Emacs' I can compose 'maces'.
The word you were looking for is called “anagram”. “Acronym” is a word
composed of first letters of other words.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 20:02 ` Yuri Khan
@ 2023-07-25 20:26 ` uzibalqa
2023-07-26 11:15 ` Pierre Rouleau
0 siblings, 1 reply; 14+ messages in thread
From: uzibalqa @ 2023-07-25 20:26 UTC (permalink / raw)
To: Yuri Khan; +Cc: uzibalqa via Users list for the GNU Emacs text editor
------- Original Message -------
On Wednesday, July 26th, 2023 at 8:02 AM, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Wed, 26 Jul 2023 at 01:29, uzibalqa uzibalqa@proton.me wrote:
>
> > I would like to compose words from acronyms (e.g. 5-letter words, 4-letter words, etc).
> > For instance, from the acronym 'Emacs' I can compose 'maces'.
>
>
> The word you were looking for is called “anagram”. “Acronym” is a word
> composed of first letters of other words.
Emacs is an Acronym my dear friend, and I am looking to compose words from them.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 20:26 ` uzibalqa
@ 2023-07-26 11:15 ` Pierre Rouleau
2023-07-26 11:23 ` uzibalqa
0 siblings, 1 reply; 14+ messages in thread
From: Pierre Rouleau @ 2023-07-26 11:15 UTC (permalink / raw)
To: uzibalqa; +Cc: Yuri Khan, uzibalqa via Users list for the GNU Emacs text editor
> > I would like to compose words from acronyms (e.g. 5-letter words,
> 4-letter words, etc).
> > > For instance, from the acronym 'Emacs' I can compose 'maces'.
> >
> >
> > The word you were looking for is called “anagram”. “Acronym” is a word
> > composed of first letters of other words.
>
> Emacs is an Acronym my dear friend, and I am looking to compose words from
> them.
>
> So, your initial request was: "compose anagrams from acronyms" .
--
/Pierre
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-26 11:15 ` Pierre Rouleau
@ 2023-07-26 11:23 ` uzibalqa
0 siblings, 0 replies; 14+ messages in thread
From: uzibalqa @ 2023-07-26 11:23 UTC (permalink / raw)
To: Pierre Rouleau
Cc: Yuri Khan, uzibalqa via Users list for the GNU Emacs text editor
------- Original Message -------
On Wednesday, July 26th, 2023 at 11:15 PM, Pierre Rouleau <prouleau001@gmail.com> wrote:
> > > I would like to compose words from acronyms (e.g. 5-letter words,
> > > 4-letter words, etc).
> > >
> > > > For instance, from the acronym 'Emacs' I can compose 'maces'.
> > >
> > > The word you were looking for is called “anagram”. “Acronym” is a word
> > > composed of first letters of other words.
> >
> > Emacs is an Acronym my dear friend, and I am looking to compose words from
> > them.
> >
> > So, your initial request was: "compose anagrams from acronyms" . /Pierre
Initial request was composing words from acronyms (after making permutations of the letters
of the acronyms). To accept words I need some checking with a dictionary so I return only valid
words.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Composing words from acronyms
2023-07-25 20:02 ` uzibalqa
@ 2023-07-26 12:02 ` Emanuel Berg
0 siblings, 0 replies; 14+ messages in thread
From: Emanuel Berg @ 2023-07-26 12:02 UTC (permalink / raw)
To: help-gnu-emacs
uzibalqa wrote:
>> (message "%S" (string-perms-filter "emacs"))
>
> I could not find the function 'string-perms'.
Keep looking - the truth is out there ...
https://dataswamp.org/~incal/emacs-init/perm.el
https://dataswamp.org/~incal/emacs-init/spell.el
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-07-26 12:02 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25 18:28 Composing words from acronyms uzibalqa
2023-07-25 18:40 ` Emanuel Berg
2023-07-25 18:50 ` Tassilo Horn
2023-07-25 19:02 ` Emanuel Berg
2023-07-25 19:19 ` Emanuel Berg
2023-07-25 19:23 ` Emanuel Berg
2023-07-25 19:48 ` uzibalqa
2023-07-25 20:02 ` uzibalqa
2023-07-26 12:02 ` Emanuel Berg
2023-07-25 18:57 ` Emanuel Berg
2023-07-25 20:02 ` Yuri Khan
2023-07-25 20:26 ` uzibalqa
2023-07-26 11:15 ` Pierre Rouleau
2023-07-26 11:23 ` uzibalqa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).