aboutsummaryrefslogtreecommitdiff
path: root/day05/part1
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2018-12-05 10:08:04 +0000
committerNat Lasseter <user@4574.co.uk>2018-12-05 10:08:04 +0000
commitcd5acc649c31f299f16ec1e205a752e19b908bc5 (patch)
treedfdf3e54969f88cf73b6d6bdbfe721c27ba0dc96 /day05/part1
parent76056832683da277b2c68794cd49897da711d456 (diff)
[day05] done, naïve and slow
Diffstat (limited to 'day05/part1')
-rwxr-xr-xday05/part127
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