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