Compare commits
No commits in common. "2d82a8d5015a479018da08c90e6a674bd7d7f88c" and "a28408d4d20bdcb8cdbe526872b12251545a12dd" have entirely different histories.
2d82a8d501
...
a28408d4d2
|
@ -5,7 +5,7 @@ numbers = File.readlines('./input')
|
|||
numbers.each do |num1|
|
||||
numbers.each do |num2|
|
||||
sum = num1.to_i + num2.to_i
|
||||
puts num1.strip + '+' + num2.strip + '=' + sum.to_s
|
||||
puts num1 + '+' + num2 + '=' + sum.to_s
|
||||
if sum == 2020
|
||||
puts num1.to_i * num2.to_i
|
||||
exit
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
#!/bin/env ruby
|
||||
#Find the three entries that sum to 2020; what do you get if you multiply them together?
|
||||
|
||||
numbers = File.readlines('./input')
|
||||
numbers.map! { |s| s.to_i}
|
||||
numbers.each do |num1|
|
||||
numbers.each do |num2|
|
||||
numbers.each do |num3|
|
||||
sum = num1 + num2 + num3
|
||||
puts num1.to_s + '+' + num2.to_s + '+' + num3.to_s + '=' + sum.to_s
|
||||
if sum == 2020
|
||||
puts num1 * num2 * num3
|
||||
exit
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
1000
day02/input
1000
day02/input
File diff suppressed because it is too large
Load Diff
|
@ -1,26 +0,0 @@
|
|||
#!/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