A recursive, but not higher order function viral-growth that returns a list of the minute-by-minute growth when one person spreads a video to three other people per minute:
(define (viral-growth mins ppl)
(if (= 0 mins)
'()
(cons (* 3 ppl) (viral-growth (- mins 1) (* 3 ppl)))))
(viral-growth 4 1)
'(3 9 27 81)
And a higher order function repeated that returns another function, f, applied count times:
(define (repeated f count)
(lambda (x)
(if (= count 0)
x
(f ((repeated f (- count 1)) x)))))
((repeated add-one 3) 1)
4
For this final lab question, rewrite viral-growth so that it can be passed to repeated and so that the count variable of repeated (rather than a mins variable in viral-growth) determines how many minutes of viral growth pass. Rewrite viral-growth to accept only one argument, the number of people who start the spread, and to return a lambda that accepts a list argument.
(define (viral-growth ppl)
(lambda (ls)
… your code goes here …
If you rewrite viral-growth correctly, you should be able to pass it to repeated as follows:
((repeated (viral-growth 1) 4) '())
'(3 9 27 81)
Sample Solution