Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname |23.2|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 ;a-fives : N[>=0] -> number
5 ;Given n, determine recursively the value of the n-th term in the series 8, 13, 18, etc. where the first term has an index 0.
7 (define (a-fives n)
8 (cond
9 [(zero? n) 8]
10 [else (+ 5 (a-fives (sub1 n)))]))
12 ;a-fives-closed : N[>=0] -> number
13 ;A non-recursive function for finding the n-th term of the series 8, 13, 18, etc., where the first term has an index 0.
15 (define (a-fives-closed n)
16 (+ (* n 5) 8))
18 ;series : (N[>=0] -> number) N[>=0] -> number
19 ;Given a-term and n, determine the sum of the first n-th terms in the sequence a-term.
21 (define (series a-term n)
22 (cond
23 [(zero? n) (a-term n)]
24 [else (+ (a-term n)
25 (series a-term (sub1 n)))]))
27 ;sequence : (N -> number) N -> (listof number)
28 ;Given a-term and n, generate the sequence of the first nth terms in a-term as a (listof numbers).
30 (define (sequence a-term n)
31 (build-list n a-term))
33 (define (seq-a-fives n)
34 (sequence a-fives-closed n))
36 ;arithmetic-term : N number -> (N -> number)
37 ;Given start and s (summand), return a function that consumes a natural number n and returns the nth-term in the arithmetic sequence.
38 (define (arithmetic-term start s)
39 (local ((define (a-term n)
40 (+ (* n s) start)))
41 a-term))
43 (define a-fives2 (arithmetic-term 8 5))
44 (define evens (arithmetic-term 0 2))
46 ;g-fives : N -> number
47 ;Recursively returns the nth term of the geometric sequence: 3, 15, 75, 275, ...
48 (define (g-fives n)
49 (cond
50 [(zero? n) 3]
51 [else (* 5 (g-fives (sub1 n)))]))
53 ;g-fives-closed : N -> number
54 ;Non-recursively returns the nth term of the geometric sequence: 3, 15, 75, 275, ...
55 (define (g-fives-closed n)
56 (* (expt 5 n) 3))
58 ;seq-g-fives : N -> (listof numbers)
59 ;Given n, returns a list of the first n-th terms in the g-fives sequence.
61 (define (seq-g-fives n)
62 (build-list n g-fives-closed))
64 ;geometric-series : number number -> (N -> number)
65 ;Given start and s, returns a function who computes the n-th term (where n is a natural number) of the geometric series with first term start with ratio s.
67 (define (geometric-series start s)
68 (local ((define (g-term n)
69 (* (expt s n) start)))
70 g-term))
72 (define g-fives2 (geometric-series 3 5))