Compare commits

..

No commits in common. "fde761d6af58266f1f18c28571ba76bd02e14897" and "e6a76e428fa0f61e2d3517bb9d20b05ccd4ff884" have entirely different histories.

2 changed files with 0 additions and 56 deletions

View File

@ -20,25 +20,3 @@ class Rectangle
end end
end end
end end
class String
def select(&block)
String.build do |s|
each_char do |c|
s << c if yield c
end
end
end
def select!(&block)
i = 0
s = size
while i < s
if yield [i]
i += 1
else
s -= 1
end
end
end
end

34
day5.cr
View File

@ -1,34 +0,0 @@
require "./common.cr"
lines = File.read("day5_input").split("\n")
struct Char
def inverse?(other)
return (other != self) && (other.downcase == self.downcase)
end
end
def react(string)
stack = [] of Char
string.each_char do |char|
last_char = stack.last?
if !last_char || !last_char.inverse? char
stack << char
else
stack.pop
end
end
return stack
end
puts react(lines[0]).size
pairs = {} of Tuple(Char, Char) => Int32
('a'..'z').to_a.zip(('A'..'Z').to_a).each do |pair|
new_string = lines[0].select { |c| c != pair[0] && c != pair[1] }
pairs[pair] = react(new_string).size
end
puts pairs.values.min