aoc

advent of code
git clone git://source.orangerot.dev:/aoc.git
Log | Files | Refs

main2.c (648B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 void draw(int ops, int x)
      5 {
      6     if ( (ops) % 40 <= x + 2 && (ops) % 40 >= x )
      7     {
      8         printf("#");
      9     } else {
     10         printf(".");
     11     }
     12     if ((ops) % 40 == 0) {
     13         printf("\n");
     14     }
     15 }
     16 
     17 int main()
     18 {
     19     char *line = NULL;
     20     size_t len;
     21     int ops = 1;
     22     int x = 1;
     23 
     24     int signal = 0;
     25 
     26     while (getline(&line, &len, stdin) != -1)
     27     {
     28         draw(ops, x);
     29         if (line[0] == 'a') {
     30             ops++;
     31             draw(ops, x);
     32             int a = atoi(line+5);
     33             x += a;
     34             // printf("%d\n", a);
     35         }
     36         ops++;
     37     }
     38 
     39     printf("%d\n", signal);
     40 }