Skip to content

Commit

Permalink
2024/07
Browse files Browse the repository at this point in the history
  • Loading branch information
encse committed Dec 7, 2024
1 parent 8b80604 commit 7cb4372
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 29 deletions.
8 changes: 8 additions & 0 deletions 2024/Day07/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## --- Day 7: Bridge Repair ---
The Historians take you to a familiar [rope bridge](/2022/day/9) over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side?

When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed.

You ask how long it'll take; the engineers tell you that it only needs final calibrations, but some young elephants were playing nearby and <em>stole all the operators</em> from their calibration equations! They could finish the calibrations if only someone could determine which test values could possibly be produced by placing any combination of operators into their calibration equations (your puzzle input).

Read the [full puzzle](https://adventofcode.com/2024/day/7).
36 changes: 36 additions & 0 deletions 2024/Day07/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace AdventOfCode.Y2024.Day07;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

[ProblemName("Bridge Repair")]
class Solution : Solver {

public object PartOne(string input) => Filter(input, Check1).Sum();
public object PartTwo(string input) => Filter(input, Check2).Sum();

private IEnumerable<long> Filter(string input, Func<long,long,List<long>, bool> check) =>
from line in input.Split("\n")
let parts = Regex.Matches(line, @"\d+").Select(m=>long.Parse(m.Value))
let target = parts.First()
let nums = parts.Skip(1).ToList()
where check(target, 0, nums)
select target;

private bool Check1(long target, long acc, List<long> nums) =>
nums switch {
[] => target == acc,
_ => Check1(target, acc * nums[0], nums[1..]) ||
Check1(target, acc + nums[0], nums[1..])
};

private bool Check2(long target, long acc, List<long> nums) =>
nums switch {
[] => target == acc,
_ => Check2(target, acc * nums[0], nums[1..]) ||
Check2(target, acc + nums[0], nums[1..]) ||
Check2(target, long.Parse($"{acc}{nums[0]}"), nums[1..])
};
}
Binary file added 2024/Day07/input.in
Binary file not shown.
2 changes: 2 additions & 0 deletions 2024/Day07/input.refout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
6231007345478
333027885676693
60 changes: 38 additions & 22 deletions 2024/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public void Show() {

var color = Console.ForegroundColor;
Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ ");
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ sub y{2024}\n \n");
Write(0xcc00, false, " ");
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ int y = 2024;\n ");
Write(0xcc00, false, " \n ");
Write(0xcccccc, false, ".--'");
Write(0xe3b585, false, "~ ~ ~");
Write(0xcccccc, false, "| .-' ");
Expand Down Expand Up @@ -48,9 +48,9 @@ public void Show() {
Write(0xcccccc, false, "| 3 ");
Write(0xffff66, false, "**\n ");
Write(0xcccccc, false, "|");
Write(0x427322, false, "@");
Write(0x7fbd39, false, "@");
Write(0x5eabb4, false, "..");
Write(0x427322, false, "@");
Write(0x4d8b03, false, "@");
Write(0xe3b585, false, "'. ~ ");
Write(0xcc00, false, "\" ' ");
Write(0xe3b585, false, "~ ");
Expand All @@ -67,10 +67,10 @@ public void Show() {
Write(0xcccccc, false, "| 4 ");
Write(0xffff66, false, "**\n ");
Write(0xcccccc, false, "|");
Write(0x4d8b03, false, "_");
Write(0x7fbd39, false, "_");
Write(0x5eabb4, false, ".~.");
Write(0x4d8b03, false, "_");
Write(0x488813, false, "#");
Write(0x7fbd39, false, "_");
Write(0x488813, false, "@");
Write(0xe3b585, false, "'.. ~ ~ ");
Write(0xffff66, true, "*");
Write(0xcccccc, false, "| | ");
Expand All @@ -83,8 +83,8 @@ public void Show() {
Write(0xffff66, false, "**\n ");
Write(0xcccccc, false, "| ");
Write(0xffffff, false, "||| ");
Write(0x427322, false, "@");
Write(0x488813, false, "@@@");
Write(0x488813, false, "@#");
Write(0x427322, false, "@@");
Write(0xe3b585, false, "'''...");
Write(0xcccccc, false, "| |");
Write(0xa25151, false, "... ");
Expand All @@ -94,19 +94,35 @@ public void Show() {
Write(0xcc00, false, "..");
Write(0xcccccc, false, "| 6 ");
Write(0xffff66, false, "**\n ");
Write(0x333333, false, "| | | | | | ");
Write(0x666666, false, " 7\n 8\n ");
Write(0x666666, false, " 9\n 10\n ");
Write(0x666666, false, " 11\n ");
Write(0x666666, false, " 12\n 13\n ");
Write(0x666666, false, " 14\n ");
Write(0x666666, false, " 15\n 16\n ");
Write(0x666666, false, " 17\n ");
Write(0x666666, false, " 18\n 19\n ");
Write(0x666666, false, " 20\n ");
Write(0x666666, false, " 21\n 22\n ");
Write(0x666666, false, " 23\n ");
Write(0x666666, false, " 24\n 25\n \n");
Write(0xcccccc, false, "|");
Write(0x427322, false, "#");
Write(0xffffff, false, "~~~");
Write(0x4d8b03, false, "@");
Write(0x488813, false, "@##@");
Write(0x1461f, false, "@");
Write(0x427322, false, "#@ ");
Write(0xcccccc, false, "| |");
Write(0xa5a8af, false, "/\\ ");
Write(0xa25151, false, "''. ");
Write(0xcccccc, false, "| | ");
Write(0xccccff, false, "-");
Write(0xd4dde4, false, "/ ");
Write(0xffffff, false, ":");
Write(0xcccccc, false, "| 7 ");
Write(0xffff66, false, "**\n ");
Write(0x333333, false, "| .--. | | | | | ");
Write(0x666666, false, " 8\n 9\n ");
Write(0x666666, false, " 10\n 11\n ");
Write(0x666666, false, " 12\n ");
Write(0x666666, false, " 13\n 14\n ");
Write(0x666666, false, " 15\n ");
Write(0x666666, false, " 16\n 17\n ");
Write(0x666666, false, " 18\n ");
Write(0x666666, false, " 19\n 20\n ");
Write(0x666666, false, " 21\n ");
Write(0x666666, false, " 22\n 23\n ");
Write(0x666666, false, " 24\n ");
Write(0x666666, false, " 25\n \n");

Console.ForegroundColor = color;
Console.WriteLine();
Expand Down
Loading

0 comments on commit 7cb4372

Please sign in to comment.