Quote (xMaxPower @ Nov 20 2009 03:43pm)
wut he said lol
please (yn))
Seriously? Here is an inefficient version:
Code
int[] smoothed(int[] input)
{
int[] output = new int[input.length];
if (input.length == 0)
return output;
if (input.length == 1)
{
// we could just return input, but this maintains that a new array will be created with each function call
output[0] = input[0];
return output;
}
//handle the inside
for (int i = 1; i < input.length - 1; ++i)
output[i] = (input[i-1] + input[i] + input[i+1]) / 3;
//handle the ends
output[0] = (input[0] + input[1]) / 2;
output[output.length-1] = (input[input.length-1] + input[input.length-2]) / 2;
return output;
}
Fuck, that was hard!