| 15 | 15 | * @returns {bigint} |
| 16 | 16 | */ |
| 17 | 17 | export const square = (num) => { |
| 18 | throw new Error('Remove this line and implement the function'); | |
| 18 | // Edge Case: Square number is less than 1 | |
| 19 | if (num < 1) { | |
| 20 | throw new Error('square must be between 1 and 64'); | |
| 21 | } | |
| 22 | ||
| 23 | // Edge Case: Square number is greater than 64 | |
| 24 | if (num > 64) { | |
| 25 | throw new Error('square must be between 1 and 64'); | |
| 26 | } | |
| 27 | ||
| 28 | // Calculate grains on square using exponentiation | |
| 29 | // Square n has 2^(n-1) grains | |
| 30 | return 1n << BigInt(num - 1); | |
| 19 | 31 | }; |
| 20 | 32 | |
| 21 | 33 | /** |
| 22 | 34 | * @returns {bigint} |
| 23 | 35 | */ |
| 24 | 36 | export const total = () => { |
| 25 | throw new Error('Remove this line and implement the function'); | |
| 37 | // Calculate total grains using formula 2^64 - 1 | |
| 38 | // This is the sum of a geometric series where a=1, r=2, n=64 | |
| 39 | return (1n << 64n) - 1n; | |
| 26 | 40 | }; |
| 41 | ||
| 42 | // Handled Edge Cases: Square number less than 1, square number greater than 64 | |
| 43 | // Handled Edge Cases: None (function always returns the same constant value) |