summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2018/day04.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/2018/day04.c b/2018/day04.c
new file mode 100644
index 0000000..5d2939f
--- /dev/null
+++ b/2018/day04.c
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef unsigned uint;
+
+enum { Len = 4096 };
+uint guards[Len][60];
+
+int main() {
+	uint id, sleep;
+	while (!feof(stdin)) {
+		uint year, month, day, hour, minute;
+		char word[256];
+		scanf(
+			"[%u-%u-%u %u:%u] %255s #%u",
+			&year, &month, &day, &hour, &minute, word, &id
+		);
+		scanf("%*[^\n]\n");
+
+		if (!strcmp(word, "falls")) sleep = minute;
+		if (!strcmp(word, "wakes")) {
+			for (uint m = sleep; m < minute; ++m) {
+				guards[id][m]++;
+			}
+		}
+	}
+	uint maxID = 0, maxSum = 0;
+	for (uint i = 0; i < Len; ++i) {
+		uint sum = 0;
+		for (uint m = 0; m < 60; ++m) {
+			sum += guards[i][m];
+		}
+		if (sum < maxSum) continue;
+		maxSum = sum;
+		maxID = i;
+	}
+	uint maxMin = 0, maxSleep = 0;
+	for (uint m = 0; m < 60; ++m) {
+		if (guards[maxID][m] < maxSleep) continue;
+		maxSleep = guards[maxID][m];
+		maxMin = m;
+	}
+	printf("%u\n", maxID * maxMin);
+}
4:52:25 -0400'>2016-09-12Add -c option to xxJune McEnroe 2016-09-12Add .bin/xx.cJune McEnroe 2016-09-08Rename colorscheme to lameJune McEnroe 2016-09-04Simplify colors syntax in zsh promptJune McEnroe 2016-08-29Color rubyStringDelimiter as StringJune McEnroe 2016-08-24Highlight rubyDefine as StructureJune McEnroe 2016-08-23Remove scroll bindings from nvim configJune McEnroe 2016-08-17Highlight Search with black foregroundJune McEnroe 2016-08-15Remove gruvboxJune McEnroe 2016-08-04Remove march from SSH configJune McEnroe 2016-08-01Disable tab indicators in iTermJune McEnroe 2016-07-30Color PreProc DarkGreenJune McEnroe 2016-07-29Color Structure and Typedef in grayJune McEnroe 2016-07-27Color comments DarkBlue and LightBlueJune McEnroe 2016-07-27Color macros in yellowJune McEnroe 2016-07-26Colorscheme colors and schemesJune McEnroe 2016-07-26Add ''subtle'' colorschemeJune McEnroe 2016-07-26Add htoprcJune McEnroe 2016-07-24Add may and refactor ssh configJune McEnroe 2016-07-18Disable cursorlineJune McEnroe 2016-07-18Use hard constrast gruvbox darkJune McEnroe 2016-07-15Remove vim configurationJune McEnroe 2016-07-15Add readline to README configurations listJune McEnroe 2016-07-15Add vendor script to READMEJune McEnroe 2016-07-15Pull latest pathogen and gruvboxJune McEnroe