From 2d82a8d5015a479018da08c90e6a674bd7d7f88c Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Wed, 2 Dec 2020 12:44:50 -0500 Subject: [PATCH] finished solution --- day02/solution1.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 day02/solution1.rb diff --git a/day02/solution1.rb b/day02/solution1.rb new file mode 100755 index 0000000..2df9185 --- /dev/null +++ b/day02/solution1.rb @@ -0,0 +1,26 @@ +#!/bin/env ruby + +def parse_line (line) + ret = Hash.new + ret[:pass] = line.split(':')[1].strip + ret[:char] = line.split(' ')[1][0] + ret[:min] = line.split(' ')[0].split('-')[0].to_i + ret[:max] = line.split(' ')[0].split('-')[1].to_i + return ret +end +results = { + :pass => 0, + :fail => 0 +} + +File.readlines('./input').each do |line| + password = parse_line(line) + count = password[:pass].count(password[:char]) + if count <= password[:max] && count >= password[:min] + results[:pass] += 1 + else + results[:fail] += 1 + end +end + +pp results \ No newline at end of file