aboutsummaryrefslogtreecommitdiff
path: root/day05/part1
blob: 9fe581dc05e704ddde1c03b0b479cef91b7d15fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env ruby

input = gets.chomp.chars

polymer = input
nextpolymer = Array.new(polymer.length)
nextpolymer[0] = polymer[0]
index = 1
nextindex = 0

while index < polymer.length do
  if polymer[index].swapcase != nextpolymer[nextindex]
    nextindex += 1
    nextpolymer[nextindex] = polymer[index]
  else
    nextpolymer[nextindex] = nil
    nextindex -= 1
  end
  index += 1
end

puts nextpolymer.compact.length