DEV Community

Black
Black

Posted on

The 52-week savings challenge, solved for any goal (and two JavaScript date bugs)

The 52-week savings challenge is simple: save $1 in week 1, $2 in week 2, and so on, up to $52 in week 52. At the end you have $1,378. That's a nice number, but it's probably not your goal. Here's the bit of math that lets you rebuild the challenge for any goal and any end date. I put it in a free savings challenge maker with weeks you tap off as you save.

Where $1,378 comes from

Week amounts of 1, 2, 3 ... n add up to a triangular number:

1 + 2 + ... + n = n(n + 1) / 2
52 x 53 / 2 = 1,378
Enter fullscreen mode Exit fullscreen mode

Solve it backwards

Let each week grow by a step s, so the amounts are s, 2s, 3s ... ns. The total is s · n(n+1)/2. Set that equal to your goal G and solve for s:

s = 2G / (n(n + 1))
Enter fullscreen mode Exit fullscreen mode

Example: $2,000 in 52 weeks gives s = 4000 / 2756 ≈ 1.45. So week 1 is about $1, week 2 about $3, and week 52 about $75.

Rounding without missing the goal

Nobody wants to save $1.45. Round each week to whole dollars, and the total drifts by a few dollars. The fix is to let one week absorb the difference:

const step = goal * 2 / (n * (n + 1));
let weeks = Array.from({ length: n }, (_, i) => Math.round(step * (i + 1)));
const diff = goal - weeks.reduce((a, b) => a + b, 0);
weeks[n - 1] += diff;            // the last (biggest) week absorbs it
Enter fullscreen mode Exit fullscreen mode

For the reverse challenge, where the big weeks come first, reverse the array and let week 1 absorb it instead.

Number of weeks from two dates

const n = Math.round((end - start) / (7 * 24 * 3600 * 1000));
Enter fullscreen mode Exit fullscreen mode

Two date bugs are worth knowing about:

  • new Date("2026-10-26") is parsed as UTC midnight. In US time zones that is the evening of the 25th, so every week label shows one day early. Use new Date("2026-10-26T00:00") to get local midnight.
  • Math.floor(days / 7) + 1 gives 53 weeks for a 364-day span. Math.round gives 52.

Which shape to pick

  • Same each week: $2,000 / 52 = about $38. The easiest to automate.
  • Growing: small at first, so it's easy to start, with the big weeks at the end. The classic.
  • Reverse: big weeks first. Good when the end of the plan lands in December, when money is tight anyway.

If you'd rather color it in on paper, my printable Savings Challenge Tracker has the 52-week and reverse 52-week challenges, a $1,000 goal tracker, the $5 bill challenge and a no-spend days page.

Top comments (0)