|
Final Review Problems Spring Semester 2004 |
1. Write a program that reads a sentence and reports the number of times each letter occurs.
2. Write a program that produces scalable patterns in the shape of the uppercase letter K.
3. Write a program that reads a number (say, 48) and adds it to the number obtained by writing the number backwards. So given 48 it would compute 48 + 84. Given 123 it would calculate 123 + 321, and so on.
4. Write a program that prints the first 15 numbers whose sum of their digits is divisible by 7.
5. Calculate and print the first 30 terms of the sequence defined by the following equations: G(0) = 0 and G(n) = n - G(G(n-1)). This is known as Hofstadter's G sequence.
6. Start with a string of 61 characters that starts with "(" and ends with ")". Characters with index 1-29 and 31-59 should have spaces. The character with index 30 should be an asterisk. Now apply the following rule for each character in the string with index i: if there are one or two (but not more or less) asterisks in positions i-1, i, i+1, then the character with index i will be an asterisk. Otherwise it will be a space. Calculate all characters in parallel and then print the next form of the string for 30 iterations. Leave the parens untouched. You should obtain the following pattern:
( *** ) ( ** ** ) ( ******* ) ( ** ** ) ( **** **** ) ( ** ** ** ** ) ( *************** ) ( ** ** ) ( **** **** ) ( ** ** ** ** ) ( ******** ******** ) ( ** ** ** ** ) ( **** **** **** **** ) ( ** ** ** ** ** ** ** ** ) ( ******************************* ) ( ** ** ) ( **** **** ) ( ** ** ** ** ) ( ******** ******** ) ( ** ** ** ** ) ( **** **** **** **** ) ( ** ** ** ** ** ** ** ** ) ( **************** **************** ) ( ** ** ** ** ) ( **** **** **** **** ) ( ** ** ** ** ** ** ** ** ) ( ******** ******** ******** ******** ) ( ** ** ** ** ** ** ** ** ) (**** **** **** **** **** **** **** ****) (* ** ** ** ** ** ** ** ** ** ** ** ** ** ** *) (***********************************************************)