Mathematical approach

You have to understand the problem.

What is the unknown? What are the data? What is the condition? Is it possible to satisfy the condition? Is the condition sufficient to determine the unknown? Or is it insufficient? Or redundant? Or contradictory?

Draw a figure. Introduce suitable notation.

Separate the various parts of the condition.

Can you write them down?

Find the connection between the data and the unknown.

You may be obliged to consider auxiliary problems if an immediate connection cannot be found. You should obtain eventually a plan of the solution.

\alpla Have you seen it before? Or have you seen the same problem in a slightly different form?

β Do you know a related problem? Do you know a theorem that could be useful?

γ Look at the unknown! And try to think of a familiar problem having the same or a similar unknown.

δ Here is a problem related to yours and solved before. Could you use it? Could you use its result? Could you use its method? Should you introduce some auxiliary element in order to make its use possible?

ε Could you restate the problem? Could you restate it still differently? Go back to definitions.

ζ If you cannot solve the proposed problem try to solve first some related problem. Could you imagine a more accessible related problem? A more general problem? A more special problem? An analogous problem? Could you solve a part of the problem? Keep only a part of the condition, drop the other part; how far is the unknown then determined, how can it vary? Could you derive something useful from the data? Could you think of other data appropriate to determine the unknown? Could you change the unknown or the data, or both if necessary, so that the new unknown and the new data are nearer to each other?

η Did you use all the data? Did you use the whole condition? Have you taken into account all essential notions involved in the problem?

Carry out your plan.

Carrying out your plan of the solution, check each step.

  • Can you see clearly that the step is correct?
  • Can you prove that it is correct?

Examine the solution obtained.

  • Can you check the result?
  • Can you check the argument?
  • Can you derive the result differently?
  • Can you see it at a glance?
  • Can you use the result, or the method, for some other problem?

Functional method

From Problem Analysis to Data Definitions

Identify the information that must be represented and how it is represented in the chosen programming language. Formulate data definitions and illustrate them with examples.

Signature, Purpose Statement, Header

State which data the desired function consumes and produces. Articulate what the function computes as a concise one-line statement. Define a stub that lives up to the signature.

Functional Examples

Work through examples that illustrate the function’s purpose.

Function Template

Translate the data definitions into an outline of the function.

Function Definition

Fill in the gaps in the function template. Exploit the purpose statement and the examples.


Articulate the examples as tests and ensure that the function passes all. Doing so discovers mistakes and also helps others read and understand the definition when the need arises—and it will arise for any serious program.

Coder's technique

blog comments powered by Disqus


11 January 2017


literate programming programming fundamentals