From 3f01d5d654988631f16279c69f8e833c11f20e43 Mon Sep 17 00:00:00 2001 From: s00ner Date: Tue, 12 Jul 2022 17:06:02 -0400 Subject: [PATCH] Solved Day 4 --- day04/input | 1 + day04/solution.rb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 day04/input create mode 100644 day04/solution.rb 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)}"