Solved Day 4

main
s00ner 2022-07-12 17:06:02 -04:00
parent a604443d87
commit 3f01d5d654
2 changed files with 26 additions and 0 deletions

1
day04/input Normal file
View File

@ -0,0 +1 @@
yzbqklnj

25
day04/solution.rb Normal file
View File

@ -0,0 +1,25 @@
#!/bin/env ruby
require 'digest'
key = File.read('./input').strip
# Part 1
answer = false
num = 0
until answer
num += 1
answer = true if Digest::MD5.hexdigest(key + num.to_s)[0..4] == '00000'
end
puts 'Part 1 Solution is: ' + num.to_s
puts "md5sum is: #{Digest::MD5.hexdigest(key + num.to_s)}"
# Part 2
answer = false
num = 0
until answer
num += 1
answer = true if Digest::MD5.hexdigest(key + num.to_s)[0..5] == '000000'
end
puts 'Part 2 Solution is: ' + num.to_s
puts "md5sum is: #{Digest::MD5.hexdigest(key + num.to_s)}"