-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperm.c
More file actions
34 lines (27 loc) · 703 Bytes
/
perm.c
File metadata and controls
34 lines (27 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const int alphabetSize = sizeof(alphabet) - 1;
static void bruteImpl(char* str, size_t index, size_t maxDepth)
{
for (size_t i = 0; i < alphabetSize; ++i)
{
str[index] = alphabet[i];
if (index == maxDepth - 1) printf("%s\n", str);
else bruteImpl(str, index + 1, maxDepth);
}
}
void bruteSequential(size_t maxLen)
{
char* buf = calloc(maxLen + 1, sizeof(char));
for (size_t len = 1; len <= maxLen; ++len)
{
bruteImpl(buf, 0, len);
}
free(buf);
}
int main(int argc, char** argv)
{
bruteSequential(6);
}