finished solution
parent
c68003b3bb
commit
2d82a8d501
|
@ -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
|
Loading…
Reference in New Issue