--- Day 25: The Multiverse Machine ---
"This is incredible!" exclaims an elf physicist, showing you an ancient device recovered from deep within the North Pole ice. "We've discovered what appears to be a quantum computer from a long-lost civilization!"
"We need your help," the elf continues. "We're trying to transport quantum particles through these parallel universes, but these universes behave strangely - they expand and contract as we move between them!"
The rules of quantum transport are very strict:
- Each parallel universe starts as an
NxNgrid. - There are many parallel universes, each with a distinct cycle length.
- Moving to an adjacent cell within the same universe costs
1energy. - You can choose to remain at the current cell, but it still costs
1energy to do so. - Jumping between universes when cycles align costs
10energy. - When you jump from Universe
Ato UniverseB:- Universe
A's grid shrinks by1in both dimensions. - If Universe
Bhasn't been visited before, its grid grows by1in both dimensions. - If any universe's grid becomes smaller than
2x2, it resets to its originalNxNsize and is no longer considered visited. - If a universe's cycle length aligns with the current cycle length but the grid is too small to jump to from your current position, a jump is impossible.
- Universe
The elves need to transport a quantum particle from the starting position (0, 0) to a specific target location using the minimum energy.
Example:
2 7,8
4 5
6 8
9 3
In this example:
- The target point is at
(7, 8)in Universe2.
For Universe 1:
- Its cycle length is
4. - Its initial dimensions are
5x5.
For Universe 2:
- Its cycle length is
6. - Its initial dimensions are
8x8.
For Universe 3:
- Its cycle length is
9. - Its initial dimensions are
3x3.
Universes 1 and 2 will align at 12 steps.
Universes 2 and 3 will align at 18 steps.
Universes 1 and 3 will align at 36 steps.
All three universes will align at 36 steps.
Your starting point is (0, 0) in Universe 1.
Following these rules:
-
Universe
1is too small to reach the target position directly, so your best choice is to move to(4, 4)using5energy and wait for7energy until you can jump to Universe2. -
At this point, you should use
10energy to jump to Universe2. -
Universe
1shrinks to4x4, and Universe2grows to9x9. Now you can move from(4, 4)to(7, 8)in7energy to reach your target point.
Your final energy usage will be 5 + 7 + 10 + 7 = 29
Remember, when jumping between universes:
- If you jump from Universe
1(initially at5x5) to Universe2(initially at8x8), Universe1shrinks to become4x4and Universe2becomes9x9. - If you jump back from Universe
2(now at9x9) to Universe1(now at4x4), Universe2shrinks to become8x8again, but Universe1remains at4x4, because it has already been visited before. - If Universe
3(initially at3x3) shrinks to 1x1, it would reset back to3x3, and it is not considered visited anymore.
The elves are waiting anxiously. Can you help them optimize their quantum particle transport system while managing these expanding and contracting universes?