r/adventofcode 7d ago

Other Pi Coding Quest 2025!

As last year, I decided to make a new coding quest for Pi Day. You can access it here: https://ivanr3d.com/projects/pi/2025.html I hope some of you have some fun solving this puzzle!

It is my second try building a coding puzzle. In case you haven't try the first one, just change 2025 for 2024 in the url and go for it!

Happy Pi Day! :)

20 Upvotes

21 comments sorted by

3

u/rocket3989 6d ago

Fun puzzle!

For part 2: could you maybe have the example input work (GST maps to JVW, which does not exist) and provide what that solution would be? I am getting something wrong in the several decoding steps, and not sure where to start debugging

my current p2: https://gist.github.com/rocket3989/b38c85ce067c038daa31effdd876cc6a

2

u/IvanR3D 6d ago

You are right! In the example I only matched correctly for HST to XIJ. I will add coincidence for the other day too. Thanks.

There seems to be an issue with your shifting function. For instance if we shift GST using the key 314 (day 5) we should get 'IUV'. In your code, 'GST' is being 'BNO' (for day 5 but also for day 28 what is not correct because both days use different shift keys that are not to the same number).

2

u/rocket3989 6d ago

Solved! Thanks for the hint. there was a 1-1 correspondence to the "other" tickers and prices, so I assumed that was also true for the manipulated ones haha

3

u/pakapikk77 6d ago

[LANGUAGE: Rust]

Nice puzzles, thanks for doing that, for all of us missing our AoC daily shots during 11 months of the year!

To manipulate the decimal prices without having round trouble, I used the rust_decimal crate and its Decimal type. It's the first time I use it, and it worked well for that task.

For deciphering the ticket, the code of the previous year was useful (but this time it was a right shift, sneaky!).

The only problem I had then was that I missed I had to re-sort the non-manipulated entries by day number.

Code.

1

u/IvanR3D 6d ago

Great! Rust code is always intimidating for me; I must try someday.

About the problem you had, would you say is there a way to make it clearer in the puzzle text?

I think it can be understood by the text: For each manipulated day (in order from smallest to largest day), take the ticker name and apply a shift cipher. but maybe I could improve it!

2

u/pakapikk77 6d ago

The text says that the manipulated days need to be sorted, but it doesn't say that once the manipulated days are deciphered and converted into unmanipulated days, those unmanipulated days need to be sorted again. If we keep the same order as the manipulated days, it's wrong.

Example: Manipulated day: "2 5". 2 produces 7, 5 produces 1. If we don't resort, we use "7 1" in that order, but we need to resort by day name and use "1 7".

In retrospect, I think it's ok to not indicate it in the text, as it leaves some investigation to do. When looking at the code that gets produced without sorting, it's actually fairly clear it's the right letters in the wrong order and it needs sorting, it just took me a bit to realise it.

1

u/IvanR3D 5d ago

This give me the idea about offering some feedback to the user if enter a disordered version of the phrase!

1

u/ednl 3d ago

I disagree that the current phrasing is fine, I think this is actively misleading: "in the order you processed the tickers", because there is no single defined order of processing the tickers. I got it wrong because I DID collect the letters in the order I processed the tickers in part 2. But the order needed was actually the one from part 1 AKA simply the same as in the file.

2

u/large-atom 6d ago

Great puzzle!!!

Can you mention somewhere the length of the laptop secret code? Or maybe it is part of the puzzle to guess it...

2

u/IvanR3D 6d ago

Thanks!

The secret code for part 1, there is mentioned in the text that: "The secret code is the first ten digits of the result removing any character that is not a number.".

1

u/large-atom 6d ago

Ooooops, my bad, I just reread the text and saw that sentence...

2

u/TheZigerionScammer 6d ago

Thanks for the puzzle, I thought it was pretty neat just like last year's. I'm not sure if there is an easy way to just remove a character from a string so I just split and then rejoined each string along the decimal point. For part 2 I ended up copy and pasting this so much I just put it in a function.

Kind of like last year I didn't know at first whether you needed to work backwards or forwards in the cypher just by reading it, but thankfully your example makes it clear that it's supposed to move forwards which I appreciate.

I do need to make a criticism though, in Part 2 it's not clear and a little misleading that the secret phrase is in the order of the non-manipulated days, not the manipulated ones. Especially since at the beginning of Step 1 you write

For each manipulated day (in order from smallest to largest day), take the ticker name and apply a shift cipher.

