From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: puzzle with string permutations [photo] Date: Mon, 01 Aug 2022 08:39:23 +0200 Message-ID: <875yjcfox0.fsf@mbork.pl> References: <87r141rn8n.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16643"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.1.0; emacs 29.0.50 Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 01 08:42:58 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oIP8i-0003vC-4U for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 01 Aug 2022 08:42:56 +0200 Original-Received: from localhost ([::1]:53674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIP8g-0002JA-Do for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 01 Aug 2022 02:42:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oIP5c-0001VY-TE for help-gnu-emacs@gnu.org; Mon, 01 Aug 2022 02:39:45 -0400 Original-Received: from mail.mojserwer.eu ([195.110.48.8]:51890) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oIP5W-0001RB-An for help-gnu-emacs@gnu.org; Mon, 01 Aug 2022 02:39:44 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id ED79DE72C4; Mon, 1 Aug 2022 08:39:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F3_0G0T9HZhD; Mon, 1 Aug 2022 08:39:25 +0200 (CEST) Original-Received: from localhost (83.21.182.82.ipv4.supernova.orange.pl [83.21.182.82]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 36164E6D86; Mon, 1 Aug 2022 08:39:25 +0200 (CEST) In-reply-to: <87r141rn8n.fsf@dataswamp.org> Received-SPF: pass client-ip=195.110.48.8; envelope-from=mbork@mbork.pl; helo=mail.mojserwer.eu X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138701 Archived-At: http://mbork.pl/2022-08-01_Making_secrets_with_Emacs On 2022-06-07, at 08:39, Emanuel Berg 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