d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Another Programming Question > Bluej (grade 11)
Add Reply New Topic New Poll
Member
Posts: 17,018
Joined: Jul 8 2007
Gold: 0.00
Nov 19 2009 04:52pm
Say that the original values are in the array “signal”.
Compute the smoothed array by doing this: Each value
smooth[N] is the average of three values: signal [N-1],
signal [N] and signal [N+1].

For the first element of smooth, average the first two
elements of signal. For the last element of smooth,
average the last two elements of signal.

Use integer arithmetic for this so that the values in
smooth are integers.

The signal array should be initialized with the following
ten values:

1 5 4 5 7 6 8 6 5 4 5 4
The smooth array should contain and output the
following:
3 3 4 5 6 7 6 6 5 4
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Nov 19 2009 11:12pm
Do you just copy and paste your homework? Fuck, add up the three values and divide by three. Handle the special case for the first and last by only dividing by two. Handle the extra special case of 1 or zero elements in the array by doing nothing.
Member
Posts: 9,475
Joined: Mar 14 2005
Gold: 110.00
Nov 19 2009 11:15pm
Quote (ASBands @ 20 Nov 2009 00:12)
Do you just copy and paste your homework?  Fuck, add up the three values and divide by three.  Handle the special case for the first and last by only dividing by two.  Handle the extra special case of 1 or zero elements in the array by doing nothing.


Post code plz. Must compile thx.
Member
Posts: 17,018
Joined: Jul 8 2007
Gold: 0.00
Nov 20 2009 02:43pm
Quote (llamaoo7 @ Nov 20 2009 05:15am)
Post code plz. Must compile thx.


wut he said lol
please (yn))
Member
Posts: 5,219
Joined: Oct 29 2009
Gold: 0.00
Warn: 20%
Nov 20 2009 02:50pm
Quote (llamaoo7 @ Nov 19 2009 10:15pm)
Post code plz.  Must compile thx.


Compile it for me plz.
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Nov 20 2009 03:02pm
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!
Member
Posts: 9,475
Joined: Mar 14 2005
Gold: 110.00
Nov 20 2009 03:40pm
Quote (xMaxPower @ 20 Nov 2009 15:43)
wut he said lol
please (yn))


I was mocking you. I really hope no one does your homework for you.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll