010203040506070809101112

Advent of Code

2025/12

Christmas Tree Farm

in C#

by encse

You're almost out of time, but there can't be much left to decorate. Although there are no stairs, elevators, escalators, tunnels, chutes, teleporters, firepoles, or conduits here that would take you deeper into the North Pole base, there is a ventilation duct. You jump in.

After bumping around for a few minutes, you emerge into a large, well-lit cavern full of Christmas trees!

Visit the website for the full story and full puzzle description.

I have no words for this...

namespace AdventOfCode.Y2025.Day12;

using System;
using System.Linq;
using System.Text.RegularExpressions;
record Todo(int w, int h, int[] counts);

[ProblemName("Christmas Tree Farm")]
class Solution : Solver {

    public object PartOne(string input) {
        // 🎄 🎄 🎄 This problem was a joke by Eric. The solution is specific to the input.
        
        var blocks = input.Split("\n\n");

        var areas = (
            from block in blocks[..^1]
            let area = block.Count(ch => ch == '#')
            select area
        ).ToArray();

        var todos = (
            from line in blocks.Last().Split("\n")
            let nums = Regex.Matches(line, @"\d+").Select(m => int.Parse(m.Value)).ToArray()
            select new Todo(nums[0], nums[1], nums[2..])
        ).ToArray();
       
        var res = 0;
        foreach(var todo in todos) {
            var areaNeeded = Enumerable.Zip(todo.counts, areas).Sum(p => p.First * p.Second);
            if (areaNeeded <= todo.w * todo.h) {
                res++;
            }
        }
        return res;
    }
}

Please ☆ my repo if you like it!

© 2025 | Advent of Code is a registered trademark in the US | Images provided by Bing and Nano Banana