#include #include int length; char *set; char *permutation; int ft_strlen(char *s) { int i = 0; while(s[i]) i++; return (i); } void permutations(int index, char *used) { if (index == length) { printf("%s\n", permutation); return ; } int i = 0; while (i < length) { if (used[i] == '0') { permutation[index] = set[i]; used[i] = '1'; permutations(index + 1, used); used[i] = '0'; } i++; } } char *populate_used() { char *ret = (char *) calloc (length + 1, sizeof(char)); int i = 0; while (i < length) ret[i++] = '0'; return (ret); } int main(int ac, char **av) { if (ac != 2) return (1); set = av[1]; length = ft_strlen(av[1]); char *used = populate_used(); permutation = (char *) malloc(sizeof(char) * (length + 1)); permutations(0, used); free(used); free(permutation); return (0); }