; Please submit on websubmission (your marks will be automatically assigned by the testing script)
; I will go over the submissions to pick a few nice looking solutions to share during the lectures. If you don’t want your code to be shared, please add a comment saying so in your file.
; All problems can be solved using what we have already covered. Feel free to use more advanced features though.
; The deadline is Aug 19th 23:59:59PM
; Note: Unfortunately, websubmission does not allow us to use “sicp Scheme” (e.g., #lang sicp). Instead, we have to use “r5rs Scheme”.
; These two flavors are almost identical.
; The only difference you need to care about for now is that you have to define “inc”, “dec”, and “identity” yourself if you want to use them (sicp Scheme has these functions built in).
; For detailed difference, please refer to https://docs.racket-lang.org/sicp-manual/index.html
; If you installed DrRacket and you are running Linux, you should already have a command called “plt-r5rs”.
; You should run this file using “plt-r5rs assignment1.scm” instead of “racket assignment1.scm”. (Websubmission calls your code using “plt-r5rs assignment1.scm”)
; question 1 (2.5%)
; If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
; Find the sum of all the multiples of 3 or 5 below 1000.
(define (sum-of-multiples n)
0 ; write this function, feel free to add additional helper functions
)
(display (sum-of-multiples 1000)) ; don’t change this line
(display ” “) ; don’t change this line
; question 2 (2.5%)
; The sum of the squares of the first ten natural numbers is,
; 1^2 + 2^2 + … + 10^2 = 385
; The square of the sum of the first ten natural numbers is,
; (1 + 2 + … + 10)^2 = 55^2 = 3025
; Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
; Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
(define (square-of-sum-minus-sum-of-squares n)
0 ; write this function, feel free to add additional helper functions
)
(display (square-of-sum-minus-sum-of-squares 100)) ; don’t change this line
(display ” “) ; don’t change this line
; question 3 (5%)
; Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
; By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
(define (sum-even-fib n)
0 ; write this function, feel free to add additional helper functions
)
(display (sum-even-fib 4000000)) ; don’t change this line
(display ” “) ; don’t change this line