Sunday, November 25, 2012

Almost there!



I completed tutorial 9 exercises today. I had a little bit of trouble fixing the definition for spiral when I started yesterday. But I came back to it today and I was just overcomplicating the definition, trying to include more than I needed to. For make-palindrome I used the Help Desk to look up something in place of equal? since Dr. Racket should return the string as is for strings of length 0 (empty) and 1. I tried
                (>= 1 (string-length s)
and all of the check-expects passed.

I got stuck on fixing writing the check-expects for interpolate-image in Project 2. I looked up local in the Help Desk to help me understand what the function was supposed to do. I still couldn't figure it out so I left it for a few more days. I tried it again on Wednesday after class and I got both check-expects to pass. Turns out I was just trying to overcomplicate it again. Project 2 was shorter and seemed simpler to me than the first project.

I've been thinking about what algorithm to write up. I've decided to write an approach for a simple algorithm: finding the greatest number in a list of numbers. I looked over and used the approach suggested by Polya that includes 4 steps to solve a problem:

1. Understand the problem.
                What is the unknown? Which number is the largest and its value.
                What are the data? A list of numbers.
2. Devise a plan.
               
Find the connection between the data and the unknown. The unknown is a number from the   list.
                Plan: start at the beginning and go one at time through the list.
3. Carry out the plan.
4. Look Back
               
Examine the solution obtained. 

So here is my set of written instructions:

1. Look at the 1st number, assume it is the greatest in the list and call it so.
                If there is only 1 number in the list then you are done.
                If the list is greater than 1 number, go to step 2.
2. Look at the next  number in the list and identify if it is greater than the "greatest" number?
                If yes, replace it as the greatest number, and repeat step 2 until the end of the list is reached.
                If not, keep the "greatest" number as is, and repeat step 2 until you reach the end of the list.

I really enjoy working on the exercises and projects for this class because I look at them like puzzles that need solving and I like using numbers without complicated calculations. And now I am happy because I have finished everything I set out to do today.

No comments:

Post a Comment