Programming Test Questions 

Notes about this programmer test: 
 
Some questions require to write code in C++, C# or shader language. Each question indicates what languages you can use:
 
 - For C++ assume a recent standard compiler
 - Please only use C# if you think you are not familiar enough with C++
 - Shader questions require shader language
 
 ------------------------- question 1
Please implement the following mathematical function, in the way you think is best (explain your choice).
 
F(0) = 0
F(n) = n + F(n-1)
n=1..20
 
Please answer in C++ (or C# if you are not familiar with C++).
 
 
 ------------------------- question 2
Please use the C++ STL vector class to make a triangle list class, for use in 3d drawing. For each triangle please store 3 vertex positions, 3 colours, and 1 face normal.
 
 ------------------------- question 3
Please fill in the rest of the C++ 'slow_string' class written below. Try to replicate the STL string class's functionality as much as possible. This question is to test how good you are at encapsulating the C standard library functions such as strXXX. 
 
You can keep that question if you are not familiar with C++.
 
class slow_string
{
char *data;
public:
...
}
 ------------------------- question 4
Please implement the standard functionality required from a 3 element vector for a math library. The design should be object oriented and protect its data members from public access. Please support simple operations on the vector such as addition, subtraction, multiplication and division as well as dot and cross product.
 
Please answer in C++ (or C# if you are not familiar with C++).
 
 ------------------------- question 5
Given that you have a 2 dimensional array of height values (say 10x10) that represent a height field. Assume that the distance between each height point in X and Y is 1 and that from the grid we form a triangulated mesh such that for each set of 4 grid points A=(x,y), B=(x+1,y) C=(x+1,y+1), and D=(x,y+1) there are two triangles ABC and ACD (so they are seperated by the line x=y in the local coordinate system of the grid). Explain how you would find the *exact* height of an arbitrary point x,y on this mesh.
 
 ------------------------- question 6
Please implement the method from the previous question in in C++ (or C# if you are not familiar with C++).
 
 ------------------------- question 7
Please think of an algorithm that given 4 arbitrary points produces a smooth curve that connects all of them. Then write a function that takes 5 parameters (4 points and a 'time' parameter between 0 and 1) and returns the point on the curve at an arbitrary 'time'.
 
Please implement your method in C++ (or C# if you are not familiar with C++).
 
 ------------------------- question 8
Now write a function that given an arbitrary number of points smoothly interpolates between them at a given input 'time' parameter between 0 and 1, making use of the function/functions you wrote in previous question if appropriate.
Some form of visual output is a plus.
 
Please answer in C++ (or C# if you are not familiar with C++).
 ------------------------- question 9
Assuming that you have a 2D game that can display hundreds of non-rotating sprites. Explain how you could efficiently optimize collision detection on these sprites without having to test every sprite against every other sprite. 
 
 ------------------------- question 10
We are making an action game (2D/3D is irrelevant).
In game we need to make coins appear when the player destroys enemies or objects.
Please implement an object pool so that we don't have to allocate those coins all the time. 
In this question we are only interested in the pool logic (api and implementation) so there is no need to worry about details such as rendering and effects. The implementation is up to you but please try to fulfill at least those conditions:
 
 - 10000 coins are allocated at init time
 - no allocation happens after that during the game
 - coins disapears when the player takes them
 - coins disappears after 300 frame
 
class Coin
{
}
 
class CoinObjectPool
{
}
 
Please answer in C++ (or C# if you are not familiar with C++).
 
 ------------------------- question 11
Think of a question that you feel should be on this test and answer it (please don't skip that question)
 
 ------------------------- question 12
Please write a shader function that meets those conditions.
You can use function available in common shader languages apis.
 
float f( float x, float dx0, float dx1 ) { ?... }
 
 f(0)=0
 f(1)=1
 f'(0)=dx0 on the right side of 0
 f'(1)=dx1 on the left side of 1
 f(x) is smooth for x in [0,1]
 f(x) = 0 for x < 0
 f(x) = 1 for x > 1
 
 ------------------------- question 13
Please write a shader function that meets those conditions.
You can use function available in common shader languages apis.
 
 - the function is identity when x is in interval [a,b]
 - the function is mirrored repeated everywhere else
 
float mirror_repeat( float x, float a, float b ) { ... }