aboutsummaryrefslogtreecommitdiff
path: root/day02/part2
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2018-12-02 12:41:05 +0000
committerNat Lasseter <user@4574.co.uk>2018-12-02 12:41:05 +0000
commit43ab0a3a7a1e095f5f33f224ce73c413f49e156c (patch)
tree1d4bfdb3385562511231f4389e29ca2279a916b1 /day02/part2
Initial commit
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