ruby solution
This commit is contained in:
parent
4d714b94fc
commit
afe06c8955
18
02/02.rb
Normal file
18
02/02.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
input = File.readlines("input.txt")
|
||||||
|
|
||||||
|
part1 = 0
|
||||||
|
part2 = 0
|
||||||
|
for line in input do
|
||||||
|
policy, password = line.split(': ')
|
||||||
|
counts, character = policy.split(' ')
|
||||||
|
n1, n2 = counts.split('-').map(&:to_i)
|
||||||
|
if password.count(character) >= n1 && password.count(character) <= n2
|
||||||
|
part1 += 1
|
||||||
|
end
|
||||||
|
if (password[n1-1] == character) ^ (password[n2-1] == character)
|
||||||
|
part2 += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "Part 1: #{part1}"
|
||||||
|
puts "Part 2: #{part2}"
|
Loading…
Reference in a new issue