aboutsummaryrefslogtreecommitdiff
path: root/day09/part1
diff options
context:
space:
mode:
Diffstat (limited to 'day09/part1')
-rwxr-xr-xday09/part144
1 files changed, 44 insertions, 0 deletions
diff --git a/day09/part1 b/day09/part1
new file mode 100755
index 0000000..1bb643a
--- /dev/null
+++ b/day09/part1
@@ -0,0 +1,44 @@
+#!/usr/bin/env ruby
+
+input = gets.chomp.chars
+
+ptr = 0
+garbage = false
+escape = false
+lvl = 0
+score = 0
+
+input.each do |ch|
+ if escape then
+ escape = false
+ next
+ end
+
+ if ch == '!' then
+ escape = true
+ next
+ end
+
+ if garbage then
+ garbage = false if ch == '>'
+ next
+ end
+
+ if ch == '<' then
+ garbage = true
+ next
+ end
+
+ if ch == '{' then
+ lvl += 1
+ score += lvl
+ next
+ end
+
+ if ch == '}' then
+ lvl -= 1
+ next
+ end
+end
+
+puts score