commit fb3a4e6b95eaff75f8e2952039e6367e27671e67
parent d43303ce4aaa5e21c99deaec2aa0fcde213aad75
Author: dwrz <dwrz@dwrz.net>
Date: Mon, 22 Apr 2019 01:17:19 +0000
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.
Diffstat:
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/c/grains/src/grains.c b/c/grains/src/grains.c
@@ -1,9 +1,8 @@
#include "grains.h"
unsigned long long square(int n) {
- if (!validSquare(n)) return 0;
- if (n == 1) return 1;
- return 2llu << (n-2);
+ if (n < 1 || n > 64) return 0;
+ return 1ull << (n-1);
}
unsigned long long total() {