Initial Commit - days 01-12
This commit is contained in:
38
day03/ex1-c.c
Normal file
38
day03/ex1-c.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ex1-c: Advent2020 game, day 3/game 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define XMOVE 3
|
||||
|
||||
int my_strlen(str)
|
||||
char *str;
|
||||
{
|
||||
int i;
|
||||
for (i=0; *str; ++i, ++str)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
int main(ac, av)
|
||||
char **av;
|
||||
{
|
||||
|
||||
int col=0, line=0, linelen=0, mod=0, count=0;
|
||||
char str[80];
|
||||
|
||||
scanf("%s", str); /* ignore 1st line */
|
||||
|
||||
while (scanf("%s", str) != EOF) {
|
||||
line++;
|
||||
col+=XMOVE;
|
||||
linelen=my_strlen(str);
|
||||
mod=col%linelen;
|
||||
if (*(str+mod) == '#')
|
||||
count++;
|
||||
}
|
||||
printf ("%s : lines:%d pos:%d found:%d\n", *av, line, col, count);
|
||||
exit (0);
|
||||
}
|
Reference in New Issue
Block a user