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