Skip to content

Instantly share code, notes, and snippets.

@dropkickfish
Created December 2, 2020 18:29
Show Gist options
  • Save dropkickfish/c590680fc1809fd7f93753b793967db8 to your computer and use it in GitHub Desktop.
Save dropkickfish/c590680fc1809fd7f93753b793967db8 to your computer and use it in GitHub Desktop.
Advent of Code 2020 - Day 2 (2)
array = []
valid = 0
def min(len)
len.split('-')[0].to_i - 1
end
def max(len)
len.split('-')[1].to_i - 1
end
File.foreach('2.txt') { |line| array << line.strip }
array.each do |pass|
p = pass.gsub(':', '').split
s = p[2]
min = min(p[0])
max = max(p[0])
if (s[min] == (p[1]) && s[max] != (p[1])) || (s[min] != (p[1]) && s[max] == (p[1]))
valid += 1
end
end
print valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment