diff --git a/day11/input b/day11/input new file mode 100644 index 0000000..988745d --- /dev/null +++ b/day11/input @@ -0,0 +1 @@ +vzbxkghb diff --git a/day11/solution.rb b/day11/solution.rb new file mode 100644 index 0000000..256fb3b --- /dev/null +++ b/day11/solution.rb @@ -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}"