mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 06:43:09 -05:00
20 lines
312 B
C
20 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;
|
|
}
|