From 43ab0a3a7a1e095f5f33f224ce73c413f49e156c Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Sun, 2 Dec 2018 12:41:05 +0000 Subject: Initial commit --- day02/part2 | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 day02/part2 (limited to 'day02/part2') 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 -- cgit v1.2.3