Skip to content

Instantly share code, notes, and snippets.

@wconrad
Created December 6, 2015 13:57
Show Gist options
  • Save wconrad/e320d151559f1513b984 to your computer and use it in GitHub Desktop.
Save wconrad/e320d151559f1513b984 to your computer and use it in GitHub Desktop.
Advent of code, day 4
#!/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