aoc

Advent of Code Solutions
git clone git://git.alexkarle.com.com/aoc
Log | Files | Refs | README | LICENSE

a.c (559B) [raw]


      1 #include <stdio.h>
      2 #include <string.h>
      3 #include <stdlib.h>
      4 
      5 int main(void) {
      6     int depth = 0;
      7     int pos = 0;
      8     int val;
      9     char comm[256];
     10     while(scanf("%255s %d\n", comm, &val) != EOF) {
     11         if (!strcmp(comm, "forward")) {
     12             pos += val;
     13         } else if (!strcmp(comm, "up")) {
     14             depth -= val;
     15         } else if (!strcmp(comm, "down")) {
     16             depth += val;
     17         } else {
     18             fprintf(stderr, "bad command: %s\n", comm);
     19             exit(1);
     20         }
     21     }
     22     printf("%d\n", pos * depth);
     23     return 0;
     24 }