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

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

Re: puzzle with string permutations [photo]


From: Marcin Borkowski
Subject: Re: puzzle with string permutations [photo]
Date: Mon, 01 Aug 2022 08:39:23 +0200
User-agent: mu4e 1.1.0; emacs 29.0.50

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



reply via email to

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