| 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 formula: 2^(n-1) | |
| 29 | return 1n << BigInt(num - 1); | |
| 19 | 30 | }; |
| 20 | 31 | |
| 21 | 32 | /** |
| 22 | 33 | * @returns {bigint} |
| 23 | 34 | */ |
| 24 | 35 | export const total = () => { |
| 25 | throw new Error('Remove this line and implement the function'); | |
| 36 | // Calculate total grains using formula: 2^64 - 1 | |
| 37 | return (1n << 64n) - 1n; | |
| 26 | 38 | }; |
| 39 | ||
| 40 | // Handled Edge Cases: Square number less than 1, square number greater than 64 | |
| 41 | // Handled Edge Cases: None (this function always returns the same constant value) |