-
-
Save darkash/b6a20260ceac7bf14d4346faa3759dd6 to your computer and use it in GitHub Desktop.
AoC 2020 (Day 2)
This file contains 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
input = [ | |
"1-3 a: abcde", | |
"1-3 b: cdefg", | |
"2-9 c: ccccccccc" | |
] | |
def parse(str) | |
str.match(/(?<min>\d+)-(?<max>\d+) (?<char>\S): (?<testcase>\S+)/) | |
end | |
def validate(ipt) | |
info = parse(ipt) | |
min, max, char, testcase = info.values_at(:min, :max, :char, :testcase) | |
count = testcase.count(char) | |
count <= max.to_i && count >= min.to_i | |
end | |
input.select { |ipt| validate(ipt) === true }.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment