Resolve day 1
This commit is contained in:
commit
a0754de631
24
1/script.rb
Executable file
24
1/script.rb
Executable file
@ -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…
x
Reference in New Issue
Block a user