#lang racket ;;;;********************************************************************** ;;; CS251 Fall 2020 T2 Solo D Problem 1 ;;; Your name: ;;;;********************************************************************** ;;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ;;; Problem 1: Diagonal Duples ;;;----------------------------------------------------------------------- ;;; Provided higher-order operations (define (genlist-apply next done? keepDoneValue? seed) (if (apply done? seed) (if keepDoneValue? (list seed) null) (cons seed (genlist-apply next done? keepDoneValue? (apply next seed))))) (define (iterate-apply next done? finalize state) (if (apply done? state) (apply finalize state) (iterate-apply next done? finalize (apply next state)))) ;;;----------------------------------------------------------------------- ;; You are given the following function. ;; In Problem 1a, explain what it returns (define (diagonal-duples n) (foldr append null (map (lambda (sum) (map (lambda (fst) (list fst (- sum fst))) (range 0 (+ sum 1)))) (range 0 (+ n 1))))) ;;;----------------------------------------------------------------------- ;; Flesh out the following skeleton for Problem 1b (define (diagonal-duples-genlist-apply n) ; Assume is n a nonnegative integer (genlist-apply 'next-function-goes-here 'done-function-goes-here 'keep-done-value-goes-here 'seed-goes-here )) ;;;----------------------------------------------------------------------- ;; Flesh out the following skeleton for Problem 1c (define (diagonal-duples-iterate-apply n) ; Assume is n a nonnegative integer (iterate-apply 'next-function-goes-here 'done?-function-goes-here 'finalize-function-goes-here 'initial-state-goes-here )) ;;;----------------------------------------------------------------------- ;; Flesh out the following skeleton for Problem 1d (define (diagonal-duples-iter n) (define (outer-tail ...outer-params...) (define (inner-tail ...inter-params...) 'inner-body-goes-here) 'outer-body-goes-here) (outer-tail 'args-go-here))