[ccan] [PATCH] permutation: Generate permutations of arrays

Rusty Russell rusty at rustcorp.com.au
Sun Sep 27 17:01:25 AEST 2015


David Gibson <david at gibson.dropbear.id.au> writes:
> + * Example:
> + *	#include <stdio.h>
> + *	#include <ccan/permutation/permutation.h>
> + *
> + *	int main(int argc, char *argv[])
> + *	{
> + *		int i;
> + *		struct permutation *pi = permutation_new(argc - 1);
> + *
> + *		do {
> + *			for (i = 1; i <= argc; i++)
> + *				printf("%s ", argv[i]);
> + *			printf("\n");
> + *		} while (permutation_change_array(pi,
> + *		         &argv[1], sizeof(argv[1])));
> + *		exit(0);
> + *	}

That is a masterful example.  It's not quite right though: (i < argc,
not i <= argc).

I tried adding:

 *     // Given 1 2 3 outputs 1 2 3 1 3 2 3 1 2 3 2 1 2 3 1 2 1 3

But ccanlint isn't clever enough to ignore the \n.

Let me fix that now...

Cheers,
Rusty.


More information about the ccan mailing list