summary refs log tree commit diff homepage
path: root/2022
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2022/day11-1.awk58
1 files changed, 58 insertions, 0 deletions
diff --git a/2022/day11-1.awk b/2022/day11-1.awk
new file mode 100644
index 0000000..97a8148
--- /dev/null
+++ b/2022/day11-1.awk
@@ -0,0 +1,58 @@
+BEGIN {
+	FS = "[ :,]+";
+}
+/^Monkey/ {
+	m = $2;
+}
+/Starting items/ {
+	for (i = 4; i <= NF; ++i) {
+		items[m,len[m]++] = $i;
+	}
+}
+/Operation/ {
+	op[m] = $6;
+	const[m] = $7;
+}
+/Test/ {
+	test[m] = $5;
+}
+/If true/ {
+	true[m] = $7;
+}
+/If false/ {
+	false[m] = $7;
+}
+END {
+	for (n = 1; n <= 20; ++n) {
+		for (m = 0; test[m]; ++m) {
+			for (i = 0; i < len[m]; ++i) {
+				insp[m]++;
+				item = items[m,i];
+				delete items[m,i];
+				if (op[m] == "+") {
+					item += const[m];
+				} else if (op[m] == "*" && const[m] != "old") {
+					item *= const[m];
+				} else {
+					item *= item;
+				}
+				item = int(item/3);
+				if (item % test[m] == 0) {
+					items[true[m],len[true[m]]++] = item;
+				} else {
+					items[false[m],len[false[m]]++] = item;
+				}
+			}
+			len[m] = 0;
+		}
+	}
+	for (m = 0; test[m]; ++m) {
+		if (insp[m] > max1) {
+			max2 = max1;
+			max1 = insp[m];
+		} else if (insp[m] > max2) {
+			max2 = insp[m];
+		}
+	}
+	print max1 * max2;
+}
-23 18:53:03 -0700'>2014-12-23git: update to v2.2.1Christian Hesse 2014-12-13filter: fix libravatar email-filter https issueChristian Hesse 2014-12-13ui-diff: add "stat only" diff typeJohn Keeping 2014-12-13Change "ss" diff flag to an enumJohn Keeping 2014-12-13ui-shared: remove toggle_ssdiff arg to cgit_diff_link()John Keeping 2014-12-13ui-shared: remove toggle_ssdiff arg to cgit_commit_link()John Keeping 2014-08-07git: update to v2.0.4John Keeping 2014-08-07Always check if README exists in choose_readme()Lukas Fleischer 2014-08-01cgitrc.5: we mean a cgi response, not requestJason A. Donenfeld 2014-07-28ui-stats.c: set parent pointer to NULL after freeing itJohn Keeping 2014-07-28git: update to v2.0.3John Keeping 2014-07-28parsing.c: make commit buffer constJohn Keeping 2014-06-30Bump version.Jason A. Donenfeld 2014-06-29remove debug fprinf() calls that sneaked in with commit 79c985Christian Hesse 2014-06-28git: update to 2.0.1Christian Hesse 2014-06-28ui-patch: Flush stdout after outputting dataJohn Keeping 2014-06-28ui-log: ignore unhandled argumentsJohn Keeping 2014-06-28git: update for git 2.0Christian Hesse 2014-04-17remove trailing whitespaces from source filesChristian Hesse 2014-04-12git: update to 1.9.2Christian Hesse 2014-04-05Fix cgit_parse_url when a repo url is contained in another repo urlJulian Maurice 2014-03-20Makefile: use more reliable git tarball mirrorJason A. Donenfeld 2014-03-20git: update to 1.9.1Christian Hesse