| 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: Non-integer input | |
| 19 | if (!Number.isInteger(num)) { | |
| 20 | throw new Error('square must be between 1 and 64'); | |
| 21 | } | |
| 22 | ||
| 23 | // Edge Case: Square number less than 1 | |
| 24 | if (num < 1) { | |
| 25 | throw new Error('square must be between 1 and 64'); | |
| 26 | } | |
| 27 | ||
| 28 | // Edge Case: Square number greater than 64 | |
| 29 | if (num > 64) { | |
| 30 | throw new Error('square must be between 1 and 64'); | |
| 31 | } | |
| 32 | ||
| 33 | // Calculate grains on square (2^(n-1)) | |
| 34 | return 1n << BigInt(num - 1); | |
| 19 | 35 | }; |
| 20 | 36 | |
| 21 | 37 | /** |
| 22 | 38 | * @returns {bigint} |
| 23 | 39 | */ |
| 24 | 40 | export const total = () => { |
| 25 | throw new Error('Remove this line and implement the function'); | |
| 41 | // Calculate total grains on all 64 squares (2^64 - 1) | |
| 42 | return (1n << 64n) - 1n; | |
| 26 | 43 | }; |
| 44 | ||
| 45 | // Handled Edge Cases: square number less than 1, square number greater than 64, non-integer square numbers | |
| 46 | // Handled Edge Cases: calculating total for all 64 squares |