69 lines
1.2 KiB
C
69 lines
1.2 KiB
C
|
#include "neat_macro.h"
|
||
|
|
||
|
int p_six_digit(char* s) {
|
||
|
int counter = 0;
|
||
|
for(char* c=s; *c!='\0'; c++) {
|
||
|
counter++;
|
||
|
}
|
||
|
|
||
|
return (counter == 6);
|
||
|
}
|
||
|
|
||
|
int p_double(char *s) {
|
||
|
char last_char = '\0';
|
||
|
int last_char_rep = 0;
|
||
|
for (char *c = s; *c!='\0'; c++) {
|
||
|
if(last_char == *c) { // found a rep
|
||
|
last_char_rep++;
|
||
|
}
|
||
|
|
||
|
if(last_char != *c && last_char_rep == 1) { // found it
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
if(last_char != *c) { // not found, just reset rep counter
|
||
|
last_char_rep = 0;
|
||
|
}
|
||
|
|
||
|
last_char = *c;
|
||
|
}
|
||
|
|
||
|
if (last_char_rep == 1) { // found it
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int p_decrease(char *s) {
|
||
|
char last_char = '\0';
|
||
|
for (char *c = s; *c!='\0'; c++) {
|
||
|
if ((last_char - '0') > (*c - '0')) return 0;
|
||
|
last_char = *c;
|
||
|
}
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
int start = atoi(argv[1]);
|
||
|
int end = atoi(argv[2]);
|
||
|
|
||
|
int count = 0;
|
||
|
for(int i=start; i<end; i++){
|
||
|
char buf[7];
|
||
|
snprintf(buf, 7, "%d", i);
|
||
|
|
||
|
if ((i % 100000)==0) {
|
||
|
log("At %d/%d %f%%\n", i, end, (((double)i) / end) * 100);
|
||
|
log("At %s\n", buf);
|
||
|
}
|
||
|
|
||
|
if(p_six_digit(buf) && p_double(buf) && p_decrease(buf)){
|
||
|
count++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
printf("Numbers: %d\n", count);
|
||
|
}
|