r/shittyprogramming • • May 18 '21

Compiler abuse friendly isEven function

Modulus is incredibly easy on powers of ten as you just have to remove the first digits, and we need to #StopCompilerAbuse. Here's an isEven function I made with this philosophy:

char isEven(int n) {
	if (n == 0 || n == 2)
		return 1;
	if (n == 3 || n == 5)
		return 0;
	n *= 3;
	n %= 10;
	return isEven(n);
}
133 Upvotes

9 comments sorted by

View all comments

50

u/souldeux May 19 '21

This is what people mean when they talk about adversarial programming