aboutsummaryrefslogtreecommitdiff
path: root/day02/part2
diff options
context:
space:
mode:
Diffstat (limited to 'day02/part2')
-rwxr-xr-xday02/part233
1 files changed, 33 insertions, 0 deletions
diff --git a/day02/part2 b/day02/part2
new file mode 100755
index 0000000..aa82247
--- /dev/null
+++ b/day02/part2
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+class String
+ def distance(other)
+ sa = self.chars
+ oa = other.chars
+ d = 0
+ (0...self.length).each do |i|
+ d += 1 if sa[i] != oa[i]
+ end
+ return d
+ end
+
+ def difference(other)
+ sa = self.chars
+ oa = other.chars
+ (0...self.length).each do |i|
+ sa[i] = nil if sa[i] != oa[i]
+ end
+ return sa.join
+ end
+end
+
+input = $stdin.readlines.map(&:chomp)
+
+(0...input.length).each do |i|
+ (i...input.length).each do |j|
+ if input[i].distance(input[j]) == 1
+ puts input[i].difference(input[j])
+ exit
+ end
+ end
+end