c 2024 3 part 2
This commit is contained in:
		
							parent
							
								
									99f7f21611
								
							
						
					
					
						commit
						d7fc4fb192
					
				| @ -11,14 +11,19 @@ int main() { | ||||
|   char *line; | ||||
| 
 | ||||
|   int sum = 0; | ||||
|   int cond_sum = 0; | ||||
| 
 | ||||
|   char d1[10], d2[10]; | ||||
|   int d1_index, d2_index; | ||||
| 
 | ||||
|   while ((line = aoc_read_line()) != NULL) { | ||||
|   enum State state = M; | ||||
|     char *c = line; | ||||
|   bool do_mult = true; | ||||
|   char *c = aoc_read_input(); | ||||
| 
 | ||||
|   while(*c != '\0') { | ||||
|     if (memcmp(c, "do()", 4) == 0) do_mult = true; | ||||
|     else if (memcmp(c, "don't()", 7) == 0) do_mult = false; | ||||
| 
 | ||||
|     switch (state) { | ||||
|     case M: | ||||
|       if (*c == 'm') state = U; | ||||
| @ -52,6 +57,7 @@ int main() { | ||||
| 	d1[d1_index] = '\0'; | ||||
| 	d2[d2_index] = '\0'; | ||||
| 	sum += atoi(d1) * atoi(d2); | ||||
| 	if (do_mult) cond_sum += atoi(d1) * atoi(d2); | ||||
| 	state = M; | ||||
|       } | ||||
|       else state = M; | ||||
| @ -59,10 +65,9 @@ int main() { | ||||
|     } | ||||
|     c++; | ||||
|   } | ||||
|   } | ||||
| 
 | ||||
|   printf("Part 1: %d\n", sum); | ||||
|   // printf("Part 2: %d\n", safe_skip_report_count);
 | ||||
|   printf("Part 2: %d\n", cond_sum); | ||||
| 
 | ||||
|   aoc_free(); | ||||
|   return 0; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user