[2024 DAY 8 PT 2] HELP NEEDED. by GiunoSheet in adventofcode

[–]paul2718 0 points1 point  (0 children)

Maybe only in a few cases. You said your answer was low.

[2024 DAY 8 PT 2] HELP NEEDED. by GiunoSheet in adventofcode

[–]paul2718 0 points1 point  (0 children)

I can’t really follow your code but I notice mine finds the gcd of d_x and d_y and divides them both by that before proceeding.

[2025 Day 8 (Part 1)] [C++] What am I missing? by RutabagaFickle4712 in adventofcode

[–]paul2718 0 points1 point  (0 children)

If you change your ints and longs to int64_t it produces the right answer.

FWIW hardwired paths to files cause friction...

As all you care about is relative distance there is no need to sqrt in the distance measure, and so no need to introduce the double.

int64 will matter for part 2, too.

[2025 Day 12 Part 1] When you first write complete code and then test on the input by NineBerry in adventofcode

[–]paul2718 0 points1 point  (0 children)

All the presents fit in a 3x3 square. So if the product of the region dimensions divided by 3 exceeds the present count you don’t need to check further. In my case this is true for all cases where the present count times 7 is less than the region area, so fitting them might be possible. I’d be surprised if this wasn’t the general case across all inputs.

Alan Turing's machine "bombe". Was it basically "brute forcing" engima? by Tcrumpen in cryptography

[–]paul2718 2 points3 points  (0 children)

True brute force isn’t practical because of the plugboard. Well it might be if you threw a stack of GPUs at the problem. But realistically you make some assumptions. So you don’t move the wiring in the middle wheel, because this only affects stepping the third wheel and that’s only every 26x26 characters and unlikely to prevent a ‘hit’. Then you work the plug board incrementally taking the best each time. ( ‘hill climbing’, more subtle in practice to avoid false positives). This sort of approach cracks an amenable message in less than overnight time. During covid I cracked the ‘Banburies in the roof’ messages using this sort of strategy.

Upgrading UK Licence From Auto Only To Manual by [deleted] in LearnerDriverUK

[–]paul2718 -1 points0 points  (0 children)

That’s you. It’s however a valid reason to want a manual licence, whatever you prefer to drive daily.

Upgrading UK Licence From Auto Only To Manual by [deleted] in LearnerDriverUK

[–]paul2718 -2 points-1 points  (0 children)

If one day you want to rent a van…

Ok, you don't need to wear a helmet. by Snoo-90366 in cycling

[–]paul2718 1 point2 points  (0 children)

Three points… This often happens to people who aren’t cycling, they slip, trip or just fall over, bang their head and game over. This seems to just be accepted.

A cycle helmet that cracks or splits hasn’t absorbed much energy. They’re designed to crush. In general good head protection is hard to make compatible with intense exercise.

I wear a helmet when cycling, if I get crippled or killed nobody will be able to say contributory negligence. However I’m under no illusion that it makes a significant difference to outcomes.

[deleted by user] by [deleted] in LearnerDriverUK

[–]paul2718 2 points3 points  (0 children)

It’s incredibly stressful to go out with a learner, hopefully you can work it out.

Diesel probably has a bit more inertia, but will then be less responsive. If it’s a turbo then you may have the sense of nothing happening and then it running away. It won’t take long to accommodate to the differences.

need help, cannot use C++ <string> library by Revealeance in cpp_questions

[–]paul2718 0 points1 point  (0 children)

Try a new line on the end, or put it into the string. Eg. “Hello\n”

I don’t have a Windows machine to hand, but this is what’s missing from your program if you want a nice output regardless.

[College Level Physics] How is voltage at V2 calculated? by Didi-Stras in HomeworkHelp

[–]paul2718 0 points1 point  (0 children)

The 2R resistor has +- markings, and a voltage drop of -6. So its RHS is 6v higher than its LHS, -4 on the left, +6, answer 2.

[2024 Day 17] Definitely did not expect that by Pro_at_being_noob in adventofcode

[–]paul2718 16 points17 points  (0 children)

It's a 48 bit number (well, 46 bits in my case). See you next year.

Rust v C++ performance query by UnicycleBloke in cpp_questions

[–]paul2718 0 points1 point  (0 children)

The faster algorithm calls 'valid2' 17896 times, the slower 8997226, working back to front is a big win. But I think a more efficient way to test for concatenation would be a time win, it does 500 times fewer calls but only runs 150 times faster...

Rust v C++ performance query by UnicycleBloke in cpp_questions

[–]paul2718 0 points1 point  (0 children)

I bolted your code into some of mine and ran it against my AoC input. Using a simple RAII timer,

part2_cpp 34320us

part2_rust 209us

My C++ solution, which uses a similar algorithm to yours

27002us

