From b501d324af4d83f97ff47cc634967a372aba503c Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 4 Dec 2016 21:30:50 -0800 Subject: [PATCH] [2016][ruby][5.x] shameless green --- 2016/ruby/day_05.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 2016/ruby/day_05.rb diff --git a/2016/ruby/day_05.rb b/2016/ruby/day_05.rb new file mode 100644 index 0000000..7420737 --- /dev/null +++ b/2016/ruby/day_05.rb @@ -0,0 +1,22 @@ +require 'digest/md5' + +door_id = 'wtnhxymk' +password = Array.new(8, nil) + +VALID = (0..7).map(&:to_s).to_a + +index = 0 +while password.any?(&:nil?) + puts index if index % 1000000 == 0 + hash = Digest::MD5.hexdigest("#{door_id}#{index}") + if hash.start_with?('00000') + i = hash[5] + if VALID.include?(i) && password[i.to_i].nil? + password[i.to_i] = hash[6] + p hash, password + end + end + index += 1 +end + +puts password.join