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

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

puzzle with string permutations [photo]


From: Emanuel Berg
Subject: puzzle with string permutations [photo]
Date: Tue, 07 Jun 2022 08:39:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

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: survivor-puzzle.png
Description: PNG image

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

reply via email to

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