From 95634fc2bd43d0bb7bc1a52852cfe1c99709e39b Mon Sep 17 00:00:00 2001 From: Adam Hellberg Date: Fri, 12 Dec 2025 06:51:58 +0100 Subject: [PATCH] Add stupid Ruby solution for 2025 day 12 --- src/y2025/d12/solve.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 src/y2025/d12/solve.rb diff --git a/src/y2025/d12/solve.rb b/src/y2025/d12/solve.rb new file mode 100755 index 0000000..817be9e --- /dev/null +++ b/src/y2025/d12/solve.rb @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'bundler/setup' +require 'aoc/point' + +sections = ARGF.read.split("\n\n") + +presents = sections[...-1].map { |p| + shape = [] + p.lines[1..].each_with_index { |l, row| + l.strip.chars.each_with_index { |c, col| + shape.push AoC::Point2[col, row] if c == ?# + } + } + shape +} + +class Tree + attr_reader :width, :height, :requirements + + def initialize(width, height, requirements) + @width = width + @height = height + @requirements = requirements + end + + def to_s + "#{width}x#{height} [#{requirements.join(', ')}]" + end +end + +trees = sections[-1].scan(/(\d+)x(\d+):(( \d+)+)/).map { |w, h, r| + Tree.new w.to_i, h.to_i, r.split.map(&:to_i) +} + +presents.each { |p| puts p.map(&:to_s).join(' ') } + +puts trees.count { |t| t.width * t.height >= t.requirements.sum { |r| r * 9 } } -- 2.51.2