mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-14 07:10:48 -05:00
21 lines
312 B
C
21 lines
312 B
C
|
#include "grains.h"
|
||
|
#include <stdint.h>
|
||
|
|
||
|
uint64_t square(uint8_t index) {
|
||
|
|
||
|
if (index == 0 || index > MAX_SQUARES) {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
return (uint64_t)1 << (index - 1);
|
||
|
}
|
||
|
|
||
|
uint64_t total(void) {
|
||
|
|
||
|
uint64_t result = 1;
|
||
|
for (int i = 1; i <= MAX_SQUARES; i++) {
|
||
|
result += 1 << i;
|
||
|
}
|
||
|
return result;
|
||
|
}
|