DEV Community

Daisy Auma
Daisy Auma

Posted on

How I Built a Daily Chart-Guessing Game on Reddit (And Why the Crowd Keeps Winning)

I built a game, and on day two I scored 0 on it.

The chart was monthly airline passengers from 1958 to 1960. I could see two years of data, with a clear summer peak each year. I drew the third summer a little higher than the last. The real line came in, and my peak was two months early. My line ended at 562 thousand passengers. The real number was 432.

Zero out of a hundred. On my own game.

That game is Trendline, my entry for Reddit's Game of the Day hackathon. Here's how it works, how I built it, and what the first nine players taught me.

What Trendline is

Every day, Trendline posts a real chart with the ending hidden. You see the first part of the line, then drag your finger across the empty space to draw where you think it goes next.

When you lock in your guess, three lines appear:

  • Yours, in orange
  • The crowd's average guess, built from everyone who played that day
  • What actually happened, drawn in last

You get a score out of 100, the crowd's score, and a short fact about the data. The charts are all real public data: CO2 at Mauna Loa, Japan's shrinking population, Ireland's 2015 GDP spike, sunspot cycles, and mobile subscriptions in Kenya.

You can play it at r/TrendlineGame, and the full code is on GitHub.

Why a chart game

I teach data science at LuxDevHQ, and my first lesson is always the same. Before we touch a model, I show a chart and ask everyone to guess what happens next.

Then we compare the guesses with what actually happened.

It's the most useful habit in data work: look at the data, commit to a prediction, then check it. When Reddit announced a hackathon for daily games, I wanted to see if that classroom moment could work as one.

How it works

Trendline runs on Devvit Web, Reddit's platform for apps that live inside posts. The client is React and TypeScript, the server is a small Hono app, and Redis stores everything the game needs to remember.

Real data, not made-up charts

The judges mark down games that feel generic, and a chart game only works if the charts are real. So the data comes from the World Bank, NOAA, NASA's GISTEMP, and a few classic time series datasets.

A Python script turns that raw data into a TypeScript file the game imports. For each chart it decides how much of the line to show and sets the axis range:

for c in charts:
    lo, hi = min(c['values']), max(c['values'])
    span = (hi - lo) or abs(hi) or 1
    y_min = lo - span * 0.3
    if lo >= 0 and y_min < 0:
        y_min = 0  # counts and rates can't go below zero
    c['yMin'] = round(y_min, c['decimals'] + 1)
    c['yMax'] = round(hi + span * 0.3, c['decimals'] + 1)
Enter fullscreen mode Exit fullscreen mode

The padding matters. If the axis stopped exactly at the highest value, players could guess the ending from the shape of the empty space.

The hidden part of each chart never reaches the browser until you've played. The server sends only the visible points, so nobody can find the answer in the network tab.

Drawing a line with your finger

Drawing sounds simple until someone swipes fast. Pointer events don't fire for every pixel, so a quick swipe can skip several points on the chart and leave gaps in the line.

The fix is to fill every gap between the last point you touched and the current one:

const step = k > from ? 1 : -1;
for (let i = from + step; step > 0 ? i < k : i > k; i += step) {
  next[i] = fromValue! + ((v - fromValue!) * (i - from)) / (k - from);
}
next[k] = v;
Enter fullscreen mode Exit fullscreen mode

Now any swipe, however fast, produces a complete line. It works the same with a mouse or a finger, which matters on Reddit, since many people play on their phones.

The crowd line without storing every guess

The crowd's average is the best part of the reveal, and I didn't want it to get slower as more people played. Reading back every guess to average them would do exactly that.

Instead, each guess is converted to a position on the chart between 0 and 1, scaled to a whole number, and added to a running total in Redis:

for (let i = 0; i < guess.length; i++) {
  await redis.hIncrBy(keys.sums(day), String(i), toFraction(chart, guess[i]!));
}
await redis.incrBy(keys.count(day), 1);
Enter fullscreen mode Exit fullscreen mode

To draw the crowd line, the server divides each total by the number of players. It costs the same for 10 players or 10,000.

One guess per player per day is enforced the same way. The server increments a counter for that player and day, and only the first increment counts, so a double tap can't submit twice.

Scoring across millions and degrees

Scoring has to work for a chart in millions of people and a chart in degrees Celsius. So the error is measured as a share of the chart's height, not in the chart's own units:

const range = chart.yMax - chart.yMin;
let total = 0;
for (let i = 0; i < actual.length; i++) {
  total += Math.abs((guess[i] ?? chart.yMin) - actual[i]!) / range;
}
const meanError = total / actual.length;
return Math.max(0, Math.round(100 * (1 - meanError * 4)));
Enter fullscreen mode Exit fullscreen mode

That last line is why I scored 0. Missing by a quarter of the chart's height, on average, drops you to the floor. More on that below.

One new post every day

A daily game needs a daily post. Devvit has a built-in scheduler, so the app creates the day's post automatically just after midnight UTC. Each post remembers which chart it belongs to, so old posts stay playable.

One thing I didn't expect: Reddit held the app's posts until I approved them as the subreddit moderator. New app accounts don't have much history, so for now, checking the mod queue is part of the morning routine.

What day one showed

The first chart was mobile subscriptions in Kenya, from 1998 to 2024. Players saw the line up to 2007, the year M-PESA launched, and had to draw the rest.

Nine people played. The crowd's average line scored 82 out of 100. The best single player scored 79.

Trendline's day one reveal: the crowd's average line, in blue, tracks the real line closely
Day one: my guess in orange, the crowd's average in blue, and what happened in white. Player names are blurred.

Nobody beat the crowd.

I scored 35. I drew Kenya passing 160 subscriptions per 100 people. The real figure for 2024 was 126.5. The crowd's average landed closer than any one of us.

That's the idea behind the whole game, and seeing it happen on the very first day was the best possible start.

What I'd change

Then came day two, and my 0.

Trendline's day two reveal: my summer peak arrives two months before the real one
Day two: the right shape, two months early, and a score of 0.

My line had the right shape. The summer peak was there, it was just early. But the scoring compares each month separately, so an early peak counts as wrong twice: too high before the real peak, then too low when it arrives.

A score of 0 for a guess with the right pattern feels broken, especially for a first-time player. Scoring that rewards the shape of the line, not just the distance at each point, would be fairer.

Try it yourself

If you want to see how good your instincts are, play today's chart at r/TrendlineGame. It takes about 30 seconds and a free Reddit account.

If you want to build something similar, the full code is on GitHub. The two ideas worth borrowing are the running totals for the crowd average and keeping the answer on the server until the player commits.

What chart would you want to see next?

Top comments (0)