aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-11-01 00:22:09 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-11-01 00:22:09 +0000
commit8c6c652c691c3b6a7e1fd37afb4f80a6c6b58b9a (patch)
tree7f47f2de6c969149ca6f6ed4864643f0dafd1b02
parentf05bcc4e5446e166937e00431f1851bd6b2ce4ea (diff)
downloadadvent-of-code-8c6c652c691c3b6a7e1fd37afb4f80a6c6b58b9a.tar.gz
advent-of-code-8c6c652c691c3b6a7e1fd37afb4f80a6c6b58b9a.tar.bz2
advent-of-code-8c6c652c691c3b6a7e1fd37afb4f80a6c6b58b9a.zip
Finished problem 1
-rw-r--r--2015/puzzle-1.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/2015/puzzle-1.sh b/2015/puzzle-1.sh
new file mode 100644
index 0000000..f134bfe
--- /dev/null
+++ b/2015/puzzle-1.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env sh
+text=$(< 1-input)
+open=$(echo $text | tr -d ')' | wc -c)
+close=$(echo $text | tr -d '(' | wc -c)
+
+echo "Round 1:" $(($open - $close))
+
+current=0
+pos=1
+while read -n1 char
+do
+ case $char in
+ "(" )
+ current=$(($current + 1))
+ ;;
+ ")" )
+ current=$(($current - 1))
+ ;;
+ esac
+ if [ $current -lt 0 ]
+ then
+ break;
+ fi
+ pos=$(($pos + 1))
+done < <(printf "%s" $text | tr -d '\n')
+
+echo "Round 2:" $pos