diff --git a/2019/ruby/Gemfile b/2019/ruby/Gemfile new file mode 100644 index 0000000..e03b97c --- /dev/null +++ b/2019/ruby/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gem "minitest" diff --git a/2019/ruby/Gemfile.lock b/2019/ruby/Gemfile.lock new file mode 100644 index 0000000..5846597 --- /dev/null +++ b/2019/ruby/Gemfile.lock @@ -0,0 +1,13 @@ +GEM + remote: https://rubygems.org/ + specs: + minitest (5.13.0) + +PLATFORMS + ruby + +DEPENDENCIES + minitest + +BUNDLED WITH + 2.0.2 diff --git a/2019/ruby/day_01.rb b/2019/ruby/day_01.rb new file mode 100644 index 0000000..c766399 --- /dev/null +++ b/2019/ruby/day_01.rb @@ -0,0 +1,15 @@ +# puts ARGF.read.lines.map(&:to_i).map {|mass| +# (mass / 3.0).floor - 2 +# }.sum + +fuel = ->(mass) { + total = 0 + loop do + mass = (mass / 3.0).floor - 2 + break if mass <= 0 + total += mass + end + total +} + +puts ARGF.read.lines.map(&:to_i).map(&fuel).sum