summary refs log tree commit diff homepage
path: root/2020
diff options
context:
space:
mode:
Diffstat (limited to '2020')
-rw-r--r--2020/day12.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/2020/day12.c b/2020/day12.c
new file mode 100644
index 0000000..1d22820
--- /dev/null
+++ b/2020/day12.c
@@ -0,0 +1,35 @@
+#include <stdio.h>
+#include <stdlib.h>
+static void swap(int *a, int *b) {
+	int x = *a;
+	*a = *b;
+	*b = x;
+}
+int main(void) {
+	int x = 0, y = 0;
+	int dx = 1, dy = 0;
+	char act;
+	int val;
+	while (0 < scanf("%c%d\n", &act, &val)) {
+		switch (act) {
+			break; case 'N': y -= val;
+			break; case 'S': y += val;
+			break; case 'E': x += val;
+			break; case 'W': x -= val;
+			break; case 'L': {
+				for (int i = 0; i < val / 90; ++i) {
+					swap(&dx, &dy);
+					dy *= -1;
+				}
+			}
+			break; case 'R': {
+				for (int i = 0; i < val / 90; ++i) {
+					swap(&dx, &dy);
+					dx *= -1;
+				}
+			}
+			break; case 'F': x += val * dx; y += val * dy;
+		}
+	}
+	printf("%d\n", abs(x) + abs(y));
+}
follow=1'>Set PSlit like NetBSD shJune McEnroe 2019-01-12Install gnupg2 from pkgsrc and symlink gpgJune McEnroe 2019-01-12Reference cash builtin man pages in cash.1 SEE ALSOJune McEnroe 2019-01-12Restore cash builtin man page datesJune McEnroe 2019-01-12Use local libeditJune McEnroe 2019-01-12Replace libedit MakefileJune McEnroe 2019-01-11Import /usr/src/lib/libedit from NetBSD 8.0June McEnroe 2019-01-11Add PSlit for prompt escapesJune McEnroe 2019-01-11Don't make depend automaticallyJune McEnroe