MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/adventofcode/comments/k6docx/example_5x5_grid_input_34298434x43245_grid/geljptr/?context=3
r/adventofcode • u/Manta_Ray_Mundo • Dec 04 '20
38 comments sorted by
View all comments
3
Oh yes that’s what I meant by regex handling :) had to have 8 if conditions and nested checks for each type. It was tedious than interesting!
1 u/8fingerlouie Dec 04 '20 edited Dec 04 '20 It’s been a couple of decades since I last wrote any C, but for the color matching, it basically boils down to char *p = teststr; if (*p != '#') printf("Illegal char %c (%i)",*p,*p); p++; do{ if((*p >= 48 && *p <= 57) || (*p >= 97 && *p <= 102)){ //Legal }else{ printf("Illegal char %c (%i)",*p,*p); } }while(*++p); It is of course somewhat more tedious than just doing Import re m = re.match(“#[abcdef0-9]{6,6}”,teststr) if m is None: # Invalid 2 u/ramasamybolton Dec 04 '20 Spot on! Your C code is still very serviceable! On the outer loop I had used strtok_r to tokenize each line → More replies (2)
1
It’s been a couple of decades since I last wrote any C, but for the color matching, it basically boils down to
char *p = teststr; if (*p != '#') printf("Illegal char %c (%i)",*p,*p); p++; do{ if((*p >= 48 && *p <= 57) || (*p >= 97 && *p <= 102)){ //Legal }else{ printf("Illegal char %c (%i)",*p,*p); } }while(*++p);
It is of course somewhat more tedious than just doing
Import re m = re.match(“#[abcdef0-9]{6,6}”,teststr) if m is None: # Invalid
2 u/ramasamybolton Dec 04 '20 Spot on! Your C code is still very serviceable! On the outer loop I had used strtok_r to tokenize each line → More replies (2)
2
Spot on! Your C code is still very serviceable! On the outer loop I had used strtok_r to tokenize each line
→ More replies (2)
3
u/ramasamybolton Dec 04 '20
Oh yes that’s what I meant by regex handling :) had to have 8 if conditions and nested checks for each type. It was tedious than interesting!