diff --git a/day04/input b/day04/input new file mode 100644 index 0000000..d75e0dc --- /dev/null +++ b/day04/input @@ -0,0 +1 @@ +yzbqklnj diff --git a/day04/solution.rb b/day04/solution.rb new file mode 100644 index 0000000..11d809e --- /dev/null +++ b/day04/solution.rb @@ -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)}"