6.s096 2013

6.s096 2013 Diagnostic Test

Due: Tuesday, January 1, 2013 11:59pm
Send Questions To: 6.s096-staff@mit.edu

Complete these 3 tasks using any programming language within reason. Since this is a diagnostic test, you should work individually.

To 6.s096-staff@mit.edu 6.s096 Diagnostic Test Include your name, Athena username, class year, and course number The source code for your solutions (as separate files, not a zip, if possible)

The staff will respond by the end of the semester.

The Fibonacci Sequence is the familiar integer sequence: { 0, 1, 1, 2, 3, 5, 8, 13, … } where the nth term is the sum of the previous 2 terms:

fib(0) = 0
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2)

Write a function named fib that calculates the nth term in the Fibonacci sequence for a given n. For example:

 fib(0) returns 0 fib(1) returns 1 fib(2) returns 1 fib(3) returns 2 fib(4) returns 3 fib(5) returns 5 fib(6) returns 8 fib(7) returns 13

Write a function named reverse that returns a given string with the order of all words reversed. Words are separated by a single space. For example:

reverse("I would like to learn C") returns "C learn to like would I"
reverse("wonder") returns "wonder"
reverse("My?! Computer#123") returns "Computer#123 My?!"