Sha256: 8d12bc1f8cb63f78339f7185e79781c3b02d8896cf912341642424cef5121674

Contents?: true

Size: 731 Bytes

Versions: 255

Compression:

Stored size: 731 Bytes

Contents

var BigInt = require('./big-integer');

/**
 * @author github.com/nonsensery
 * @class Grains
 *
 * Computes the number of grains on the squares of a
 * chess board, starting with one grain on the first
 * square, and doubling with each successive square.
 */
function Grains() {
  // no op!
}

/**
 * Gets the number of grains on the nth square.
 */
Grains.prototype.square = function(num) {
  return BigInt(2).pow(num - 1).toString();
};

/**
 * Gets the total number of grains on all squares.
 */
Grains.prototype.total = function () {
  var total = BigInt(0);

  for (var squareNum = 1; squareNum <= 64; ++squareNum) {
    total = total.add(this.square(squareNum));
  }

  return total.toString();
};

module.exports = Grains;

Version data entries

255 entries across 255 versions & 1 rubygems

Version Path
trackler-2.2.1.37 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.36 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.35 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.34 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.33 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.32 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.31 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.30 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.29 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.28 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.27 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.26 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.25 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.24 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.23 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.22 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.21 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.20 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.19 tracks/javascript/exercises/grains/example.js
trackler-2.2.1.18 tracks/javascript/exercises/grains/example.js