AoC2015/day11/solution.rb

35 lines
779 B
Ruby

#!/bin/env ruby
require 'pry'
def pw_checks(password)
return false if password =~ /i|o|l/
return false unless find_pairs(password)
return false unless find_straights(password)
true
end
def find_pairs(password)
password.scan(/([a-z])\1/).uniq.count >= 2
end
def find_straights(password)
$straights.map { |straight| password.include?(straight) }.include?(true)
end
$straights = ['a']
25.times { $straights.push($straights[-1].next) }
$straights.map! { |char| char << char.next + char.next.next }
$straights.pop(2)
$straights.freeze
password = File.read('./input').chomp.next
password.next! until pw_checks(password) == true
puts "Part 1 Solution: #{password}"
password.next!
password.next! until pw_checks(password) == true
puts "Part 2 Solution: #{password}"