From f6eba9c4237db8ad49f8be682e626f0bbb196e99 Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Tue, 19 Dec 2023 16:37:08 -0500 Subject: [PATCH] Ruby (I get paid to write this) --- ruby/2015/1/problem.rb | 15 +++++++++++++++ ruby/bin/run | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 ruby/2015/1/problem.rb create mode 100755 ruby/bin/run 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