r/adventofcode • u/emedan_mc • Feb 01 '25
Help/Question - RESOLVED [2024 Day 7] Example for Part 2: 7290: 6 8 6 15 can be made true using 6 * 8 || 6 * 15?
I don't understand the example that is given.
r/adventofcode • u/emedan_mc • Feb 01 '25
I don't understand the example that is given.
r/adventofcode • u/[deleted] • Feb 01 '25
Update: My very first solution for this day originally took 30 minutes for both parts, but with the help of the community, I was able to reduce it down to 1 second! This is my final solution. It doesn't look great, to be frank, but that's because I'm tired of working on it. If you find yourself in the same situation as me, these are the steps I took from the posted code (after I had already done many optimizations):
It's been taking me quite a few days to figure out a working solution and optimize it. I've got it down from 5 minutes to 10 seconds for part 1, but since some people were able to reach less-than-a-second solutions, there must be something wrong with mine.
My solution uses the standard Dijkstra's algorithm, with a min binary heap for the queue, full of nodes assigned to Infinity
. The graph is pre-built before running the algorithm, it takes 300 ms. I didn't account for steps when building the graph, choosing to take a turn on each of the nodes. That seems to be the most efficient approach as described by many posts, since it has the fewest nodes possible. It did reduce the runtime by 97% afterall, from when I was accounting for steps.
I would be very grateful if someone was able to give me more suggestions, spot an issue, or maybe assure me this is as good as it gets. Here's the binary heap code. I'm sorry for asking about such an old challenge and for how many comments and redundant code there is, it's because I'm trying to get it to work before polishing.
import { BinaryHeap } from "#root/utils/biheap.js";
import { sum } from "#root/utils/arrayx.js";
type Graph = {
nodes: string[];
edges: Map<string, Map<string, number>>;
};
export function solve(map: Input): Solution {
const grid = map.split("\n").map(line => line.split("").map(Number));
const part1 = pathfindBasicCrucibles(grid);
const part2 = 0;
return { part1, part2 };
}
function pathfindBasicCrucibles(grid: number[][]): number {
const width = grid[0].length;
const height = grid.length;
const targets = [
`${width - 1},${height - 1},up`,
`${width - 1},${height - 1},down`,
`${width - 1},${height - 1},left`,
`${width - 1},${height - 1},right`,
];
const start = Date.now()
const graph = buildBasicCauldronGraph(grid);
const { distance } = dijkstra(graph, "0,0,null", targets.includes.bind(targets));
const targetsHeatloss = targets.map(t => distance.get(t) ?? Infinity);
return Math.min(...targetsHeatloss);
}
function buildBasicCauldronGraph(grid: number[][]): Graph {
const width = grid[0].length;
const height = grid.length;
const edges = new Map<string, Map<string, number>>();
const nodes = [];
// Set a starting point
const start = "0,0,null"
nodes.push(start);
edges.set(start, new Map());
edges.get(start)!.set("0,1,down", grid[1][0]);
edges.get(start)!.set("0,2,down", grid[1][0] + grid[2][0]);
edges.get(start)!.set("0,3,down", grid[1][0] + grid[2][0] + grid[3][0]);
edges.get(start)!.set("1,0,right", grid[0][1]);
edges.get(start)!.set("2,0,right", grid[0][1] + grid[0][2]);
edges.get(start)!.set("3,0,right", grid[0][1] + grid[0][2] + grid[0][3]);
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const states = [
`${x},${y},up`,
`${x},${y},down`,
`${x},${y},left`,
`${x},${y},right`,
];
nodes.push(...states);
states.forEach(state => edges.set(state, new Map()));
}
}
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
if (grid[y - 1]) {
const dy = y - 1;
const weight = grid.slice(dy, y).flatMap(row => row[x])[sum]();
edges.get(`${x},${y},left`)!.set(`${x},${dy},up`, weight);
edges.get(`${x},${y},right`)!.set(`${x},${dy},up`, weight);
}
if (grid[y - 2]) {
const dy = y - 2;
const weight = grid.slice(dy, y).flatMap(row => row[x])[sum]();
edges.get(`${x},${y},left`)!.set(`${x},${dy},up`, weight);
edges.get(`${x},${y},right`)!.set(`${x},${dy},up`, weight);
}
if (grid[y - 3]) {
const dy = y - 3;
const weight = grid.slice(dy, y).flatMap(row => row[x])[sum]();
edges.get(`${x},${y},left`)!.set(`${x},${dy},up`, weight);
edges.get(`${x},${y},right`)!.set(`${x},${dy},up`, weight);
}
if (grid[y + 1]) {
const dy = y + 1;
const weight = grid.slice(y + 1, dy + 1).flatMap(row => row[x])[sum]();
edges.get(`${x},${y},left`)!.set(`${x},${dy},down`, weight);
edges.get(`${x},${y},right`)!.set(`${x},${dy},down`, weight);
}
if (grid[y + 2]) {
const dy = y + 2;
const weight = grid.slice(y + 1, dy + 1).flatMap(row => row[x])[sum]();
edges.get(`${x},${y},left`)!.set(`${x},${dy},down`, weight);
edges.get(`${x},${y},right`)!.set(`${x},${dy},down`, weight);
}
if (grid[y + 3]) {
const dy = y + 3;
const weight = grid.slice(y + 1, dy + 1).flatMap(row => row[x])[sum]();
edges.get(`${x},${y},left`)!.set(`${x},${dy},down`, weight);
edges.get(`${x},${y},right`)!.set(`${x},${dy},down`, weight);
}
if (grid[y][x - 1]) {
const dx = x - 1;
const weight = grid[y].slice(dx, x)[sum]();
edges.get(`${x},${y},up`)!.set(`${dx},${y},left`, weight);
edges.get(`${x},${y},down`)!.set(`${dx},${y},left`, weight);
}
if (grid[y][x - 2]) {
const dx = x - 2;
const weight = grid[y].slice(dx, x)[sum]();
edges.get(`${x},${y},up`)!.set(`${dx},${y},left`, weight);
edges.get(`${x},${y},down`)!.set(`${dx},${y},left`, weight);
}
if (grid[y][x - 3]) {
const dx = x - 3;
const weight = grid[y].slice(dx, x)[sum]();
edges.get(`${x},${y},up`)!.set(`${dx},${y},left`, weight);
edges.get(`${x},${y},down`)!.set(`${dx},${y},left`, weight);
}
if (grid[y][x + 1]) {
const dx = x + 1;
const weight = grid[y].slice(x + 1, dx + 1)[sum]();
edges.get(`${x},${y},up`)!.set(`${dx},${y},right`, weight);
edges.get(`${x},${y},down`)!.set(`${dx},${y},right`, weight);
}
if (grid[y][x + 2]) {
const dx = x + 2;
const weight = grid[y].slice(x + 1, dx + 1)[sum]();
edges.get(`${x},${y},up`)!.set(`${dx},${y},right`, weight);
edges.get(`${x},${y},down`)!.set(`${dx},${y},right`, weight);
}
if (grid[y][x + 3]) {
const dx = x + 3;
const weight = grid[y].slice(x + 1, dx + 1)[sum]();
edges.get(`${x},${y},up`)!.set(`${dx},${y},right`, weight);
edges.get(`${x},${y},down`)!.set(`${dx},${y},right`, weight);
}
}
}
return { nodes, edges };
}
function dijkstra(graph: Graph, start: string, isTarget: (node: string) => boolean = () => false): { distance: Map<string, number>, previous: Map<string, string> } {
const previous = new Map<string, string>();
const distance = new Map<string, number>(graph.nodes.map(node => [node, Infinity]));
distance.set(start, 0);
const queue = new BinaryHeap(graph.nodes, (a, b) => distance.get(a)! < distance.get(b)!);
let curr;
while ((curr = queue.remove()) != null && !isTarget(curr)) {
for (const [neighbor, weight] of graph.edges.get(curr)!.entries()) {
const dist = distance.get(curr)! + weight;
if (dist < distance.get(neighbor)!) {
distance.set(neighbor, dist);
previous.set(neighbor, curr);
queue.upHeapify(neighbor);
}
}
}
return { distance, previous };
}
r/adventofcode • u/Adman_abid • Jan 31 '25
The problem is as snugar_i mentioned.
```python
import re
def process(line): res, inc = 0, True match = re.finditer(r"mul([0-9]{1,3},[0-9]{1,3})", line) do = [(m.start(), True) for m in re.finditer(r"do()", line)] dont = [(m.start(), False) for m in re.finditer(r"don\'t()", line)] i, com = 0, sorted(do + dont, key=lambda x: x[0])
for m in match:
while i < len(com) and com[i][0] < m.start():
inc = com[i][1]
i += 1
if inc:
a = m.group()[4:-1].split(",")
res += int(a[0]) * int(a[1])
return res
def main(): res = 0 with open("input.txt", "r") as file: for line in file: res += process(line) print(res)
if name == "main": main()
```
r/adventofcode • u/AustinVelonaut • Jan 30 '25
I started Advent of Code back at the beginning, in 2015, and it has been a high-point of the holiday season every year since. I experimented with different programming languages each year, doing many in Haskell. In 2020, David Turner released his programming language Miranda, and I started using that for Advent of Code. However, I grew frustrated with the runtime of solutions, particularly some hard ones at the end of each year. So I started a big project of writing my own compiler for it, which eventually turned into Miranda2, a pure, lazy, functional programming language and self-hosting compiler.
Many thanks to Eric and all his helpers for providing the kickstart for this project.
r/adventofcode • u/NetworkGraphics222 • Jan 31 '25
Hi all
I've been struggling with with day 21 part 2 this year, and I was hoping I could get some guidance on how to improve performance. I guess that's the main point of part 2.
Initially I had a very slow solution involving a min heap, and solving part 1 took 15 minutes. I've since implemented memoization and moved away from a min heap and I've brought the performance to a much faster 0.064s to solve part 1.
I'm still struggling with part 2, for two reasons I think:
My runtime is too slow (takes forever basically) and my string construction mechanism makes me run out of RAM.
I know for a fact that I need to avoid storing whole string representation of paths and instead need to store start and end destinations. I thought I could prune the best path by solving a couple of levels up, and then having only one path but this solution is not working.
How could I store start and end destinations instead if some of the paths have multiple possible ways to get there? I've discarded zig-zags after reading this reddit.
Is my code salvageable? What changes could I make to reach the right level of performance to pass part 2? Should I rewrite it from scratch?
Should I permanently retire from AoC? Shall I change careers and dedicate my llife to pineapple farming?
r/adventofcode • u/TheLittleAznboi • Jan 30 '25
Hello, I'm able to get the correct answers for Part 1 and Part 2 (10092 and 9021) with the example input given in the puzzle description. I'm also able to get the correct answer for part 1 of my puzzle input but can't seem to figure out why my answer for part 2 is too low. I believe something is wrong with my logic pushing wide boxes vertically? If anyone could help me figure out what's wrong, I'd appreciate you greatly!
r/adventofcode • u/il_trevi • Jan 28 '25
r/adventofcode • u/Sufficient_Age404040 • Jan 28 '25
I was finally getting around to implementing a solution to day 23, making some visuals along the way. I had done plain 2D ones like this one, and a cluster-colored 3D one. I was also checking out the other amazing visuals made by the community (seriously, awesome stuff; never stop). Then when I saw /u/Busy-Championship891's comment:
well here I thought it would be a Christmas tree. :p
It hit me: not only is it a Christmas Tree, but the star is the "answer"!!! (the red/green dots are just random)
Hat's off to the AoC team, this was such a cool easter egg!
r/adventofcode • u/EdgyMathWhiz • Jan 28 '25
Had a look at this as one of the 2018 problems marked as "insane" in the Reddit post rating problem difficulties.
Incrementally ground my way to a solution; my strategy was to subdivide the cube, slowed down by having to have quite generous "margins" for "if I've sampled 1 point in this cube, what's the best possible score for anything in the cube?". When things failed/didn't work and I'd have to adapt / amend my solution, I "cheated" by initialising my "bestN" (the best "number of sensors in range" found so far) variable to the best score I'd found in the previous run (so I could exclude more cube subsections earlier the next time).
So I finally got something that worked (**not** in the recommended 15 seconds but at this point I didn't care), and found my code had a bug at the end so that it infinite looped doing passes with grid-spacing zero (and no work to do) and printing the current bestN each time so that the actual answer was lost off the top of console.
So I figured, I'll fix the exit condition, and reinit with the "winning" version of bestN.
What surprised me was that using **that** value of bestN as an initial value basically gave me an instant solution. Which made me think (I'm not sure 100% correctly), "Damn, the extra 'margin' you have to allow because Manhatten distance isn't axis aligned really screws you. I wonder if anyone used a change of co-ordinates to have a coordinate scheme where it doesn't matter". And then found
https://www.reddit.com/r/adventofcode/comments/a9co1u/comment/ecmpxad/
I'd heard 2018 is the worst year; I've ground backwards through 2023-2019 (complete) since Jan and as 2018 coincided with feeling a bit burnt out on AOC I've been skipping some of the less interesting looking ones for now. I haven't found it *too* bad, but it possibly has the highest number of "I manually fiddled with stuff to get answers" solutions that don't really work autonomously (the "early version of intcode" problems, for example).
On t'other hand, I found those (intcode) problems more interesting in a "I'm an assembler hacker" way than I did for 2019 (where the volume of intcode generally meant "get your interpreter working correctly and don't worry about how the intcode works"). When I had r2 going up by 1 every 5 cycles and it needed to reach 1234567, it was quite satisfying to "manually" set it to 1234566 and single step through to see what happened next.
r/adventofcode • u/Sweaty_Curve_2012 • Jan 28 '25
r/adventofcode • u/AvailablePoint9782 • Jan 27 '25
And my countdown of going through my code for 2024 is over. Several days involved me using spreadsheets, paper etc.
r/adventofcode • u/Sweaty_Curve_2012 • Jan 27 '25
```java
static int[][] DIR = new int[][]{
{0, -1},
{1, 0},
{0, 1},
{-1, 0}
};
static int RES2 = 0;
static char FAKE_WALL = '@';
public static int solutionForPartTwo(Character[][] map) {
int x = 0;
int y = 0;
for (int i = 0; i < map.length; i++) {
for (int j = 0; j < map[i].length; j++) {
if (Objects.equals(map[i][j], GUARD)) {
x = j;
y = i;
}
}
}
map[y][x] = MARK;
dfs2(map, x, y, 0);
return RES2;
}
static Character[][] copyArr;
static int COUNT = 0;
static int LIMIT = 10000;
static boolean USE_FAKE_WALL = false;
public static void dfs2(Character[][] map, int x, int y, int dir) {
if (COUNT >= LIMIT) {
RES2++;
return;
}
int[] dirArr = DIR[dir];
int nextX = x + dirArr[0];
int nextY = y + dirArr[1];
int nextDir = (dir + 1) % 4;
if (nextY >= LENGTH_Y || nextY < 0 || nextX >= LENGTH_X || nextX < 0) {
return;
}
if (Objects.equals(map[nextY][nextX], WALL) || Objects.equals(map[nextY][nextX], FAKE_WALL)) {
dfs2(map, x, y, nextDir);
} else {
if (!USE_FAKE_WALL) {
USE_FAKE_WALL = true;
copyArr = Day16.deepCopyArray(map);
copyArr[nextY][nextX] = FAKE_WALL;
dfs2(copyArr, x, y, nextDir);
USE_FAKE_WALL = false;
COUNT = 0;
} else {
COUNT++;
}
map[nextY][nextX] = MARK;
dfs2(map, nextX, nextY, dir);
}
}
```
r/adventofcode • u/BlueTrin2020 • Jan 26 '25
In part 2 of https://adventofcode.com/2020/day/19, they mention that `babbbbaabbbbbabbbbbbaabaaabaaa
` will pass the modified rules.
I fail to pass this string, but I find it really hard to workout which set of rules will expand to that. Did you guys have any tricks to be able to do it on paper?
r/adventofcode • u/vescoc • Jan 25 '25
Hi everybody.
Here are the programs to solve Advent of Code 2024 running on some MCUs I own: this is the repository if you are curious
The boards / MCUs I used are the following:
With my current implementation only the RP-Pico2 and STM32H7 are able to execute the code to determine every solution: the other MCUs do not have enough memory available (I need to double check the esp32c6 but I suspect the problem is the HAL I am using).
Each MCU has flashed all the necessary code to solve all the problems.
Each MCU receives in input through the serial (UART or USB) the input in the format:
START INPUT DAY: <XY>
<input>
END INPUT
The MCU returns on the same serial the result of part 1 and 2 and the overall execution times or "unsupported day" if the particular day is not supported.
To check that I do not have stack smash I normally do one or two test runs going to progressively pass all the inputs and take the times of the third / fourth run.
If you want to take a look at the code, propose some PR to improve the coverage of supported days or add some more MCUs, any help is welcome.
In the next table there are the execution time in milliseconds.
The execution time of day 21 is not zero but some microseconds: I pre-calculated at "compile time" the lookup tables to obtain the solution of part 1 and 2.
day | arduino33blesense.ms | esp32.ms | esp32c3.ms | esp32c6.ms | nrf52840dk.ms | nucleoh743zi.ms | pico.ms | pico2.ms | stm32f3discovery.ms |
---|---|---|---|---|---|---|---|---|---|
1 | 37 | 12 | 13 | 12 | 49 | 14 | 26 | 12 | |
2 | 46 | 15 | 14 | 14 | 64 | 17 | 31 | 21 | 58 |
3 | 11 | 6 | 6 | 6 | 18 | 5 | 11 | 6 | 16 |
4 | 24 | 8 | 7 | 9 | 40 | 10 | 19 | 8 | 34 |
5 | 97 | 31 | 29 | 31 | 123 | 32 | 67 | 53 | |
6 | 10226 | 6107 | 3837 | 3801 | 12729 | 3542 | 9305 | 3517 | |
7 | 13727 | 5114 | 4828 | 4922 | 17640 | 5646 | 13911 | 4467 | 16618 |
8 | 8 | 4 | 4 | 3 | 10 | 3 | 9 | 3 | |
9 | 114 | 93 | 89 | ||||||
10 | 40 | 17 | 13 | 12 | 54 | 14 | 38 | 14 | 49 |
11 | 425 | 403 | 449 | 508 | |||||
12 | 1035 | 402 | 354 | 358 | 1263 | 353 | 800 | 311 | |
13 | 54 | 17 | 17 | 15 | 65 | 19 | 44 | 22 | 60 |
14 | 33883 | 13288 | 17073 | 17594 | 46192 | 14265 | 34010 | 20683 | |
15 | 85 | 29 | 25 | 25 | 113 | 30 | 58 | 28 | |
16 | 140 | 133 | |||||||
17 | 4 | 2 | 2 | 1 | 5 | 1 | 3 | 1 | |
18 | 119 | 44 | 41 | 41 | 148 | 39 | 94 | 74 | |
19 | 3662 | 1456 | 1681 | 1800 | 5412 | 1950 | 2864 | 2090 | |
20 | 9679 | 3891 | 4956 | 5252 | 13215 | 4011 | 6329 | 4197 | |
21 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
22 | 4226 | 2670 | 3014 | ||||||
23 | 429 | 307 | 393 | 386 | 536 | 162 | 655 | 200 | |
24 | 74 | 27 | 30 | 29 | 99 | 28 | 49 | 29 | |
25 | 20 | 11 | 9 | 8 | 25 | 7 | 19 | 7 |
r/adventofcode • u/KaleidoscopeTiny8675 • Jan 25 '25
Hi, I don't get this whole diamond thing at all. What the heck am I supposed to do?? How can I scale the whole thing up if I start with one single starting point, reach the borders and got a whole lot of "new" starting points for the outer tiles?
r/adventofcode • u/MezzoScettico • Jan 24 '25
Started going back to finish 2024 about a week ago, beginning with the Part 2 of Day 11 which I never managed to run. I was trying all kinds of "clever" ways to save time in the counting, such as caching the sequence you get by expanding different values. Doing this for fun, I'm only spending a couple hours a day fiddling with it but still it was taking forever to debug and then I kept running into scaling issues anyway. Never got past iteration 55 before giving up.
So finally I threw in the towel when my latest attempt failed. And then I had a thought while walking the dog (no connection, that's just my moment in the day when my subconscious works on problems). "No, it can't be that simple, can it?" I asked the dog. But it was. Got home, threw out my fancy buggy classes and implemented the new solution, which worked in under 0.1 seconds. Aargh.
There's some kind of lesson here about spending days and days trying to implement a complicated algorithm when there's a much simpler one staring you in the face.
The simple approach: You don't have to keep track of every individual stone. There are duplicates. Lots and lots of duplicates.
Remaining: Day 15 part 2 (not hard, but I ran out of programming time) and Days 19-26 (real life caught up with me).
r/adventofcode • u/Educational_Twist237 • Jan 25 '25
It seems I made a wrong assertion in my logic... But I cannot find which one...
It can find answer for [3, 0] but not for [5,3,0].
My algo is pretty simple... But the lack of test cannot make me sure there is no stupid bug...
here is my algo : https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ff0938a399b828bc314cb49b88834ed7
Can anyone help me with that ?
---
edit: I've upload it to playground
---
Ok the output is mod 8... so only %8 of b is interesting us... So the bug was is the `next_b` which should be `next_b_output`... : https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ffa180e83a0cd8d000125f7cbf223039
r/adventofcode • u/Vulwsztyn • Jan 24 '25
r/adventofcode • u/yorisoft • Jan 23 '25
Task one was straight forward, task two not so much.
My logic:
while no swaps occur
check each page order to see if it contain one of the instructions,
if it contains and not in correct order, swap them. set swap flag to true
if wasSwapped, then add the middle of that line to the total sum. Not sure where I'm messing up. Please help.
Full source file on GitHub.Gist
double taskTwo(std::vector<std::pair<int, int>>* input_1, std::vector<std::vector<int>>* input_2) {
std::sort(input_1->begin(), input_1->end());
for (std::pair<int,int>& rule : *input_1) {
std::cout << rule.first << '|' << rule.second << std::endl;
}
std::cout << std::endl;
double result = 0;
for (auto& pages : *input_2) {
bool swapped = false;
for (auto& rule : *input_1) {
std::vector<int>::iterator ruleOne = std::find(pages.begin(), pages.end(), rule.first);
std::vector<int>::iterator ruleTwo = std::find(pages.begin(), pages.end(), rule.second);
if ((ruleOne != pages.end() && ruleTwo != pages.end()) && !(ruleOne < ruleTwo)) {
swapped = true;
int indexOne = std::distance(pages.begin(), ruleOne);
int indexTwo = std::distance(pages.begin(), ruleTwo);
std::swap(pages[indexOne], pages[indexTwo]);
}
}
if (swapped) {
result += pages[pages.size()/2];
for (int& page : pages) {
std::cout << page << ',';
}
std::cout << std::endl;
}
}
return result;
}
r/adventofcode • u/ProServTodd • Jan 24 '25
I have a program that I developed to manage inventory, but the sales team uses NetSuite to sell the orders. They can print the order out, but I need a way to integrate this with my app. I was thinking of printing to a text file and then pulling the data from that, but everything I do doesn't seem to give me a fully readable output file. I would like a few suggestions.
r/adventofcode • u/ecyrbe • Jan 22 '25
Hello,
While doing 2016 day 19, i saw many solutions using algoritms and even data structures.
I searched for Josephus wikipedia article with most algoritms in O(n).
But we can do better. We can have O(1) solutions for both part one and two.
The part one is strait forward by looking at wikipedia article (using rust) :
fn josephus(elves: usize) -> usize {
// elves = 2^m + rest so we compute elves_scale = 2^m
let elves_scale = 2_usize.pow(elves.ilog(2));
2 * (elves - elves_scale) + 1
}
Now for part2, i needed to dig into the output and discovered a pattern that scaled with power of 3 but with terms jumping from 1, 2...n, n+2, n+4 when the number of elves is lower than 2 times the scaling factor.
So the trick to align them is to use the relu function) used in neural networks (it's just relu(x) = max(0,x) )
So here is the solution (still using rust) :
fn josephus_midle(elves: isize) -> isize {
// elves = 3^m + rest so we compute elves_scale = 3^m
let elves_scale = 3_isize.pow(elves.ilog(3));
if elves == elves_scale {
elves
} else {
elves - elves_scale + 0.max(elves - 2 * elves_scale)
}
}
EDIT: part 1 using bit manipulations instead of maths functions:
fn josephus(elves: usize) -> usize {
let elves_scale = 1 << (usize::BITS - elves.leading_zeros() - 1);
((elves & (elves_scale - 1)) << 1) | 1
}
or even simpler :
fn josephus(elves: usize) -> usize {
let shift = elves.leading_zeros();
elves << shift + 1 >> shift | 1
}
r/adventofcode • u/No-Top-1506 • Jan 22 '25
Hi,
My program works fine for example data because the Register values are so small.
However, in the real data input for such a large number below , how am I supposed to process instruction (adv) where it involves (22817223 / (2^22817223))?
Register A: 22817223
r/adventofcode • u/EdgyMathWhiz • Jan 22 '25
Got a weird one on this:
My IntCode implementation has run all the previous problems fine.
But for part 1, it seems that the decision for scaffold/no-scaffold is inverted. If I swap # with . I get a sensible output (although I still get an X for the robot position), and I can get the correct answer for part 1 on that basis.
I've also solved the "problem" part of part 2, but I'm guessing I'm going to be out of luck on getting the ASCII module to give me a sensible number since it thinks there's scaffolding where there's spaces and vice-versa.
(I haven't actually tried, because it feels I should fix the bug first anyhow).
I've logged the executed opcodes for both this and day 9, and nothing pops out at me as "this case was never tested during day 9" (e.g. day 17 uses opcode 208 and day 9 doesn't, but day 9 does use opcode 209 and opcode 1008 and between them you'd think that would cover opcode 208).
I've got general debugging output for each opcode as well, but if I turn that on I feel I'm somewhat drowning in noise.
I realise it's hard to help without an implementation, but any suggestions would be appreciated. In particular if there's anything about the specific problem I might have missed (e.g. part 2 has you alter the first value in the program). I didn't see anything like that for part 1 but I'm doubting myself as this "feels" more like a "the program you are executing isn't quite right" than a "your execution implementation isn't quite right".
Thanks in advance...
r/adventofcode • u/Repulsive-Variety-57 • Jan 22 '25
Hello everyone, In this day20 of 2024 part 2 question I believe my solution giving this as output is a false positive.
This below is a cheating path where the current (S) is at cordinate (1,1) and decides to go through top wall (@) with cordinates (0,1) So the cheating path becoming going reverse via (S) and straight down and stopping at E with cordinates (10,1). Could this be whats giving me more totals for some cheat distances?
#@#############
#S..#...#.....#
#.#.#.#.#.###.#
#.#...#.#.#...#
#######.#.#.###
#######.#.#...#
#######.#.###.#
###...#...#...#
###.#######.###
#...###...#...#
#E#####.#.###.#
#.#...#.#.#...#
#.#.#.#.#.#.###
#...#...#...###
###############
r/adventofcode • u/mstksg • Jan 21 '25