Skip to content

Instantly share code, notes, and snippets.

@dropkickfish
Created December 2, 2020 12:29
Show Gist options
  • Save dropkickfish/432934627311ab6f727c720ef161c1c0 to your computer and use it in GitHub Desktop.
Save dropkickfish/432934627311ab6f727c720ef161c1c0 to your computer and use it in GitHub Desktop.
Advent of Code 2020 - Day 2 (1)
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