Skip to content

Instantly share code, notes, and snippets.

@Qix-

Qix-/stupid-riddle.c Secret

Created Dec 15, 2020
Embed
What would you like to do?
#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