29 lines
568 B
Ruby
Executable File
29 lines
568 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require_relative '../common'
|
|
|
|
RANGE = '372037-905157'
|
|
|
|
def part1
|
|
first, last = RANGE.split('-')
|
|
(first..last).count do |password|
|
|
password = password.to_s
|
|
password.chars == password.chars.sort &&
|
|
password.match?(/(.)\1/)
|
|
end
|
|
end
|
|
|
|
def part2
|
|
first, last = RANGE.split('-')
|
|
(first..last).count do |password|
|
|
password = password.to_s
|
|
password.chars == password.chars.sort &&
|
|
password.chars.group_by(&:itself).any? { |_,v| v.size == 2 }
|
|
end
|
|
end
|
|
|
|
puts "=== Part 1 ==="
|
|
puts part1
|
|
puts "=== Part 2 ==="
|
|
puts part2
|