#lang racket ;;;;********************************************************************** ;;; CS251 Spring 2017 PS6 ;;; Your name: ;;;;********************************************************************** ;;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ;;; Solo Problem 1: Diagonal Duples ;;;----------------------------------------------------------------------- ;; You are given the following function. ;; In Problem 1a, explain what it returns (define (diagonal-duples n) (foldr append null (map (λ (sum) (map (λ (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...) ...outer-body...) (outer-tail ...args...)) ;;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ;;; Helper Functions from PS5 and iteration lectures (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))))