Skip to content

Instantly share code, notes, and snippets.

@spacelatte
Last active November 18, 2016 09:54
Show Gist options
  • Save spacelatte/494751ef22b2e401adf23b92403e0bf3 to your computer and use it in GitHub Desktop.
Save spacelatte/494751ef22b2e401adf23b92403e0bf3 to your computer and use it in GitHub Desktop.
programmerid: is a number for defining your programming decisions and showing it.
#!/usr/bin/env make
all:
$(CC) -o programmertype programmertype.c
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <string.h>
#define qlen 32
const char *questions[qlen-1][2] = {
{ "indent width", "8642", },
{ "tabs or spaces", "ts", },
{ "wrap at col 80", "yn", },
{ "spaces around =", "yn", },
{ "spaces around math operations (+-*/%)", "yn", },
{ "spaces before/after ++/-- signs;", "yn", },
{ "spaces before/after binary operations (^|&~)", "yn", },
{ "spaces before/after logical operations (||/&&)", "yn", },
{ "spaces before/after loop parenthesis", "yn", },
{ "spaces before/after paren in function arguments", "yn", },
{ "spaces after using commas/semicolons", "yn", },
{ "brace in newline in functions", "yn", },
{ "brace in newline in loops", "yn", },
{ "brace in newline in class/struct declerations", "yn", },
{ "brace in newline in others", "yn", },
{ "empty line after class/struct", "yn", },
{ "empty line after function", "yn", },
{ "empty line after control (loops/switch)", "yn", },
{ "empty line after imports/includes", "yn", },
{ "empty line after preprocessor statements (define/override/pragma)", "yn", },
{ "empty line after variable blocks", "yn", },
{ "matrices' elements are using multiple lines", "yn", },
{ "underscore or camelcase", "uc", },
{ "garbage collection, auto/manual", "am", },
{ "thinking or writing", "tw", },
{ "custom environment", "yn", },
{ "libraries/frameworks or from scratch", "ls", },
{ "object oriented or not", "on", },
{ "male/female", "mf", },
{ NULL, NULL, },
{ NULL, NULL, },
};
unsigned encode(void) {
char answer;
unsigned code = 0;
printf("%s? (%c/%c/%c/%c): ",
questions[0][0],
questions[0][1][0],
questions[0][1][1],
questions[0][1][2],
questions[0][1][3]
);
scanf(" %c", &answer);
for(int i=0;i<4;i++)
if(questions[0][1][i] == answer)
code = i;
for(int i=1;i<qlen;i++) {
if(!*(questions[i]))
continue;
answer = 0;
while(questions[i][1][0] != answer && questions[i][1][1] != answer) {
if(answer)
printf("wrong answer!\n");
printf("%s? (%c/%c): ",
questions[i][0], questions[i][1][0], questions[i][1][1]);
scanf(" %c", &answer);
}
code |= (questions[i][1][0] == answer)<<i;
continue;
}
printf("binary:");
for(int i=0;i<qlen;i++)
printf("%*d", (i%4)?1:2, (code>>i)&1);
printf("\n");
return code;
}
void decode(unsigned code) {
printf("binary:");
for(int i=0;i<qlen;i++)
printf("%*d", (i%4)?1:2, (code>>i)&1);
printf("\n");
printf("%s: %c\n", questions[0][0], questions[0][1][code&3]);
for(int i=1;i<qlen;i++) {
if(!*(questions[i]))
continue;
printf("%s: %c\n", questions[i][0], questions[i][1][(code>>i)&1]);
continue;
}
return;
}
int main(int argc, char **argv) {
setlocale(LC_ALL,"");
switch(argc) {
case 1:
printf("Result: %'10u\n",encode());
break;
default:
decode((unsigned)atoi(argv[1]));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment