-
-
Save Qix-/d70281a74ba4fca58566a56cd2030e8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
static inline void decompose(int i, char *buf) { | |
buf[0] = i / 100; | |
buf[1] = (i / 10) % 10; | |
buf[2] = i % 10; | |
} | |
static inline int rule1(char *buf) { | |
return buf[0] == 6 || buf[1] == 8 || buf[2] == 2; | |
} | |
static inline int rule2(char *buf) { | |
return | |
buf[1] == 6 || buf[2] == 6 | |
|| buf[0] == 1 || buf[2] == 1 | |
|| buf[0] == 4 || buf[1] == 4; | |
} | |
static inline int rule3(char *buf) { | |
int wrong = 0; | |
wrong += (buf[1] == 2) ^ (buf[2] == 2); | |
wrong += (buf[0] == 0) ^ (buf[2] == 0); | |
wrong += (buf[0] == 6) ^ (buf[1] == 6); | |
return wrong == 2; | |
} | |
static inline int rule4(char *buf) { | |
for (int i = 0; i < 3; i++) { | |
if (buf[i] == 7 || buf[i] == 3 || buf[i] == 8) { | |
return 0; | |
} | |
} | |
return 1; | |
} | |
static inline int rule5(char *buf) { | |
return | |
buf[1] == 7 || buf[2] == 7 | |
|| buf[0] == 8 || buf[2] == 8 | |
|| buf[0] == 0 || buf[1] == 0; | |
} | |
int main(void) { | |
char buf[3]; | |
for (int i = 0; i <= 999; i++) { | |
decompose(i, buf); | |
if ( | |
rule1(buf) | |
&& rule2(buf) | |
&& rule3(buf) | |
&& rule4(buf) | |
&& rule5(buf) | |
) { | |
printf("%d\n", i); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment