-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.c
51 lines (41 loc) · 1.07 KB
/
solution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "../../utils.h"
int calculateHASH(char* sequence);
int main(int argc, char* argv[]){
getFileName("input.txt");
openFile;
timerStart;
size_t size = 65000;
char* lineBuf = malloc(size);
getline(&lineBuf, &size, fd);
int lineSize = strlen(lineBuf);
int index = 0;
int inputIndex = 0;
int solution = 0;
char inputBuf[256];
while(index < lineSize+1){
if(lineBuf[index] != ',' && lineBuf[index] != '\0' && lineBuf[index] != '\n') {
inputBuf[inputIndex] = lineBuf[index];
index++;
inputIndex++;
continue;
}
inputBuf[inputIndex] = '\0';
solution += calculateHASH(inputBuf);
inputIndex = 0;
index++;
}
printf("Solution: %d\n", solution);
timerEnd;
return 0;
}
int calculateHASH(char* sequence){
int i = 0;
int currentHash = 0;
while(sequence[i] != '\0'){
currentHash += (int) sequence[i];
currentHash *= 17;
currentHash = currentHash % 256;
i++;
}
return currentHash;
}