Name: Anonymous 2012-01-29 15:38
Just made this for you, /prog/
It's on my Github as well!
It's on my Github as well!
#include <stdio.h>
#include <stdlib.h>
#define FOREVER for(;;)
#define MAXBASE 16
typedef struct house {
struct house *prev;
struct house *next;
unsigned long int value;
} house;
int BASE = 2;
void check(unsigned long int num) {
house *first;
first = (house*)malloc(sizeof(house));
first->prev = NULL;
first->next = NULL;
first->value = num;
house *current = first;
house *aux = first;
FOREVER {
if(current->value < BASE) {
goto U_MAD;
}
else {
house *nexthouse;
nexthouse = (house*)malloc(sizeof(house));
nexthouse->prev = current;
nexthouse->next = NULL;
nexthouse->value = 0;
current->next = nexthouse;
while(current->value >= BASE) {
current->value -= BASE;
nexthouse->value += 1;
}
current = nexthouse;
}
}
U_MAD:
if(first->value == first->next->value) {
while(aux->next != NULL) {
aux = aux->next;
}
printf("Base %d : %X",BASE,aux->value);
while(aux->prev != NULL) {
aux = aux->prev;
printf("%X",aux->value);
}
printf("\n");
}
while(aux->next != NULL) {
aux = aux->next;
}
while(aux != first) {
aux->prev->next = NULL;
current = aux->prev;
free(aux);
aux = current;
}
free(first);
}
int main(int argc,char **argv) {
do {
check(atoi(argv[1]));
++BASE;
}while(BASE <= MAXBASE);
return EXIT_SUCCESS;
}