aoc/18/5/main.rb

49 lines
787 B
Ruby
Raw Normal View History

2023-04-17 18:18:20 +00:00
require 'pry'
input = File.open('input') {|file| file.readline}
('a'..'z').each do |letter|
output = input
temp = ""
i = 0
while i != output.length
if output[i].downcase != letter
temp += output[i]
end
i += 1
end
output = temp
temp = ""
removed = true
while removed
removed = false
i = 1
while i < output.length
if output[i - 1] != output[i] && output[i - 1].downcase == output[i].downcase
removed = true
i += 2
if i == output.length
temp += output[-1]
end
else
temp += output[i - 1]
i += 1
if i == output.length
temp += output[-1]
end
end
end
output = temp
temp = ""
end
puts "#{letter}: #{output.length}"
end