grains.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var BigInt = require('./big-integer');

var Grains = function() {
  var NUMBER_OF_SQUARES = 64;

  this.total = function() {
    // 2**0 + 2**1 + ... 2**(n-1) = (2**n) - 1
    return BigInt(2).pow(NUMBER_OF_SQUARES).subtract(1).toString();
  };

  this.square = function(n) {
    return BigInt(2).pow(n-1).toString();
  };
};

module.exports = Grains;

Comments


You're not logged in right now. Please login via GitHub to comment