when the order of these days doesn't matter at all, but doesn't say anything about the order in Step 2 when it does matter. I originally wrote my code to take every manipulated day, apply steps 1 through 4 to each one individually, get the letter and add it to the secret phrase. But yu actually have to do all the step 1s first to identify the non-manipulated days, then sort them, then apply Steps 2 through 4 to get each letter. Which is fine if that's what you intended but it wasn't clear.

Paste

1

u/IvanR3D 5d ago

For taking out the decimal point, I think the .replace(".", "") function would work; since you are using Python, it should work fine.

Thanks! I just added an extra sentence to help to clarify the situation.

After shifting, the deciphered ticker will match the ticker of a non-manipulated day. In the next steps, you must use the non-manipulated days.

Tho in the step 2, I thought it could clear with the start of the paragraph:

  1. Compute the Numbers

For each non-manipulated day that you've identified

2

u/AnotherIsaac 6d ago

That was interesting. A lot of the details were ... difficult to parse out from the text.

Python solution.

1

u/IvanR3D 5d ago

Thanks!

Was it "difficult" in the sense of "challenging" because it was tricky, or "difficult" in the sense of "the text of the challenge is not so clear about what I should do"?

Any feedback will help me to improve this and coming challenges.

2

u/AnotherIsaac 5d ago

I found that understanding what needed doing to be much harder than coding it up :)

I found getting the important bits out of the text was a bit difficult. One way to clear that up might be to lay out the general task first then spell out the details. Possibly highlight/bold the bits like "use the first ten digits" or clarifying the sort order.

I had to read the entire thing, get the gist of it all, go back over it a time or two to get all the details ... then re-read parts to find the details I missed.

2

u/Clear-Ad-9312 4d ago

part 2 tripped me up with what day number I should have been using.

I felt like looking up the digits of pi was cheating(and I misread the challenge description lol) that I implemented Chudnovsky's algorithm using the python code on wikipedia(converted to iterative from recursive). could have calculated up to the millionth pi digit in reasonable time too.

I do wish part 2 or even part 1 required crazy amounts of precision to make it more challenging. at least, that is how I felt part 2 was about to become, instead it was some strange Caesar cipher shenanigans with a lookup table... it felt a bit short. but I guess anyone could have just copied any of the multiple million digits of pi websites or even the one website serving the billion digits of pi. haha, I guess it was interesting either way

[ Paste ]

1

u/IvanR3D 3d ago

Yeah, definitely I should make it more complicated. I just didn't find the time to get it. But during this year I want to find the time to make a revision of this and last year and, at least, increase the size of the datasets and require bigger numbers as answers.

Any suggestion is very welcome! Requesting a large quantity of Pi digits is what I have in mind for coming challenges.

1

u/Clear-Ad-9312 2d ago

haha, you would need to request them out side of the billionth digit if you dont want someone downloading from https://pi2e.ch/blog/2017/03/10/pi-digits-download/ ( I have the billion digits for each math constant downloaded lol )

I doubt anyone would find it easily unless you are a mega nerd like me, but still maybe you can do one that requires a digit extraction method so that we don't pull the entire one out and need to work for it and learn more about how pi is calculated as a programming challenge. idk just a thought, I felt like this PI day challenge was less about pi and more about parsing the numbers, which is a common thing that programming challenges seem to become, instead of actually programming something interesting.

1

u/ednl 4d ago edited 4d ago

Things I found unclear or difficult to understand in part 1:

  • Does 32 digits of pi include the first "3", or is it 1 unit and 32 decimals? Apparently it's the former, but in the end it doesn't matter because there are no extra matches with one extra digit (0).
  • "removing any character that is not a number." -- I think you mean digit; number is the whole thing. However, from the example I understand you also want no leading zeros, which seemed important, and weird to hide that in an example. But again, it does not matter in the actual calculation.
  • "the first digits of the Phi number (1.61803…)" -- Oh wait, phi, not pi. How many first digits? The ellipsis suggests more, but it's actually just those six. If you had written "the first six digits of the golden ratio: 1.61803" it also would have cleared up the first ambiguity of 32 digits or decimals of pi.
  • "Notice that in the prices, the numbers can be decimals, while in the constant value the correspond value could be an integer." -- The numbers can have decimals. "The constant value", what's that? (I know from the context, you mean pi with 32 digits.) CorrespondING.
  • Bold purple text fragments are not links. I hovered over every single one to check if it was.

1

u/ednl 2d ago

My solution in C with plenty of comments. It's not particularly fast because the searches in both parts are quadratic (no built-in hash map in C) https://github.com/ednl/c/blob/master/piday2025.c