Skip to content

Instantly share code, notes, and snippets.

@tecknoh19
Created June 9, 2018 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tecknoh19/47b3a457ab5323595edc0bf4e27c0d95 to your computer and use it in GitHub Desktop.
Save tecknoh19/47b3a457ab5323595edc0bf4e27c0d95 to your computer and use it in GitHub Desktop.
#include <stdio.h>
//global variaes and magic numbers are the basis of good programming
const char* charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`~@#$%^&*()-_=+|]}[{';:<,.>?";
char buffer[50];
void permute(int level) {
const char* charset_ptr = charset;
if(level == -1){
puts(buffer);
}else {
while(buffer[level]=*charset_ptr++) {
permute(level - 1);
}
}
}
int main(int argc, char **argv)
{
int length;
sscanf(argv[1], "%d", &length);
//Must provide length (integer < sizeof(buffer)==50) as first arg;
//It will crash and burn otherwise
buffer[length]='\0';
permute(length - 1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment