diff options
Diffstat (limited to 'day05/part1')
-rwxr-xr-x | day05/part1 | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/day05/part1 b/day05/part1 new file mode 100755 index 0000000..4761380 --- /dev/null +++ b/day05/part1 @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby + +input = gets.chomp.chars + +l = input.length +loop do + i = input.length - 1 + loop do + break if i < 1 + + if input[i] == input[i-1].swapcase + input[i] = nil + input[i-1] = nil + i -= 2 + else + i -= 1 + end + end + input = input.compact + if input.length == l + break + else + l = input.length + end +end + +puts input.length |