Refactor grains/square

Check internally for valid squares.

Shift on 1, not two -- the first bit is to mark 0 and 1, and shifting it once will turn it into 2.
This commit is contained in:
dwrz
2019-04-22 01:17:19 +00:00
parent d43303ce4a
commit fb3a4e6b95
+2 -3
View File
@@ -1,9 +1,8 @@
#include "grains.h" #include "grains.h"
unsigned long long square(int n) { unsigned long long square(int n) {
if (!validSquare(n)) return 0; if (n < 1 || n > 64) return 0;
if (n == 1) return 1; return 1ull << (n-1);
return 2llu << (n-2);
} }
unsigned long long total() { unsigned long long total() {