aboutsummaryrefslogtreecommitdiff
path: root/day02/part2
blob: aa82247180ca2b345a94e527735256cd09cb5899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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