uppga.c (525B)
1 #include "common.h" 2 3 static inline char *hashnext(uint64_t *r, char *s) { 4 if (*s == '\0' || *s == '\n') 5 return NULL; 6 uint64_t v = 0; 7 char *cp = s; 8 9 while (*cp != '\0' && *cp != '\n' && *cp != ',') { 10 v = (17 * (v + ((uint64_t)*cp))) & 0xff; 11 cp++; 12 } 13 14 *r = v; 15 16 return cp + 1; 17 } 18 19 int main(int argc, char **argv) { 20 char **lines; 21 readlines(&lines, "input"); 22 23 uint64_t h, summa = 0; 24 char *cp = lines[0]; 25 while ((cp = hashnext(&h, cp)) != NULL) { 26 summa += h; 27 } 28 29 printf("%llu\n", summa); 30 }