Once upon a time, in a world made of paths and pebbles,
a little boy named Sumy had to walk through a trail of numbers.
On each step, Sumy picked up all the pebbles he had already seen,
including the one on the current step. He placed them in his magical bag.
🧮 What is the Running Sum?
Imagine an array like this:
[3, 1, 2, 10, 1]
Step 0: Just 3 → Bag = 3
Step 1: 3 + 1 → Bag = 4
Step 2: 3 + 1 + 2 → Bag = 6
Step 3: 3 + 1 + 2 + 10 → Bag = 16
Step 4: 3 + 1 + 2 + 10 + 1 → Bag = 17
[3, 4, 6, 16, 17]
💻 Python Code (with Output)
def running_sum(nums):
result = []
total = 0
for i in nums:
total += i
result.append(total)
return result
# Try it out
nums = [3, 1, 2, 10, 1]
print("Running Sum:", running_sum(nums))
Output:
Running Sum: [3, 4, 6, 16, 17]
💻 C# Code (with Output)
using System;
public class Program
{
public static void Main()
{
int[] nums = {3, 1, 2, 10, 1};
int[] result = new int[nums.Length];
int total = 0;
for (int i = 0; i < nums.Length; i++)
{
total += nums[i];
result[i] = total;
}
Console.WriteLine("Running Sum: [" + string.Join(", ", result) + "]");
}
}
Output:
Running Sum: [3, 4, 6, 16, 17]
🎮 How to Turn It Into a Game?
🎒 Imagine a side-scrolling game where:
-
Each step shows a new number tile.
-
Your character collects running totals as coins or experience.
-
Game shows how your power builds up over time.
-
It becomes a visual math journey!

Comments
Post a Comment