Solved Day 11

main
s00ner 2022-07-17 11:19:04 -04:00
parent cb1283d990
commit 29fc374254
2 changed files with 35 additions and 0 deletions

1
day11/input Normal file
View File

@ -0,0 +1 @@
vzbxkghb

34
day11/solution.rb Normal file
View File

@ -0,0 +1,34 @@
#!/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}"