-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathlangtons-ant.c
More file actions
24 lines (21 loc) · 776 Bytes
/
langtons-ant.c
File metadata and controls
24 lines (21 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct _card { int x, y; } card;
main() {
int W, H, x, y, T; char d[2], C[31][31]; scanf("%d%d%d%d%s%d", &W, &H, &x, &y, &d, &T);
int dir_i; card dirs[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
switch(*d) {
case 'N': dir_i = 0; break;
case 'E': dir_i = 1; break;
case 'S': dir_i = 2; break;
case 'W': dir_i = 3; break;
}
for (int i = 0; i < H; i++) { scanf("%s", C[i]); }
for (int i = 0; i < T; i++) {
dir_i = (dir_i + 4 + (C[y][x] == '#' ? 1 : -1)) % 4;
C[y][x] = (C[y][x] == '#' ? '.' : '#');
x += dirs[dir_i].x; y += dirs[dir_i].y;
}
for (int i = 0; i < H; i++) { printf("%s\n", C[i]); }
}