function [grains, total] = chessboard(n)
%CHESSBOARD Grains of rice on a chessboard.
%   [GRAINS, TOTAL] = CHESSBOARD(N) returns the number of grains GRAINS of
%   rice on square N of a chessboard, and the the total number of grains
%   TOTAL on squares 1 through N.
%
%   For N=1, GRAINS=1. For any other positive value of N,
%   GRAINS = 2 * CHESSBOARD(N - 1); i.e., the number of grains of rice
%   doubles for each subsequent square.

G = 2 .^ [0:(n - 1)];
grains = G(end);
total = sum(G);

end

