diff options
author | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-09 18:29:02 +0000 |
---|---|---|
committer | Nat Lasseter <Nat Lasseter nathan@bytemark.co.uk> | 2017-12-09 18:29:02 +0000 |
commit | 89b9402b79bb0d496e37ec2a02164cbbb211a637 (patch) | |
tree | f1d37f4019d4aab3ac410fcfb6a2a78debf96f5b /day09/part2 | |
parent | 7be7d207474ddcdd55318822c9fefd9637361acf (diff) |
Day 09
Diffstat (limited to 'day09/part2')
-rwxr-xr-x | day09/part2 | 37 |
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 |