11-01-2013 HW*

posted Nov 1, 2013, 3:51 AM by Samuel Konstantinovich   [ updated Nov 4, 2013, 5:02 AM ]
Update: Practice recursion problems added to the list of challenge problems click on "Practice Recursion problems, Solutions, Challenge Problems." they are optional but will help you do better. 

New Problems:

1. Write a function (sumSquaresAtoB a b) 
it takes all of the numbers from a to b inclusive, squares them, and adds those squares together. 
(sumSquareAtoB 3 5)  means 3*3 + 4*4 + 5*5  which is 50.
(sumSquareAtoB 10 12) means  10*10 + 11*11 + 12*12   which is 365.

If this problem is tricky, go do the practice recursion problems first!

2. Write a function (sumSquaresList L) which adds all the squares of each element of a list. Assume L has no sublists.
(sumSquaresList '() ) -> 0
(sumSquaresList '(3 1) ) -> 10
(sumSquaresList '(1 2 3) ) -> 14

3. Write a function (sumSquaresSubList L) which adds all the squares of each element of a list. L may contain sublists.
(sumSquaresSubList '( ) ) -> 0
(sumSquaresSubList '( ()  ()   (   ( )  )  ) ) -> 0
(sumSquaresSubList '( (1 2)  ()   (   (3 )  )  ) ) -> 14
(sumSquaresSubList '( (1 2)  (4)   (   (3 ) 5 )  ) ) -> 55


Submit the following functions on HW server in a single plain text file. Make sure the names are spelled the same way I give you here, and that you test your functions. Deadline is Sunday November 3rd 10:52pm.
This HW counts as 3 homework submissions. DO NOT WAIT UNTIL SUNDAY to complete this assignment.  
(printHail n)
(hanoi n a b c)
(prime? n)
(sumSquareAtoB a b)
(sumSquaresList L)
(sumSquaresSubList L)
Comments