Resolve day 4

main
Guillaume Dott 2021-11-22 14:01:31 +01:00
parent 8021474688
commit bcd8c8400e
1 changed files with 24 additions and 0 deletions

24
4/script.rb 100755
View File

@ -0,0 +1,24 @@
#!/usr/bin/env ruby
require 'digest'
def part1(input)
find_md5 input
end
def part2(input)
find_md5 input, 6
end
def find_md5(input, leading_zeros = 5)
(1..).detect do |i|
Digest::MD5.hexdigest(input + i.to_s).start_with?('0' * leading_zeros)
end
end
input = 'yzbqklnj'
puts "=== Part 1 ==="
puts part1(input)
puts "=== Part 2 ==="
puts part2(input)