AoC2015/day04/solution.rb

26 lines
535 B
Ruby

#!/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)}"