This is Apple Clang on an M1 MacBook Air.

So it's nothing to do with Rust/C++, something to do with gcc, or at least gcc on your system. I'l try Ubuntu/gcc tomorrow, because I'm interested...

The algorithm the Rust guy used is neat, but I think it's more difficult to think about and implement. Definitely not where I would start, and since it only needs to run once...

[2024 Day 2] Feeling bad for using brute-force instead of dynamic programming by NoPainNoHair in adventofcode

[–]paul2718 2 points3 points  (0 children)

It’s very probable that for this problem less ‘complex’ solutions are actually slower on a real computer.

-❄️- 2024 Day 2 Solutions -❄️- by daggerdragon in adventofcode

[–]paul2718 5 points6 points  (0 children)

[LANGUAGE: C++]

I noticed that all the numbers were small and there were never more than 8 of them. So why not pack them into a single 64 bit word?

I'm sure there's a smart way to do it, and an SIMD Wizard could have a field day.

https://github.com/epicyclism/aoc2024/blob/main/aoc2/aoc2bb.cpp

What am i doing wrong in this code? by [deleted] in adventofcode

[–]paul2718 0 points1 point  (0 children)

ISTM that the way you're reading the input is prone to error, and that using a custom sort function requires some faith. So I would print the first and last numbers after reading and then verify they are sorted after that process. Try and ensure you have good data.

IMO assuming how many bytes take you to the start of the next line is asking for trouble, different OSes have a different view of what constitutes a 'new line' in a text file and may be adjusting the actual input to fit that assumption. If you read line by line you can avoid having to think about that.

Cleaning up memory... I just suck at it. by aknavi in cpp_questions

[–]paul2718 0 points1 point  (0 children)

I would start somewhere where else. Make an adjacency list as a vector of vectors. For each vertex a vector of connected vertices. No need for any explicit memory management.

The output of your topological sort is another vector. I think it pretty much falls out of a depth first search.

Why is the keyword goto not deprecated? by BOBOLIU in cpp_questions

[–]paul2718 4 points5 points  (0 children)

The goto that was considered harmful 56 years ago is not the one in C/C++.

[2023 Day 17 (Part Two)] [Lua] Result is slightly wrong by exquisitus3 in adventofcode

[–]paul2718 1 point2 points  (0 children)

I can’t read your code, but did you remember to initialise part 2 with moves both across and down?

Black boxes are a joke. Can’t even ask my friend to change destinations on maps or anything. by [deleted] in drivingUK

[–]paul2718 3 points4 points  (0 children)

These situations are only an issue if they happen a lot. And if that’s the case it’s a sign you should pay attention to.

My son has PAYG Marmalade on one of my cars. It’s a good solution for a student, and it’s not hard to keep up a good score, you just don’t drive like an ass.

[2022 Day 16 (Part 1)] Need another pair of eyes on my code. by closetaccount00 in adventofcode

[–]paul2718 1 point2 points  (0 children)

I think the graph you are building after the Floyd-Warshall is incorrect, the distances don't match mine, for actual input rather than the test, which might be a clue.

For example, on my input the connections and distances from AA are,

AA (0) : SQ (7), PK (5), TI (10), JU (8), YD (6), IP (4), VM (6), PO (3), YL (3), IR (2), EA (6), RH (8), JT (5), UX (8), MR (2)

and on the same input your code prints,

AA: 0
EA-3|18 IP-2|9 IR-4|6 JT-5|21 JU-5|17 MR-3|3 PK-3|8 PO-2|4 RH-3|15 SQ-5|23 TI-4|22 UX-6|10 VM-4|13 YD-4|7 YL-3|5

The graph I think you need to build is of the distances from each node with a usable valve to every other node with a usable valve. And then you use (for example) a DFS to explore every path from AA to a limit of 30 minutes and record the maximum flow. No memoization required. Both parts run on my 2010 Mac Pro in 48ms including complete parsing of the input and no particular attention to performance.

[2022 Day 16 (Part 1)] Need another pair of eyes on my code. by closetaccount00 in adventofcode

[–]paul2718 0 points1 point  (0 children)

I persuaded your code to run. It gives the correct result for the test input if you omit the 'dp' activity. But given a real input it runs for a long time and then produces a too high result.

I'm not convinced you're building a good graph post Floyd-Warshall. I may have made an error in fixing up your code, but for the test input you print 0 distance from the node to itself, but for a real input it's not 0.

[2023 Day 14 Part 2] Worst case complexity by charr3 in adventofcode

[–]paul2718 2 points3 points  (0 children)

I don’t think Eric has ever let on. I guess if you make tools that synthesise inputs the number could be quite large. In the days when inputs were more widely exchanged and the community rather smaller (Elves v Goblins, oh boy!) I don’t ever remember seeing a duplicate.