- if the number 1 is selected. The largest product will be 1 itself.
- For the number 2, we can use 1+1 or 2 itself. The larger product would be 2 since 1*1 = 1 which is smaller than 2.
- For the number 3, we can have 1+1+1, 1+2, and 3. Out of theses numbers 3 has the largest product.
- For number 4, we can have 1+1+1+1, 1+1+2, 1+3, 2+2, or 4. 4 would be the largest product.
- For number 5, we can have 1+1+1+1+1, 1+1+1+2, 1+1+3, 1+4, 2+2+1, 2+3 or 5. In this case, 2*3=6 would be the largest product.
- For number 6, we can have 1+1+1+1+1+1, 1+1+1+1+2, 1+1+1+3, 1+1+4, 1+5, 2+2+1+1, 2+2+2, 2+3+1, 2+4, 3+3, 6 etc... In this case, 3*3=9 would be the largest product.
By trying out these numbers, a pattern was quickly found and I realize that a recursion program would be able to solve this problem. Although I have not test the solution in Dr.Racket, the following code is what I have come up with.
(define max_product n
(cond (> n 4)
(cond (> n 4)
(* 3 (max_product (- n 3)))
)
(else n)
(else n)
)
Note that this code is only at its initial stage and might need changes and checks from Dr.Racket to be functional.
Term test two was held this week during the tutorial section. The parts involving Dr.Racket was straightforward. The two questions related to the knowledge of computer and internet was a bit harder in my opinion. The first question asks about the development of internet had if the government is essential for it. The second question asks about the difference today's browser and a terminal in the 1960s.
Also, project two has been posted on the course website. I will be looking into it and start working on it. This way, any question I have in the process can be solved by asking the TAs or the prof. ahead of time.
No comments:
Post a Comment