/**
* @(#)DifDif.java
*
*
* @author
* @version 1.00 2007/9/6
*/
public class DifDif {
/**
* Creates a new instance of <code>DifDif</code>.
*/
public DifDif() {
}
public int predict( int [] seq) {
int len = seq.length;
int [] s0 = new int [len];
int [] s1 = new int [len];
s0[ 0 ] = seq[ 0 ];
for ( int i = 0 ; i < len; i ++ ) {
s1[ 0 ] = seq[i];
for ( int j = 1 ; j <= i; j ++ ) s1[j] = s1[j - 1 ] - s0[j - 1 ];
for ( int r = 0 ; r < len; r ++ ) s0[r] = s1[r];
}
int sum = 0 ;
for ( int i = 0 ; i < len; i ++ ) {
sum += s0[i];
}
return sum;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
DifDif dif = new DifDif();
int [] seq = { - 1000 , 1000 , - 1000 , 1000 , - 1000 , 1000 , - 1000 , 1000 , - 1000 , 1000 };
System.out.println(dif.predict(seq));
}
}
* @(#)DifDif.java
*
*
* @author
* @version 1.00 2007/9/6
*/
public class DifDif {
/**
* Creates a new instance of <code>DifDif</code>.
*/
public DifDif() {
}
public int predict( int [] seq) {
int len = seq.length;
int [] s0 = new int [len];
int [] s1 = new int [len];
s0[ 0 ] = seq[ 0 ];
for ( int i = 0 ; i < len; i ++ ) {
s1[ 0 ] = seq[i];
for ( int j = 1 ; j <= i; j ++ ) s1[j] = s1[j - 1 ] - s0[j - 1 ];
for ( int r = 0 ; r < len; r ++ ) s0[r] = s1[r];
}
int sum = 0 ;
for ( int i = 0 ; i < len; i ++ ) {
sum += s0[i];
}
return sum;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
DifDif dif = new DifDif();
int [] seq = { - 1000 , 1000 , - 1000 , 1000 , - 1000 , 1000 , - 1000 , 1000 , - 1000 , 1000 };
System.out.println(dif.predict(seq));
}
}