Created
December 6, 2015 13:57
-
-
Save wconrad/e320d151559f1513b984 to your computer and use it in GitHub Desktop.
Advent of code, day 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "digest/md5" | |
# http://adventofcode.com/day/4 | |
INPUT = "yzbqklnj" | |
def find(regex) | |
loop.with_index do |_, i| | |
plaintext = "#{INPUT}#{i}" | |
hash = Digest::MD5.hexdigest(plaintext) | |
return i if hash =~ regex | |
end | |
end | |
puts find(/^0{5}/) # part 1 | |
puts find(/^0{6}/) # part 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment