summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2018/day22.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/2018/day22.c b/2018/day22.c
new file mode 100644
index 0000000..459f8cb
--- /dev/null
+++ b/2018/day22.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef unsigned uint;
+
+enum Type {
+	Rocky,
+	Wet,
+	Narrow,
+};
+
+static uint depth;
+static uint targetX, targetY;
+
+static uint erosionLevel(uint x, uint y);
+
+static uint geologicIndex(uint x, uint y) {
+	if (x == 0 && y == 0) return 0;
+	if (x == targetX && y == targetY) return 0;
+	if (y == 0) return x * 16807;
+	if (x == 0) return y * 48271;
+	return erosionLevel(x - 1, y) * erosionLevel(x, y - 1);
+}
+
+static uint erosionLevels[1000][1000];
+
+static uint erosionLevel(uint x, uint y) {
+	if (!erosionLevels[x][y]) {
+		erosionLevels[x][y] = (geologicIndex(x, y) + depth) % 20183;
+	}
+	return erosionLevels[x][y];
+}
+
+static enum Type type(uint x, uint y) {
+	return erosionLevel(x, y) % 3;
+}
+
+int main(void) {
+	scanf("depth: %u\n", &depth);
+	scanf("target: %u,%u\n", &targetX, &targetY);
+
+	uint riskLevel = 0;
+	for (uint x = 0; x <= targetX; ++x) {
+		for (uint y = 0; y <= targetY; ++y) {
+			riskLevel += type(x, y);
+		}
+	}
+	printf("%u\n", riskLevel);
+}
id=7957ca0ecd5c3e512c836a1b19dbd75628c439fb&follow=1'>Only make windows hotterJune McEnroe A warm message shouldn't clear a window's hotness. 2020-02-10Always increase unreadLinesJune McEnroe So that if you switch to a window and some new activity happens before you press M-u, it'll still jump to the right place. 2020-02-10Move scroll marker on resizeJune McEnroe 2020-02-10Update line count for words longer than linesJune McEnroe 2020-02-10Simplify mark, heat, unread trackingJune McEnroe 2020-02-10Update prompt when own nick changesJune McEnroe 2020-02-10Match URLs surrounded by parenthesesJune McEnroe But include a pair of parentheses in the URL itself. 2020-02-10Fix M-a so it properly cycles back to where it startedJune McEnroe 2020-02-09Add M-lJune McEnroe 2020-02-09Add /whoisJune McEnroe 2020-02-09Add /msgJune McEnroe