unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* puzzle with string permutations [photo]
@ 2022-06-07  6:39 Emanuel Berg
  2022-06-07  7:12 ` Marcin Borkowski
  2022-08-01  6:39 ` Marcin Borkowski
  0 siblings, 2 replies; 16+ messages in thread
From: Emanuel Berg @ 2022-06-07  6:39 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1924 bytes --]

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


[-- Attachment #2: survivor-puzzle.png --]
[-- Type: image/png, Size: 357181 bytes --]

[-- Attachment #3: Type: text/plain, Size: 61 bytes --]


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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-08-02 12:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2022-08-01  7:39   ` Emanuel Berg
2022-08-02 12:21   ` Jean Louis

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).