-
-
Save zid/f25c10d7d02626ea38aef8dac502ec71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(void) | |
{ | |
FILE *f; | |
char line[1024]; | |
unsigned long sum = 0; | |
f = fopen("day3.txt", "r"); | |
char sack1a[256]; | |
char sack1b[256]; | |
char sack1c[256]; | |
while(1) | |
{ | |
memset(sack1a, 0, 256); | |
memset(sack1b, 0, 256); | |
memset(sack1c, 0, 256); | |
if(!fgets(line, 128, f)) | |
break; | |
if(line[0] == '\n') | |
break; | |
int i, len = strlen(line) - 1; | |
for(i = 0; i < len; i++) | |
sack1a[line[i]]=1; | |
if(!fgets(line, 128, f)) | |
break; | |
if(line[0] == '\n') | |
break; | |
len = strlen(line) - 1; | |
for(i = 0; i < len; i++) | |
sack1b[line[i]]=1; | |
if(!fgets(line, 128, f)) | |
break; | |
if(line[0] == '\n') | |
break; | |
len = strlen(line) - 1; | |
for(i = 0; i < len; i++) | |
sack1c[line[i]]=1; | |
for(i = 0; i < 255; i++) | |
{ | |
if(sack1a[i] && sack1b[i] && sack1c[i]) | |
{ | |
if(i >= 'a' && i <= 'z') | |
sum += 1 + i - 'a'; | |
else | |
sum += 27 + i - 'A'; | |
printf("sum: %lu, %c is in all 3: %s", sum, i, line); | |
} | |
} | |
} | |
printf("sum: %lu\n", sum); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment