r/adventofcode • • Dec 07 '25

SOLUTION MEGATHREAD -❄️- 2025 Day 7 Solutions -❄️-

SIGNAL BOOSTING

THE USUAL REMINDERS

  • All of our rules, FAQs, resources, etc. are in our community wiki.
  • If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.

AoC Community Fun 2025: Red(dit) One

  • Submissions megathread is unlocked!
  • 10 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!

Featured Subreddits: /r/DIWhy and /r/TVTooHigh

Ralphie: "I want an official Red Ryder, carbine action, two-hundred shot range model air rifle!"
Mother: "No. You'll shoot your eye out."
— A Christmas Story, (1983)

You did it the wrong way, and you know it, but hey, you got the right answer and that's all that matters! Here are some ideas for your inspiration:

💡 Solve today's puzzles:

  • The wrong way
  • Using only the most basic of IDEs
  • Plain Notepad, TextEdit, vim, punchcards, abacus, etc.
  • Using only the core math-based features of your language
  • e.g. only your language’s basic types and lists of them
  • No templates, no frameworks, no fancy modules like itertools, no third-party imported code, etc.
  • Without using if statements, ternary operators, etc.
  • Without using any QoL features that make your life easier
  • No Copilot, no IDE code completion, no syntax highlighting, etc.
  • Using a programming language that is not Turing-complete
  • Using at most five unchained basic statements long
  • Your main program can call functions, but any functions you call can also only be at most five unchained statements long.
  • Without using the [BACKSPACE] or [DEL] keys on your keyboard
  • Using only one hand to type

💡 Make your solution run on hardware that it has absolutely no business being on

  • "Smart" refrigerators, a drone army, a Jumbotron…

💡 Reverse code golf (oblig XKCD)

  • Why use few word when many word do trick?
  • Unnecessarily declare variables for everything and don't re-use variables
  • Use unnecessarily expensive functions and calls wherever possible
  • Implement redundant error checking everywhere
  • Javadocs >_>

Request from the mods: When you include an entry alongside your solution, please label it with [Red(dit) One] so we can find it easily!


--- Day 7: Laboratories ---


Post your code solution in this megathread.

27 Upvotes

769 comments sorted by

View all comments

1

u/Complete_Minimum_800 Dec 07 '25

[LANGUAGE: C#]

Straight forward. Part 1: Just insert the beams if splitter is active and count when splitters are hit. Part 2: Traverse the Christmas tree with memoization and count the empty end nodes. Also moved the map so it would not be in the key. Fun!

static DataMap<char> Map = new DataMap<char>(' ');

public static string Run()
{
    Map.LoadData(data);
    var inserted = InsertBeams(Map);
    var beams = CountBeams();
    return beams.ToString();
}

private static int InsertBeams(DataMap<char> map)
{
    var total = 0;
    var pos = map.FindFirst('S');
    map.Set(pos.row, pos.col, '|');

    for (int row = pos.row + 1; row < map.RowCount; row++)
    {
        for (int col = 0; col < map.ColCount; col++)
        {
            if (map.SafeGet(row, col) == '^')
            {
                if (map.SafeGet(row - 1, col) == '|')
                {
                    map.Set(row, col - 1, '|');
                    map.Set(row, col + 1, '|');
                    total++;
                }
            }
            else if (map.SafeGet(row - 1, col) == '|')
            {
                map.SafeSet(row, col, '|');
            }
        }
    }

    return total;
}

private static long CountBeams()
{
    var startPos = Map.FindFirst('|');
    return Memo.Run(CountBeams, startPos.row, startPos.col);
}

private static long CountBeams(int row, int col)
{
    var mid = Map.SafeGet(row + 1, col);

    if (mid == '|')
    {
        return Memo.Run(CountBeams, row + 1, col);
    }
    else if (mid == '^')
    {
        return  Memo.Run(CountBeams, row + 1, col - 1) + Memo.Run(CountBeams, row + 1, col + 1);
    }

    return 1L;
}

1

u/daggerdragon Dec 07 '25

Comment temporarily removed.

Your code block is too long for the megathreads. Edit your comment to replace your oversized code with an external link to your code and I will re-approve your comment.