Resolve day 1
commit
a0754de631
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require_relative '../common'
|
||||
|
||||
def part1
|
||||
input = Input.new(__dir__).readlines.join
|
||||
input.count('(') - input.count(')')
|
||||
end
|
||||
|
||||
def part2
|
||||
input = Input.new(__dir__).readlines.join
|
||||
|
||||
input.chars.each_with_index.inject(0) do |floor, (char, i)|
|
||||
return i if floor < 0
|
||||
char == '(' ? floor + 1 : floor - 1
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
puts "=== Part 1 ==="
|
||||
puts part1
|
||||
puts "=== Part 2 ==="
|
||||
puts part2
|
Loading…
Reference in New Issue