Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <uutqd2$bhl0$1@i2pn2.org>
Deutsch   English   Français   Italiano  
<uutqd2$bhl0$1@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder6.news.weretis.net!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: fir <fir@grunge.pl>
Newsgroups: comp.lang.c
Subject: Re: Recursion, Yo
Date: Sun, 07 Apr 2024 11:52:29 +0200
Organization: i2pn2 (i2pn.org)
Message-ID: <uutqd2$bhl0$1@i2pn2.org>
References: <uut24f$2icpb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 7 Apr 2024 09:52:35 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="378528"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="+ydHcGjgSeBt3Wz3WTfKefUptpAWaXduqfw5xdfsuS0";
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
In-Reply-To: <uut24f$2icpb$1@dont-email.me>
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 3753
Lines: 108

Lawrence D'Oliveiro wrote:
> Some homies they be sayin’ recursion is Teh Evulz. Well, check this
> out. This program be recursing to the max, yo.
>
> Peace.
>
> ----
> /*
>      Generate permutations of a list of items.
>      Pass a list of arbitary words as command arguments, and this
>      program will print out all possible orderings of them.
> */
>
> #include <iso646.h>
> #include <stdbool.h>
> #include <stdlib.h>
> #include <stdio.h>
>
> typedef void (*permute_action)
>    (
>      const char * const * words
>    );
>
> void permute
>    (
>      unsigned int nrwords,
>      const char * const * words,
>      permute_action action
>    )
>    {
>      if (nrwords > 0)
>        {
>          const char ** const permbuf = (const char **)malloc(nrwords * sizeof(char *));
>          bool * const used = (bool *)malloc(nrwords);
>          for (unsigned int i = 0; i < nrwords; ++i)
>            {
>              used[i] = false;
>            } /*for*/
>
>          void permute1
>            (
>              unsigned int depth
>            )
>            {
>              if (depth < nrwords)
>                {
>                  for (unsigned int i = 0; i < nrwords; ++i)
>                    {
>                      if (not used[i])
>                        {
>                          permbuf[depth] = words[i];
>                          used[i] = true;
>                          permute1(depth + 1);
>                          used[i] = false;
>                        } /*if*/
>                    } /*for*/
>                }
>              else
>                {
>                  action(permbuf);
>                } /*if*/
>            } /*permute1*/
>
>          permute1(0);
>
>          free(permbuf);
>          free(used);
>        } /*if*/
>    } /*permute*/
>
> int main
>    (
>      int argc,
>      char ** argv
>    )
>    {
>      const unsigned int nrwords = argc - 1;
>      unsigned int count = 0;
>
>      void collect
>        (
>          const char * const * words
>        )
>        {
>          count += 1;
>          fprintf(stdout, "[%d](", count);
>          for (unsigned int i = 0; i < nrwords; ++i)
>            {
>              if (i != 0)
>                {
>                  fputs(", ", stdout);
>                } /*if*/
>              fputs(words[i], stdout);
>            } /*for*/
>          fputs(")\n", stdout);
>        } /*collect*/
>
>      permute
>        (
>          /*nrwords =*/ nrwords,
>          /*words =*/ (const char * const * )(argv + 1),
>          /*permute_action =*/ (permute_action)collect
>        );
>
>      fprintf(stdout, "Nr found: %d\n", count);
>    } /*main*/
>
okay, there are some class of things that suit good for recursion - and 
its probably good to spot whose they are