Completed Day 1

main
s00ner 2022-07-12 10:54:21 -04:00
parent 9c9c2aaba7
commit 29463a6bb2
2 changed files with 18 additions and 0 deletions

1
day01/input Normal file

File diff suppressed because one or more lines are too long

17
day01/solution.rb Normal file
View File

@ -0,0 +1,17 @@
#!/bin/env ruby
# Part 1, To what floor do the instructions take Santa?
directions = File.read('./input')
p1answer = directions.each_char.map { |char| char == '(' ? 1 : -1 }.sum
puts "Part 1 Answer: " + p1answer.to_s
# Part 2, What is the position of the character that causes Santa to first enter the basement?
directions = directions.each_char.map { |char| char == '(' ? 1 : -1 }
position = 0
catch :basement do
directions.each.with_index do | x, i |
position = i + 1
throw :basement if directions[0..i].sum == -1
end
end
puts "Part 2 Answer: " + position.to_s