summaryrefslogtreecommitdiffstats
path: root/2021/day2/pilot.c
diff options
context:
space:
mode:
Diffstat (limited to '2021/day2/pilot.c')
-rw-r--r--2021/day2/pilot.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/2021/day2/pilot.c b/2021/day2/pilot.c
index 4268cc7..6bc0630 100644
--- a/2021/day2/pilot.c
+++ b/2021/day2/pilot.c
@@ -22,13 +22,23 @@ int main(int argc, char *argv[])
22 22
23 int scalar; 23 int scalar;
24 char *way; 24 char *way;
25 int h_pos = 0, depth = 0, aim = 0;
25 while ((read = getline(&buffer, &len, fp)) != -1) { 26 while ((read = getline(&buffer, &len, fp)) != -1) {
26 sscanf(buffer, "%s %d", way, &scalar); 27 sscanf(buffer, "%s %d", way, &scalar);
27 // printf("READ: <%s>, <%d>\n", way, scalar); 28 // printf("READ: <%s>, <%d>\n", way, scalar);
28 29
29 if (strncmp(buffer, "forward", strlen(buffer))) { 30 if (strncmp(way, "forward", strlen("forward")) == 0) {
31 // printf("GOING FORWARD\n");
32 h_pos += scalar;
33 depth += aim * scalar;
34 } else if (strncmp(way, "down", strlen("forward")) == 0) {
35 aim += scalar;
36 } else { /* up */
37 aim -= scalar;
30 } 38 }
31 } 39 }
32 40
41 printf("%d\n", depth * h_pos);
42
33 return 0; 43 return 0;
34} 44}