feat: add code for day 4
This commit is contained in:
parent
f0138f708a
commit
0fd1eecefa
28
4/script.rb
Executable file
28
4/script.rb
Executable file
@ -0,0 +1,28 @@
|
||||
#!/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
|
Loading…
x
Reference in New Issue
Block a user