diff options
author | Yigit Sever | 2021-12-07 21:34:31 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-07 21:34:31 +0300 |
commit | ae3853b6e8ab02023ccd74baac6dc177b1ee879a (patch) | |
tree | 2ac9f32251ca23a0950759675a19f836994d3fbb /2021/day2 | |
parent | ce9b9c411bd6c36d80fe6dd8112c8188661e2844 (diff) | |
download | aoc-ae3853b6e8ab02023ccd74baac6dc177b1ee879a.tar.gz aoc-ae3853b6e8ab02023ccd74baac6dc177b1ee879a.tar.bz2 aoc-ae3853b6e8ab02023ccd74baac6dc177b1ee879a.zip |
2021, day2: done
Diffstat (limited to '2021/day2')
-rw-r--r-- | 2021/day2/pilot.c | 12 |
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 | } |