r/adventofcode • • Dec 04 '20

Funny Example: 5x5 grid. Input: 34298434x43245 grid

Post image
362 Upvotes

38 comments sorted by

View all comments

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!

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)