Write the function mult-table which consumes two natural numbers nr and nc, and produces a list of nr lists, each of which contains nc natural numbers. The cth entry of the rth list (where we start numbering at 0) in the produced list should be r*c.
For example, (mult-table 2 3) => (list (list 0 0 0) (list 0 1 2))
and (mult-table 3 4) =>
(list (list 0 0 0 0)
(list 0 1 2 3)
(list 0 2 4 6)).
Hint: use build-list twice. The first time, try to make a list containing nr elements. Then, for each of these elements, make a list of nc elements. You may use other abstract list functions as well.
(define (mult-table nr nc)
(define (iter-table r)
(define (iter-row c)
(if (< c nc)
(cons (* r c)
(iter-row (+ c 1)))
'()))
(if (< r nr)
(cons (iter-row 0)
(iter-table (+ r 1)))
'()))
(iter-table 0))
Of course, this doesn't use the build-list procedure you're supposed to use, because you provide it, so you probably won't get full credit.
What school are you attending that teaches Scheme?
Solution in OCaml:
let generate_list x y =
let rec aux pas init indice =
if indice = y then []
else init::(aux pas (init + pas) (indice + 1))
in aux x 0 0 ;;
let multtable x y =
let rec aux indice = if indice = x then []
else (generate_list indice y)::(aux (indice + 1))
in aux 0 ;;