From: Marcin Borkowski <mbork@mbork.pl>
To: Emanuel Berg <incal@dataswamp.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: puzzle with string permutations [photo]
Date: Mon, 01 Aug 2022 08:39:23 +0200 [thread overview]
Message-ID: <875yjcfox0.fsf@mbork.pl> (raw)
In-Reply-To: <87r141rn8n.fsf@dataswamp.org>
http://mbork.pl/2022-08-01_Making_secrets_with_Emacs
On 2022-06-07, at 08:39, Emanuel Berg <incal@dataswamp.org> wrote:
> Try to solve this - not easy!
>
> https://dataswamp.org/~incal/pimgs/survivor-puzzle.png
>
> It is from US/CBC Survivor S42E13 around 9 minutes in.
>
> It says
>
> eht kudtce pigelsen tagni ogod seot erontuf si ni fo hte
>
> Easy LOL :) The first word should be "the"!
>
> But even the second one, "kudce", that has
>
> (length (string-perms "kudce")) ; 120
>
> permutations [source last]
>
> And (length (string-perms "pigelsen")) ; 40 320 !
>
> Even a word with just four letters, e.g. what should come out
> of "seot", has 24 perms already!
>
> (length (string-perms "seot")) ; 24
>
> Because of the vowels, word order, and generally just how the
> brain works, which we don't know exactly even by far BTW, it
> doesn't translate lineary to more difficult because of more
> permutations ...
>
> But let's just say I was unable to solve it with a full
> stomach and rising from a cozy bed, actually that should be
> the other way around now that we are mentioning the brain
> and all.
>
> What should it be?
> "eht kudtce pigelsen tagni ogod seot erontuf si ni fo hte" ?
>
> ;;; -*- lexical-binding: t -*-
> ;;
> ;; this file:
> ;; https://dataswamp.org/~incal/emacs-init/perm.el
>
> (require 'cl-lib)
>
> ;; 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 (s)
> (let*((chars (string-to-list s))
> (char-perms (perms chars)) )
> (mapcar (lambda (a)
> (concat a) )
> char-perms) ))
>
> ;; (string-perms "abc") ; abc acb bac bca cab cba
> ;; (string-perms "neo") ; neo noe eno eon one oen
>
> ;; eht kudtce pigelsen tagni ogod seot erontuf si ni fo hte
> ;; (length (string-perms "kudce")) ; 120
> ;; (length (string-perms "seot")) ; 24
> ;; (length (string-perms "pigelsen")) ; 40 320
--
Marcin Borkowski
http://mbork.pl
next prev parent reply other threads:[~2022-08-01 6:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 6:39 puzzle with string permutations [photo] Emanuel Berg
2022-06-07 7:12 ` Marcin Borkowski
2022-06-07 7:54 ` Emanuel Berg
2022-06-07 7:58 ` Emanuel Berg
2022-06-07 8:08 ` Emanuel Berg
2022-06-07 13:53 ` Emanuel Berg
2022-06-07 14:18 ` Emanuel Berg
2022-06-07 16:09 ` Yuri Khan
2022-06-07 22:04 ` Emanuel Berg
2022-06-08 0:17 ` Emanuel Berg
2022-06-08 2:52 ` missing Lisp world (was: Re: puzzle with string permutations [photo]) Emanuel Berg
2022-06-07 8:37 ` puzzle with string permutations [photo] Emanuel Berg
2022-06-07 13:28 ` Emanuel Berg
2022-08-01 6:39 ` Marcin Borkowski [this message]
2022-08-01 7:39 ` Emanuel Berg
2022-08-02 12:21 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875yjcfox0.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=help-gnu-emacs@gnu.org \
--cc=incal@dataswamp.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).