From c619806f7bcf52692056a53c9f727520cc15e640 Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Fri, 27 Dec 2024 12:19:28 -0500 Subject: [PATCH] Ruby STDIN conversion --- ruby/2015/1/problem.rb | 2 +- ruby/bin/run | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ruby/2015/1/problem.rb b/ruby/2015/1/problem.rb index efafcb9..c705c0f 100644 --- a/ruby/2015/1/problem.rb +++ b/ruby/2015/1/problem.rb @@ -1,4 +1,4 @@ -input = File.read("../data/2015/1/input.txt").split("") +input = STDIN.read.split("") counts = input.tally final_floor = counts["("] - counts[")"] puts "Part 1: #{final_floor}" diff --git a/ruby/bin/run b/ruby/bin/run index 01cd351..c381539 100755 --- a/ruby/bin/run +++ b/ruby/bin/run @@ -3,4 +3,12 @@ year=$1 day=$2 -time ruby $year/$day/problem.rb +mkdir -p $year/$day +source_file=$(ls $year/$day/*.rb) + +if [[ -z $source_file ]] ; then + echo "No ruby source file found in $year/$day" + exit 1 +fi + +time (cat ../data/$year/$day/input.txt | ruby $source_file)