Created
December 2, 2020 12:29
-
-
Save dropkickfish/432934627311ab6f727c720ef161c1c0 to your computer and use it in GitHub Desktop.
Advent of Code 2020 - Day 2 (1)
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
array = [] | |
valid = 0 | |
def min(len) | |
len.split("-")[0].to_i | |
end | |
def max(len) | |
len.split("-")[1].to_i | |
end | |
File.foreach('2.txt') { |line| array << line.strip } | |
array.each do |pass| | |
parray = pass.gsub(':', '').split | |
if parray[2].count(parray[1]) >= min(parray[0]) && parray[2].count(parray[1]) <= max(parray[0]) | |
valid += 1 | |
end | |
end | |
print valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment