Solved Day 5

main
s00ner 2022-07-12 20:52:51 -04:00
parent 667edb6369
commit 438a42fffd
2 changed files with 1022 additions and 0 deletions

1000
day05/input Normal file

File diff suppressed because it is too large Load Diff

22
day05/solution.rb Normal file
View File

@ -0,0 +1,22 @@
#!/bin/env ruby
strings = File.readlines('./input').map(&:strip)
bad_pairs = Regexp.new(/ab|cd|pq|xy/).freeze
double_letters = Regexp.new(/([a-z])\1/).freeze
three_vowels = Regexp.new(/[aeiou]/).freeze
letter_pairs = Regexp.new(/([a-z]{2}).*\1/).freeze
alternate = Regexp.new(/([a-z]).\1/).freeze
part1 = strings.reject do |string|
bad_pairs.match?(string) == true or double_letters.match?(string) == false or string.scan(three_vowels).count < 3
end
puts part1.count
part2 = strings.reject do |string|
letter_pairs.match?(string) == false or alternate.match?(string) == false
end
puts part2.count