kale

Finished
1515 * @returns {bigint}
1616 */
1717export const square = (num) => {
18 throw new Error('Remove this line and implement the function');
18 // Edge Case: Input is not a number
19 if (typeof num !== 'number' || isNaN(num)) {
20 throw new Error('square must be between 1 and 64');
21 }
22
23 // Edge Case: Input is not an integer
24 if (!Number.isInteger(num)) {
25 throw new Error('square must be between 1 and 64');
26 }
27
28 // Edge Case: Square number less than 1
29 if (num < 1) {
30 throw new Error('square must be between 1 and 64');
31 }
32
33 // Edge Case: Square number greater than 64
34 if (num > 64) {
35 throw new Error('square must be between 1 and 64');
36 }
37
38 // Calculate grains on the square (2^(n-1))
39 return 1n << BigInt(num - 1);
1940};
2041
2142/**
2243 * @returns {bigint}
2344 */
2445export const total = () => {
25 throw new Error('Remove this line and implement the function');
46 // The total number of grains is 2^64 - 1
47 // This is a mathematical sum of 1 + 2 + 4 + ... + 2^63
48 return (1n << 64n) - 1n;
2649};
50
51// Handled Edge Cases: square number less than 1, square number greater than 64, non-integer square numbers, handling very large numbers that exceed standard integer limits
Test NameStatus
grains on square 1
Pass
grains on square 2
Pass
grains on square 3
Pass
grains on square 4
Pass
grains on square 16
Pass
grains on square 32
Pass
grains on square 64
Pass
square 0 raises an exception
Pass
negative square raises an exception
Pass
square greater than 64 raises an exception
Pass
returns the total number of grains on the board
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.