grains
module.
#lang racket
The functions grains.rkt needs to export are square and total.
(provide square total)
The definition of square
is simple:
$\displaystyle \text{square}\ n = 2n - 1$
(define (square n) (expt 2 (sub1 n)))
The total
is the sum of the number of grains of wheat on every square,
i.e. $\displaystyle ∑n=164 2n - 1$.
\begin{align*}
∑n=1k 2n - 1 &= 2^k &- 1
∑n=164 2n - 1 &= 264 &- 1 \
\text{total} &= 265 - 1 &- 1 \
&= \text{square}\ 65 &- 1
\end{align*}
(define (total) (sub1 (square 65)))