Coral Pulse Count
Every full tide on Azure Reef, divers gather around a ring of luminous coral. The celebration opens with one radiant pulse at the center of the reef. Before the tide shifts, a herald declares how many ripple layers will follow. Each new layer introduces a fresh pulse to mark the boundary, and the coral from the previous layer echoes three times through the reefs lattice, sending light outward like a heartbeat felt in every direction.
The community treats this rhythm as a pact with the sea. Once the boundary pulse flashes, the reef repeats every earlier shimmer in triplicate, creating overlapping waves that help fishers navigate and keep nearby lagoon traffic aware of currents. The pattern is slow, deliberate, and always identical: one guiding pulse, three echoes of the past.
Your task is to compute the total number of pulses that glow by the time the final layer finishes. The input, layers, is a non-negative integer. If layers equals zero, only the central pulse shines. For each additional layer, include one new boundary pulse and triple the entire glow from the previous layer. Return the resulting number of pulses as an integer.
Example 1:
Input: layers = 0
Output: 1
Explanation: Only the initial coral emits light.
Example 2:
Input: layers = 1
Output: 4
Explanation: The first ripple adds one pulse and repeats the earlier glow three times.
Example 3:
Input: layers = 3
Output: 40
Explanation: Three layers maintain the rule, producing forty pulses when the celebration ends.
Related Problems
No related problems found
Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
