# Algorithmic code

Algorithmic code is code that calculates or makes decisions. It can be either stateful or stateless.

Example algorithmic code:

``````def regression(data):
"""Calculate linear regression"""
average_x = 0.0
average_y = 0.0
for i in data:
average_x += i / len(data)
average_y += i / len(data)

total_xy = 0
total_xx = 0

for i in data:
total_xx += (i - average_x) ** 2
total_xy += (i - average_x) * (i - average_y)

m = total_xy / total_xx
c = average_y - m * average_x
return m, c
``````

It does not interact with I/O and, where it does interact with APIs, will solely interact with APIs surrounding simple, self contained algorithmic code.

Examples of exclusively algorithmic code are sorting algorithms, parsers and pricing engines.

It contrasts with integration code and blends of integration and algorithmic code.

It is rare for algorithmic code to predominate in user facing projects. However, it is very common for libraries or other forms of shared code to be used in other software projects to be exclusively algorithmic.

The distinction is important primarily because algorithmic code requires a very different kind of testing to integration code. It also has different failure conditions and even requires a different set of skills to write well. 