diff --git a/ruby/2015/1/problem.rb b/ruby/2015/1/problem.rb new file mode 100644 index 0000000..efafcb9 --- /dev/null +++ b/ruby/2015/1/problem.rb @@ -0,0 +1,15 @@ +input = File.read("../data/2015/1/input.txt").split("") +counts = input.tally +final_floor = counts["("] - counts[")"] +puts "Part 1: #{final_floor}" + +floor = 0 +steps = 0 +input.each do |char| + floor += 1 if char == "(" + floor -= 1 if char == ")" + steps += 1 + break if floor < 0 +end + +puts "Part 2: #{steps}" diff --git a/ruby/bin/run b/ruby/bin/run new file mode 100755 index 0000000..01cd351 --- /dev/null +++ b/ruby/bin/run @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +year=$1 +day=$2 + +time ruby $year/$day/problem.rb