AdventOfCode-2018/day2_1.cr

16 lines
279 B
Crystal
Raw Normal View History

2018-12-01 21:24:37 -08:00
lines = File.read("day2").split("\n")
lines.pop
CHARS = ('a'..'z').to_a
def has_n?(string, n)
CHARS.each do |c|
return true if string.count(c) == n
end
return false
end
two = lines.count { |s| has_n?(s, 2) }
three = lines.count { |s| has_n?(s, 3) }
puts two * three