import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
public static List<Integer> computeCheckSums(List<Integer> filebytes){
ArrayList<Integer> computeList = new ArrayList<>();
int subSize=0;
for(int j=0; j<filebytes.size();j=j+filebytes.get(j)+1){
int sum=0;
subSize=subSize+filebytes.get(j)+1;
System.err.println("j : " + j + " : " + filebytes.get(j));
System.err.println("size : " + subSize);
for(int i=j+1; i<subSize; i++){
System.err.println("i : " + i + " : " + filebytes.get(i));
sum+=filebytes.get(i);
}
sum = sum%256;
computeList.add(sum);
}
return computeList;
}
public static void main(String[] args) {
System.out.println(computeCheckSums(Arrays.asList(3,44,55,66,2,110,220)));
}
/*Some file formats (images, videos, ...) are organised in "chunks", containing a header
and the data. To make sure the files are not corrupted, checksums are sometimes
computed.
Given a list of integers ranging from O to 255 (parameter fileBytes ), representing
the bytes of a file. You have to return the checksums of all the chunks.
The file is structured as follows:
The first byte is the header of the first chunk, which defines its size (header is
not counted in the chunk size).
The next bvtes are the chunk data.
The next byte is the header of the second chunk, and so on.
The data you get in input will always be consistent. For example, if the last chunk
header is 5, then you have exactly 5 bytes just after, no more, no less.
You have to retrieve all the chunks. For each of them, sum up all their bytes (header
not included), and keep only the 8 lowest bits to produce its checksum. Then return a
list containing all the checksums.*/
}
To embed this project on your website, copy the following code and paste it into your website's HTML: