08 March 2013

Problem Solving as Programming Principle: Begin with the end in mind.

Problems can be solved by different algorithms:

First, a solution is reached by the obvious way. Then, secondly, it is getting to the solution by the methodological or structural way. Then, you have the “smart” way, meaning, using clever insight into the different aspects of the algorithm, thereby devising the best approach to the problem. I would say that this is the best problem solving algorithm. Lastly, but not the least, is the serendipitous way. But this last method relies almost on a hunch.  Hunches are not bad at all. But the problem with that is the inability to write the solution so as to get the right results given different values.

Once, a young lady came up with a question which had to do with an item that she bought at a discounted price. She knew how much she finally paid, but did not know the actual discount percentage. Then her older sister said that the percentage was such and such. She just "knew" the answer but could not explain how she got it. I, in the meantime, wrote out the equation on paper and did the calculations by testing the algorithms I came up with. Well, I did get the same answer as the older sister. We were both right, the difference being that I could repeat the calculations with different variables. She, on the other hand, could not verify her answer.

This is what we are after, devising the best algorithm so as to be able to come up with the ideal solution regardless of the variables, meaning, reproducible results. We cannot rely on hunches or even educated guesses. As in evidence-based medicine, we rely on logical, verifiable methods, taking into consideration all the possible variations as well as mitigating circumstances. Even if one had a eureka moment, we still have to verify the methods involved. That is the hallmark of science- reproducible results. It is a discipline.

To code or not to code…

Given the conditions above, there is then the question: do I need to develop programs? The path to this activity has six points to follow along the way. We will go over those six points briefly.

   1.)  Do I need a program for myself, for my own needs? Or for others’ needs? Question: What are my goals? If you were to write a program for yourself, or for the department you were working in, then you have a stronger motivation, whether or not you were compensated materially for it.

    2.)  What do I hope to achieve, or to make progress in? Think more, and think better. Considering the path that lies along the programming road, you will do well to concentrate on the different activities that are necessary for this task. (e.g. seminars, classes, online training). Become a project manager at heart.

    3.)  Can I do it on my own? Or, do I invite others to collaborate in the project? Feel competent! If you must work alone, do so, remembering that your battles will be yours alone. There are circumstances when working alone is of utmost importance. Like, for example writing a program as part of school tests. Otherwise, there is strength in numbers, and it would be best for the project to form some team for collaboration. Which brings us to the next point…

    4.)  Equip yourself, equip others. Study well what you’ll need. Prepare, prepare, prepare. As mentioned before, get a good look at what you need to do to continue working strong. And if you’re part of a team, your good insights will strengthen everybody as well. No man is an island in this scenario.

    5.)  Follow set guidelines, follow through with development milestones. Be disciplined, not stressed out. Stick to the roadmap, and in so doing you will be avoiding latency. In the aspect of agile development, cooperation throughout the course will give a more holistic view, as well as strength.

    6.)  Give credit to whom it is due, to others and yourself as well. This may be the most important factor for the success of the project and the group itself. Let everybody own the project. That way the outcome is far better than a lackadaisical product.

Reward hard work along the way.

Now that we have laid out the rules, let’s take a look at some code which will be useful, not just for today’s purpose, but will serve as a template if you will.

The code is in C++, and is a snippet for converting temperature from the Centigrade format to the Fahrenheit one, and vice versa. Use the tools we talked about in the previous post, and which are repeated for you below.

Convert Temperatures from Celsius to Fahrenheit and vice versa.

   #include <iostream.h>
   #include <conio.h>
   void main()
        int choice;
        float ctemp,ftemp;
        cout << "1.Celsius to Fahrenheit" << endl;
        cout << "2.Fahrenheit to Celsius" << endl;
        cout << "Choose between 1 & 2 : " << endl;
        if (choice==1)
          cout << "Enter the temperature in Celsius : " << endl;
         cout << "Temperature in Fahrenheit = " << ftemp << endl;
          cout << "Enter the temperature in Fahrenheit : " << endl;
          cout << "Temperature in Celsius = " << ctemp << endl;


Tools for C, C++

C++ Standards Foundation website http://isocpp.org/,

C++ FAQ from its founder’s website http://www.stroustrup.com/

C and C++ Programming tutorials http://www.cprogramming.com/tutorial.html

MinGW-Minimalist GNU for Windows http://www.mingw.org/

MinGW –W64 for 32 and 64 bit Windows http://mingw-w64.sourceforge.net/

ARM Linux GCC – OS X Mountain Lion (Mac, of course) http://www.benmont.com/tech/crosscompiler.html

For Commercial Options:

Embarcadero C++ Builder XE3 for Windows 8 and Mac http://www.embarcadero.com/products/cbuilder


Other application tools  you can use:

For structural biology, check out:
COMPLEAT – Protein Complex Enrichment Analysis Tool

For statistical operations,
the R language is a really good tool.

The Comprehensive R Archive Network

R bioinformatics Packages (for genetics)-Bioconductor

R Graph Gallery

A collection of graphics entirely generated with R.

R Projects of interest

Good Read:

Science Magazine online http://www.sciencemag.org/

Stay Curious. Stay Busy.

Fernando Yaakov Lalana, M.D.

No comments:

Post a Comment