Wednesday, May 9, 2007

Small Programming Assignments

In a typical programming 101 class we write stand alone easy apps. In real life, we generally maintain ugly big apps with libraries not written by us. How we all miss the days where we can take full control of small programs. I recall some small programming assignments that trains the computer programmer. No bells and whistles pretty interface needed, just pure programming. Oh and you don't need a powerful machine to do these. If you find a compiler in a still running 8086 you can write code to implement these.

Pat and Vanna's tool
I'm sure you have watched Wheel of Fortune. Pat is able to tell you "there are 4 T" or "there are no N" in each puzzle. He has been counting alphabets on the fly for all these years. You can help his job easier by writing a program to count how many letters given each phrase. This lets you practice counters.

Factorial and Fibonacci
Factorial is classic example for recursion. You can view it as n!=n×(n-1)!, and 0!=1, or n!=1×2×3...×n. It can be implemented in a few lines.

The Fibonacci sequence is 1,1,2,3,5,8... Start with first two terms with 1 and 1. Find the next term by adding sum of previous two terms. you may not know how the mathematicians love it and its relationship with the golden ratio, but you can write n-th term programmatically. Is it advisable to do Fibonacci recursively?

Reverse a string
Enter a string, output the reverse. For example, enter "hello", return "olleh". Quite useless but it is a small exercise of accessing elements in an array. An atheist student decided to use "god" as test case and see if it return "dog". You only need to reverse half the string. Remember to handle the case of odd length. This can also be done recursively.

Maintain a linked list
In the beginning there are no good standard libraries and free Collection classes and we have to implement our own. We use a struct, with a "next" field to host a pointer to the same struct, thereby implementing a dynamic list. We can make our list sort on the fly by inserting the data in the right place. We also implement plain menus like 1-Add element, 2-Remove element, 3-Show List. Although the output is not impressive but it is a lot of tricky pointer assignmentss to make this work. One mistake you have to reboot. This program weeds out programmers wannabes when they can't handle the frustration.

You'll be surprised how many so called professional programmers don't know how to do any of these. Many programming in real life do nothing more than entering data and saving data.

1 comment:

Alex Mak said...

there are way too many untalented programmers out there. What they lack in programming skills they make up in being stealth with amazing suck-up (shoeshine) and BS skills.

For those talentless folks, these assignments are way too hard. They would never be able to do any of them.

For others, they wouldn't reinvent the wheel and look for libraries (e.g. STL ) to do much of the work.