Step 1: Begin with a very basic version. The purpose of this step is to get a compilable "frame", which you will later build on.
Step 2: Start working on mathematics. Begin with as direct and primitive approach as possible. This version doesn't yet include any distracting technicalities as, say, a loop (for those who are not comfortable). The purpose of this step is to get a working code that produces the correct result in a sample case.
Step 3: Analyse repetitions, observe pattern(s), generalize. Concentrate on one thing at a time. In this version I concentrated on the loop. Alternatively, a nice user interface could be implemented before.
Step 4: After the basic functionality has been achieved for more or less general data, round up nicely. Final version