about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-12-01 21:47:09 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-12-01 21:47:09 +0900
commitff0bb53c15ddb51c94bcf9400c68f0858a48a6e2 (patch)
tree6a9018445febfedeafc091702da715c40a95d383
parentf934ff8b3b44bfea5f0d3eb9d16fba06a9289849 (diff)
downloadcp-ff0bb53c15ddb51c94bcf9400c68f0858a48a6e2.tar.gz
[aoc/2022] Finish day 1
-rwxr-xr-xaoc/2022/01/part-one.sh2
-rwxr-xr-xaoc/2022/01/part-two.sh3
2 files changed, 5 insertions, 0 deletions
diff --git a/aoc/2022/01/part-one.sh b/aoc/2022/01/part-one.sh
new file mode 100755
index 0000000..a0e0095
--- /dev/null
+++ b/aoc/2022/01/part-one.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+sed 's/$/+/' | { echo 0; sed 's/^+$/p0/'; echo p; } | dc | sort -n | tail -1
diff --git a/aoc/2022/01/part-two.sh b/aoc/2022/01/part-two.sh
new file mode 100755
index 0000000..a5a4d77
--- /dev/null
+++ b/aoc/2022/01/part-two.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+sed 's/$/+/' | { echo 0; sed 's/^+$/p0/'; echo p; } | dc |
+  sort -n | tail -n 3 | { echo 0; sed 's/$/+/'; echo p; } | dc