summaryrefslogtreecommitdiff
path: root/2021/2.sh
blob: 360b5fca4b145c40c8ff57e558a98ace8e4ada01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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