Solution for Day 02

This commit is contained in:
Patrick Michl 2020-12-02 08:43:55 +01:00
parent 06bae360a3
commit 3658d97661
3 changed files with 1017 additions and 0 deletions

8
day_02/first.rb Normal file
View File

@ -0,0 +1,8 @@
input = File.readlines('./input')
a = input.map do |pwl|
matches = pwl.match /(?<start>\d+)-(?<end>\d+) (?<char>\w): (?<pw>\w+)/
matches[:pw].count(matches[:char]).between? matches[:start].to_i, matches[:end].to_i
end
puts a.count(true)

1000
day_02/input Normal file

File diff suppressed because it is too large Load Diff

9
day_02/second.rb Normal file
View File

@ -0,0 +1,9 @@
input = File.readlines('./input')
a = input.map do |pwl|
matches = pwl.match /(?<start>\d+)-(?<end>\d+) (?<char>\w): (?<pw>\w+)/
matches[:pw].chars.values_at(matches[:start].to_i-1, matches[:end].to_i-1).count(matches[:char])
end
puts a.inspect
puts a.count(1)