summaryrefslogtreecommitdiff
path: root/2021/2.sh
diff options
context:
space:
mode:
Diffstat (limited to '2021/2.sh')
-rwxr-xr-x2021/2.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/2021/2.sh b/2021/2.sh
new file mode 100755
index 0000000..360b5fc
--- /dev/null
+++ b/2021/2.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+{
+ echo 'h=0'
+ echo 'd=0'
+ cat 2.in | sed 's/forward/h+=/; s/down/d+=/; s/up/d-=/; s/^/: $((/; s/$/))/'
+ echo 'echo $((h * d))'
+} | bash
+
+{
+ echo 'h=0'
+ echo 'a=0'
+ echo 'd=0'
+ cat 2.in | sed 's/forward \(.*\)/: $((h+=\1)) $((d+=a*\1))/; s/down \(.*\)/: $((a+=\1))/; s/up \(.*\)/: $((a-=\1))/'
+ echo 'echo $((h * d))'
+} | bash