Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Single tasking: Just Say No.


computers / comp.os.linux.advocacy / Re: D'Oliveiro: I saw your recursion/permutation post on comp.lang.c

SubjectAuthor
* D'Oliveiro: I saw your recursion/permutation post on comp.lang.cDFS
`- Re: D'Oliveiro: I saw your recursion/permutation post on comp.lang.cDFS

1
D'Oliveiro: I saw your recursion/permutation post on comp.lang.c

<v0b3hc$2bukd$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14023&group=comp.os.linux.advocacy#14023

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: D'Oliveiro: I saw your recursion/permutation post on comp.lang.c
Date: Wed, 24 Apr 2024 10:04:31 -0400
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <v0b3hc$2bukd$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 24 Apr 2024 16:04:28 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f4cc782050c0240147f4690572f965ca";
logging-data="2488973"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xXjZT4Z8pJ5LmIZW+CVtv"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:rQ+zPPY0rCFlBISYgtjLe0PzFiw=
Content-Language: en-US
 by: DFS - Wed, 24 Apr 2024 14:04 UTC

It's a lot of code (84 lines), but I see you split your function
definitions across multiple lines, and put opening brackets on a new
line. Fixing those snafus reduces it to 52 lines, with absolutely no
loss of readability and comprehension.

The new file is "permute_DOliveiro_with_DFS_formatting_corrections.c"

In your best suburban ghetto-speak, you said "This program be recursing
to the max, yo." Nauseating. Stick to the White man's English and
conjugate your verbs and your wife won't divorce you and you can stay
employed and afford transportation to said employment.

Instead of that fit of overblown C narcissism, why didn't you use
something short and sweet like Heap's algorithm?

------------------------------------------------------------------------
import sys
def permute(k,a):
if k==1:
print(a)
else:
permute(k-1,a)
for i in range(k-1):
if k%2==0:
a[i],a[k-1]=a[k-1],a[i]
else:
a[0],a[k-1]=a[k-1],a[0]
permute(k-1,a)
a = []
for i in range(1,len(sys.argv)):
a.append(sys.argv[i])
permute(len(a),a)
------------------------------------------------------------------------

$ python3 permute_Heap.py 1 2 3
['1', '2', '3']
['2', '1', '3']
['3', '1', '2']
['1', '3', '2']
['2', '3', '1']
['3', '2', '1']

$ python3 permute_Heap.py dance the night away
['dance', 'the', 'night', 'away']
['the', 'dance', 'night', 'away']
['night', 'dance', 'the', 'away']
['dance', 'night', 'the', 'away']
['the', 'night', 'dance', 'away']
['night', 'the', 'dance', 'away']
['away', 'the', 'dance', 'night']
['the', 'away', 'dance', 'night']
['dance', 'away', 'the', 'night']
['away', 'dance', 'the', 'night']
['the', 'dance', 'away', 'night']
['dance', 'the', 'away', 'night']
['dance', 'night', 'away', 'the']
['night', 'dance', 'away', 'the']
['away', 'dance', 'night', 'the']
['dance', 'away', 'night', 'the']
['night', 'away', 'dance', 'the']
['away', 'night', 'dance', 'the']
['away', 'night', 'the', 'dance']
['night', 'away', 'the', 'dance']
['the', 'away', 'night', 'dance']
['away', 'the', 'night', 'dance']
['night', 'the', 'away', 'dance']
['the', 'night', 'away', 'dance']

Re: D'Oliveiro: I saw your recursion/permutation post on comp.lang.c

<v0c6b4$2jp69$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14066&group=comp.os.linux.advocacy#14066

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nospam@dfs.com (DFS)
Newsgroups: comp.os.linux.advocacy
Subject: Re: D'Oliveiro: I saw your recursion/permutation post on comp.lang.c
Date: Wed, 24 Apr 2024 19:58:29 -0400
Organization: A noiseless patient Spider
Lines: 90
Message-ID: <v0c6b4$2jp69$1@dont-email.me>
References: <v0b3hc$2bukd$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 25 Apr 2024 01:58:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d5df2c4a47f21da70800fe0a265cd227";
logging-data="2745545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PzF4A3Rl58qfxY5iWDulz"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:UYcLTBOMD7uSvZtnYDCzz0WH624=
In-Reply-To: <v0b3hc$2bukd$2@dont-email.me>
Content-Language: en-US
 by: DFS - Wed, 24 Apr 2024 23:58 UTC

On 4/24/2024 10:04 AM, DFS wrote:

> Heap's algorithm

Improvements: lexico sort and enumerate the output, remove list
punctuation, line break on each change of the first element
----------------------------------------------------------------------------
import sys
def permute(k, a):
global b
if k == 1:
b.append(list(a))
else:
permute(k-1, a)
for i in range(k-1):
if k % 2 == 0:
a[i], a[k-1] = a[k-1], a[i]
else:
a[0], a[k-1] = a[k-1], a[0]
permute(k-1, a)
a,b = [],[]
for i in range(1,len(sys.argv)):
a.append(sys.argv[i])
permute(len(a),a)
e = sorted(b)[0][0]
for i, itm in enumerate(sorted(b)):
if len(b) > 2:
if itm[0] != e:
e = itm[0]
print()
print("%2d." % (i+1),end = ' ')
print(*itm)
----------------------------------------------------------------------------
$ python3 permute_Heap.py dance the night away
1. away dance night the
2. away dance the night
3. away night dance the
4. away night the dance
5. away the dance night
6. away the night dance

7. dance away night the
8. dance away the night
9. dance night away the
10. dance night the away
11. dance the away night
12. dance the night away

13. night away dance the
14. night away the dance
15. night dance away the
16. night dance the away
17. night the away dance
18. night the dance away

19. the away dance night
20. the away night dance
21. the dance away night
22. the dance night away
23. the night away dance
24. the night dance away

previously
['dance', 'the', 'night', 'away']
['the', 'dance', 'night', 'away']
['night', 'dance', 'the', 'away']
['dance', 'night', 'the', 'away']
['the', 'night', 'dance', 'away']
['night', 'the', 'dance', 'away']
['away', 'the', 'dance', 'night']
['the', 'away', 'dance', 'night']
['dance', 'away', 'the', 'night']
['away', 'dance', 'the', 'night']
['the', 'dance', 'away', 'night']
['dance', 'the', 'away', 'night']
['dance', 'night', 'away', 'the']
['night', 'dance', 'away', 'the']
['away', 'dance', 'night', 'the']
['dance', 'away', 'night', 'the']
['night', 'away', 'dance', 'the']
['away', 'night', 'dance', 'the']
['away', 'night', 'the', 'dance']
['night', 'away', 'the', 'dance']
['the', 'away', 'night', 'dance']
['away', 'the', 'night', 'dance']
['night', 'the', 'away', 'dance']
['the', 'night', 'away', 'dance']


computers / comp.os.linux.advocacy / Re: D'Oliveiro: I saw your recursion/permutation post on comp.lang.c

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor