seahawk

Finished
1111//
1212
1313/**
14 * @param {number} num
15 * @returns {bigint}
14 * Calculate the number of grains on a specific square of a chessboard.
15 * Each square has twice as many grains as the previous square.
16 *
17 * @param {number} num - The square number (1-64)
18 * @returns {bigint} The number of grains on that square
19 * @throws {Error} If the square number is not between 1 and 64
1620 */
1721export const square = (num) => {
18 throw new Error('Remove this line and implement the function');
22 // Edge Case: Square number is less than 1
23 if (num < 1) {
24 throw new Error('square must be between 1 and 64');
25 }
26
27 // Edge Case: Square number is greater than 64
28 if (num > 64) {
29 throw new Error('square must be between 1 and 64');
30 }
31
32 // Calculate grains on square: 2^(n-1)
33 return 1n << BigInt(num - 1);
1934};
2035
2136/**
22 * @returns {bigint}
37 * Calculate the total number of grains on the entire chessboard.
38 * This is the sum of grains on all 64 squares.
39 *
40 * @returns {bigint} The total number of grains on the chessboard
2341 */
2442export const total = () => {
25 throw new Error('Remove this line and implement the function');
43 // The sum of 2^0 + 2^1 + 2^2 + ... + 2^63 = 2^64 - 1
44 return (1n << 64n) - 1n;
2645};
46
47// Handled Edge Cases:
48// - square(): Input less than 1 throws Error with message 'square must be between 1 and 64'
49// - square(): Input greater than 64 throws Error with message 'square must be between 1 and 64'
50// - square(): Valid inputs (1-64) return correct number of grains using bit shifting
51// - total(): Returns correct total grains using mathematical formula 2^64 - 1
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.