This commit is contained in:
Bill Rossi 2025-12-06 06:16:20 -05:00
parent 9ca8885fbc
commit f3b7f68188
2 changed files with 21 additions and 1 deletions

View File

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
require "cephalopod_math"
puts STDIN.read.chomp.split("\n").map(&:split).transpose.map { |p| p[..-2].map(&:to_i).reduce(&(p[-1]).to_sym) }.sum
cephalopod_math = CephalopodMath.for STDIN.read.chomp
puts "Part 1: #{cephalopod_math.wide_column_answers.sum}"

View File

@ -0,0 +1,18 @@
class CephalopodMath
attr_reader :worksheet
def initialize(worksheet)
@worksheet = worksheet
end
def self.for(input)
new input
end
def wide_columns
worksheet.split("\n").map(&:split).transpose
end
def wide_column_answers
wide_columns.map{ |column| column[..-2].map(&:to_i).reduce(&(column[-1]).to_sym) }
end
end