Daily puzzle seed from date: a 35-day repeat
My daily challenge hashed the date to pick one of 365 puzzles. In 2026 it played 277 of them and repeated one after 35 days. The fix, and what switching cost.
Contents
The daily challenge in ASMR Logo Craft Block picks one puzzle a day out of a pool of 365. The day's puzzle came from a hash of the date string, taken modulo 365. Same date, same puzzle, on every phone, with no server. It is the standard answer to "how do I get a daily puzzle seed from the date", and it looks like a rotation through the pool.
It is not one. In 2026 that hash plays only 277 of the 365 puzzles, never deals the other 88, and hands 2026-03-06 the same puzzle as 2026-01-30 — 35 days apart. A player who plays every day gets a "new" daily they already solved, five weeks later.
The code
A simplified version of what shipped. The hash is the usual 31-multiplier string hash, the
one Java uses for String.hashCode:
// simplified: the day is a 'YYYY-MM-DD' string in the player's local time
function puzzleFor(day) {
let h = 0;
for (let i = 0; i < day.length; i++) {
h = ((h << 5) - h) + day.charCodeAt(i); // h * 31 + c
h &= h; // keep it a 32-bit int
}
return Math.abs(h) % 365;
}
Nothing in that is wrong as a hash. It is deterministic, it is the same in every time zone because it only reads the string, and it spreads strings out well enough for a hash table. The mistake is asking it to do something else: visit every slot once before visiting any twice.
The test that found it
I ran a bug hunt over the game with Claude Code, and the rule for every finding was a repro test that fails on the current code. This one is short. Walk every day of 2026 and 2027, map each to a puzzle, and expect nothing to come back within 365 days:
days 730 distinct 337 repeats within a year 342 smallest gaps [
{ day: '2026-03-06', idx: 32, sameAs: '2026-01-30', gap: 35 },
{ day: '2026-03-07', idx: 33, sameAs: '2026-01-31', gap: 35 },
{ day: '2027-03-06', idx: 8, sameAs: '2027-01-30', gap: 35 },
{ day: '2027-03-07', idx: 9, sameAs: '2027-01-31', gap: 35 },
{ day: '2026-10-05', idx: 154, sameAs: '2026-08-30', gap: 36 },
...
]
× no daily puzzle repeats within a year of days
730 days, 337 distinct puzzles, 342 repeats less than a year apart. Taking 2026 alone: 365 days, 277 puzzles, 88 never played. 2027 comes out the same, 277. A second test checked that the 365 puzzles themselves are all different, so the repeats are the date mapping and nothing else.
The test costs nothing to write, because the mapping is pure. It takes a date string and returns a number, so a year of it is a loop. This is the same argument I made for generating levels offline: content you can enumerate before shipping is content you can check before shipping, and a date-to-puzzle function is content in that sense. I had never enumerated it.
Why a string hash makes runs
The numbers printed next to each date show what is going on. Consecutive days get consecutive puzzles:
| Date | Puzzle |
|---|---|
| 2026-01-28 | 9 |
| 2026-01-29 | 10 |
| 2026-01-30 | 32 |
| 2026-01-31 | 33 |
| 2026-02-01 | 166 |
| 2026-03-05 | 31 |
| 2026-03-06 | 32 |
| 2026-03-07 | 33 |
The last character is added with a weight of 1, so going from 28 to 29 in the units digit
moves the hash by one, and every ordinary next day is the next puzzle. The tens digit carries
a weight of 31, so rolling from 29 to 30 jumps by 31 − 9 = 22: puzzle 10 to puzzle 32. A new
month changes a character with a weight of 31³ and lands somewhere else entirely.
So the year is a set of short runs, each starting wherever the month and tens digit put it, and nothing stops two runs from overlapping. January 30 and March 6 differ in three characters. Those differences add up to 2 × 31³ − 3 × 31 + 6 = 59,495, which is exactly 163 × 365. Modulo 365 that is zero, and the two days get the same puzzle. March 6 and 7 replay January 30 and 31, five weeks later.
A good hash would not fix this either. Pick 365 values at random from 365 slots and you still miss about a third of them. Hashing gives you "the same answer for the same input", which is what a seed needs. A rotation needs "every answer once", and that is a different property.
How to pick the daily puzzle from the date
Count days. Whole days since a fixed start date, plus an offset, modulo the pool size:
// simplified
const START = '2026-11-01';
const OFFSET = 16;
const daysBetween = (from, to) => {
const utc = (d) => Date.UTC(+d.slice(0, 4), +d.slice(5, 7) - 1, +d.slice(8, 10));
return Math.round((utc(to) - utc(from)) / 86_400_000);
};
const rotationIndex = (day) => (daysBetween(START, day) + OFFSET) % 365;
Every puzzle comes up once, in a fixed order, before any comes back. The day is still the
player's local YYYY-MM-DD; the arithmetic converts both ends with Date.UTC, so a
daylight-saving change cannot turn one day into 23 or 25 hours and push the count off by
one. There is a test that runs the same date under Pacific/Kiritimati and America/Adak
and expects the same puzzle.
A fixed order does not mean a visible one. Each puzzle here is dealt from its own seed, built from its index, so puzzle 32 and puzzle 33 are two separate random deals and a player has no sequence to notice.
Switching without changing anyone's today
Replacing the function outright is the obvious fix, and it is a data migration in disguise. I measured what that would do on update day:
- The old and new mappings agreed on 0 of the next 365 days, so today's puzzle changed for every player the moment the update installed.
- A daily in progress was lost. A saved board is checked against the puzzle it was dealt from, and the puzzle's identity changed under it.
- A daily already finished today was safe, because completion is recorded by date.
- A puzzle a player had seen under the hash could come back as soon as 31 days after the switch.
So the fix keeps the hash for every day before a cutover date and counts days from that date on:
// simplified
function puzzleFor(day) {
if (day >= START) return rotationIndex(day);
return oldHashIndex(day); // unchanged, so no past day changes
}
String comparison works on YYYY-MM-DD, which is one reason to keep the day in that form.
Every player crosses the cutover at their own local midnight, so nobody's puzzle changes
while they are playing it.
The offset is there for the seam. Right after the switch, the rotation starts dealing puzzles the hash played recently, unless it starts somewhere the hash has not been lately. A script tried every offset from 0 to 364 for four candidate dates and kept the one whose closest repeat across the switch was furthest away:
| Cutover | Best offset | Closest repeat across the switch |
|---|---|---|
| 2026-10-20 | 16 | 126 days |
| 2026-11-01 | 16 | 138 days |
| 2026-12-01 | 244 | 135 days |
| 2027-01-01 | 104 | 138 days |
I took 2026-11-01 with offset 16: the same 138 days as the new year, two months sooner. An earlier measurement, against 2027-01-01, put the closest repeat at 58 days with the count starting at offset 0. Searching the offsets more than doubled it.
The tests that hold it
Three, all on the pure function:
- From the cutover on, no puzzle comes back within 365 days, over two full years, and the first 365 days use all 365 puzzles.
- Days before the cutover map as they did. 2026-01-30 is still puzzle 32 — the bug stays in the past, on purpose. Nothing from the year before the switch comes back within 138 days of it.
- The mapping is the same in the two time zones above, near opposite ends of the clock.
The second one is the test I would have skipped. Without it, a later cleanup that "simplifies" the function down to the rotation alone would rewrite a year of past dailies and pass every other test.
What I did not test
Whether any player noticed. I do not know, and how many players it touched is not something these tests can say. What the test proves is narrower: on the old code, a player who played every day of 2026 would have met the same puzzle twice, with five weeks between them.
I also did not test a device crossing the cutover at midnight. The time-zone test covers the arithmetic; the switch itself is one string comparison on the same local date the game already used.
Takeaway
A hash of the date is a seed. It gives you the same puzzle for the same day and promises nothing about how often a daily challenge repeats. If the requirement is "each puzzle once a year", count days from a fixed date, and write the test that walks every day of the year — it is a dozen lines, and mine failed on the code that had shipped.
If the old mapping has already shipped, do not replace it. Keep it for the past, start the count at a future midnight, and pick the offset by measuring the seam.