Welcome, Agent!

This Pi Day your mission is more than just a coding test—it's a race to uncover a hidden financial scheme. During an investigation, our team found a laptop belonging to a mysterious trader known as "π-Ghost." The laptop is locked with a secret numerical code, and inside, it may hold proof of a stock market conspiracy. We discovered that π-Ghost has been manipulating stock prices to match the digits of pi.

Part 1 - Finding Manipulated Prices

A leaked dataset from the Pi Market reveals that some stock prices were altered to match the sequence of digits in Pi. Your first task is to identify which days were manipulated by finding stock prices that appear sequentially within the first 32 digits of Pi.

A clue found on π-Ghost's laptop suggests that the secret code is hidden within these manipulated prices. Follow these steps:

  1. Search for price values that appear in the sequence of Pi.
  2. Find the earliest occurrence of each price in the Pi sequence and match it to the corresponding day.
  3. Continue the process until no more prices match a sequence in Pi.

Once you've identified the manipulated days and their corresponding prices, put them in order from smaller to largest day and apply the following operations:

  1. Use the price from the first manipulated day as your base value.
  2. For every subsequent manipulated day, perform an operation based on the day number:
    • - If day number is even, multiply the current value by the price from that day.
    • - If day number is odd, divide the current value by the price from that day.
  3. Continue this process sequentially for all manipulated days to arrive at the final secret code.

The secret code is the first ten digits of the result removing any character that is not a number.

Example Calculation

Imagine we use the first digits of the Phi number (1.61803…) instead of Pi. Here's a sample dataset:

Day          Price ($)          Ticker
1            0.3                GST
2            3.75               IVA
3            2.64               SPI
4            7.77               LCK
5            1.6                HST
6            1.8                NUM
7            5.88               XIJ

From the Phi sequence, we find the manipulated prices happened on days 1, 5, and 6, so we order them by its day number:

Day          Price ($)          Ticker
1            0.3                GST
5            1.6                HST
6            1.8                NUM

Notice that in the prices, the numbers can be decimals, while in the constant value the correspond value could be an integer.

Now, we apply the operations:

  1. Start with 0.3 (from day 1).
  2. Day 5 (odd) → Divide by 1.6 → 0.3 / 1.6 = 0.1875
  3. Day 6 (even) → Multiply by 1.8 → 0.1875 * 1.8 = 0.3375

Final secret code = 03375 = 3375

Pi Market Dataset:

Day          Price ($)          Ticker
1            150.00             TLM
2            93.23              PIH
3            300.50             MTH
4            420.75             IUV
5            3.14               GST
6            720.20             FKE
7            12.57              KVW
8            88.90              TEC
9            210.00             OIL
10           2.64               PHI
11           45.60              CUV
12           33.83              SPI
13           999.99             MEME
14           28.27              MED
15           123.45             BIA
16           65.80              REN
17           6.53               HST
18           250.00             AND
19           18.85              YVO
20           33.33              XOR
21           8.46               NUM
22           777.77             POT
23           9.42               BNO
24           199.99             NOT
25           15.92              SPI
26           850.00             VSL
27           19.94              IVA
28           58.97              GST
29           27.95              PHI
30           21.99              EXW
                        
Part 2 - Cracking Secret Phrase

After you unlock π-Ghost's laptop in Part 1, you find a hidden text file protected by a secret phrase. Your next mission is to reveal this phrase by following these steps:

1. Decipher the Tickers

For each manipulated day (in order from smallest to largest day), take the ticker name and apply a shift cipher. The key (shift) for each ticker is the price of that day, but first convert the price into an integer by removing the decimal point.

Example:

  • - A price of 10.00 becomes 1000
  • - A price of 3.14 becomes 314

After shifting, the deciphered ticker will match the ticker of a non-manipulated day.

For instance, consider the day 5 from the previous sample dataset:


5            1.6                HST
                        

If we apply the shift cipher to 'HST' with the key '16', we get 'XIJ' that is the ticker that correspond to day 7 in the same sample dataset.

2. Compute the Numbers

For each non-manipulated day that you've identified, convert its price into an integer (remove the decimal point). It will gives you a number that will help you find a letter in the next step.

3. Extract the Letters from the Letters Soup

While searching through π-Ghost's laptop, you find another suspicious file named "cipher_map.txt." Inside, you discover a 16x16 grid filled with what appears to be random letters. However, based on clues from previous investigations, we believe this file contains the key to uncovering the secret phrase.

Think of this table as a circular array with positions numbered from 0 to 255 (starting at 0 in the top-left, moving left-to-right and top-to-bottom). For each number you computed, locate the corresponding position in the grid and extract the letter found there.

4. Reveal the Secret Phrase

Once you have collected all the letters from the letters soup in the order you processed the tickers, combine all the letters to form the secret phrase.

Copy of the cipher_map.txt file:
X J P Z Q T M C A O W Y B G D A
N F R S H V K U E X J P Z Q T M
C L O W Y B G D A N F R S H V K
G E X J P Z Q T M P L O W Y B G
D A N F R S H V K U E X J P Z Q
T M A L O W Y B G D A O F I S H
A K U E X J P Z Q T M C L O W Y
O G D A N F R S H V K U E X J P
Y Q T M C L O W Y B G D A N F R
S H V K U E X Y G Z Q T M C L O
D Y B G D A N F R S H V K U D X
J P Z Q T M C L O W Y B G D A N
F R S H V K U E X J P Z Q T M C
D O W Y B G D A N F R S H V K U
E X J P Z Q T M C O O W Y B G D
A N F R S H V K U E X J P Z Q T

Congratulations! You've completed the challenge. Happy Pi Day!

Did you enjoy solving this quest?

Challenge other people to solve it by sharing it. If you have any feedback, feel free to drop me a message hi@ivanr3d.com, I would like to know your experience!