The goal of this coding kata is to come up with a solution for the following bearing in mind what this might mean for processing at scale:
Write a function f(x) that returns all distinct pairs of integers between -50 and 50 (inclusive) whose sum is X. The solution should be in PHP. Thus:
f(100) returns an empty list
f(99) returns (49,50)
f(0) returns (-50,50)(-49,49) … (-2,2)(-1,1)
I came up with a design that addresses the following:
- Object-oriented programming principles:
- Single responsibility
- Dependency inversion
- Don’t repeat yourself
- Test driven development (or at the very least, having functional tests)
- Exception handling
- Lazy class loading
- Namespacing
Please find the solution for further discussion including a section on Big-O notation.