From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20377 invoked from network); 30 May 2022 09:19:42 -0000 Received: from minnie.tuhs.org (2600:3c01:e000:146::1) by inbox.vuxu.org with ESMTPUTF8; 30 May 2022 09:19:42 -0000 Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 721D540CBC; Mon, 30 May 2022 19:19:41 +1000 (AEST) Received: from relay05.pair.com (relay05.pair.com [216.92.24.67]) by minnie.tuhs.org (Postfix) with ESMTPS id E481440CB9 for ; Mon, 30 May 2022 19:19:36 +1000 (AEST) Received: from orac.inputplus.co.uk (unknown [84.51.159.244]) by relay05.pair.com (Postfix) with ESMTP id 18FEB1A2992 for ; Mon, 30 May 2022 05:19:36 -0400 (EDT) Received: from orac.inputplus.co.uk (orac.inputplus.co.uk [IPv6:::1]) by orac.inputplus.co.uk (Postfix) with ESMTP id 073CA21F37 for ; Mon, 30 May 2022 10:19:35 +0100 (BST) To: Computer Old Farts Followers From: Ralph Corderoy MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-reply-to: References: <20220530081604.A9FBF21F8A@orac.inputplus.co.uk> Date: Mon, 30 May 2022 10:19:35 +0100 Message-Id: <20220530091935.073CA21F37@orac.inputplus.co.uk> Message-ID-Hash: RHB5SUYALNWPHFZAOIX72MRCPO6Q5NO6 X-Message-ID-Hash: RHB5SUYALNWPHFZAOIX72MRCPO6Q5NO6 X-MailFrom: ralph@inputplus.co.uk X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [COFF] Re: Grep has gone overboard List-Id: Computer Old Farts Forum Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hi Bakul, > For permutations I just use this k program: > > $ cat perm.k > p:{:[1:'(x,x)#1,x#0)[;0,'1+_f x-1];,!x]} > perm:{x@p[#x]} I was thinking it looks like APL and it turns out to be a descendant. https://en.wikipedia.org/wiki/K_(programming_language) That pushed me into writing an awk-permutation generator. It's inefficient as it keeps altering $0 which cascades into re-working $1, etc., even if that's lazily done. Still, it sufficies for the small cases I typically need. $ cat perm #! /bin/awk -f function perm(s, f, l, t) { if (!NF) { print substr(s, 2) return } l = $0 for (f = 1; f <= NF; f++) { t = $f $f = ""; $0 = $0 perm(s " " t) $0 = l } } { perm("") } $ $ ./perm <<<'' $ ./perm <<<1 1 $ ./perm <<<'1 2' 1 2 2 1 $ ./perm <<<'1 2 3' 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 $ $ time ./perm <<<'1 2 3 4 5 6 7 8 9' | wc -l 362880 real 0m5.421s user 0m5.406s sys 0m0.082s $ $ dc <<<'9 8*7*6*5*4*3*2*p' 362880 $ -- Cheers, Ralph.