Excelling at DIVE via number theory

Excelling at DIVE via number theory

If you’ve been on the internet in 2022, you have probably encountered Wordle. And if you were on the internet in 2014, you probably encountered 2048. The stories of Wordle and 2048 are remarkably similar. One person takes a not-completely-original idea and gives it a fresh interface on a free website. The game is simple and accessible enough to garner a wide audience. At its core it captures a nugget of strategy and stirs a viral obsession. Some groups play the original religiously, while others rush toward spinoffs with creative twists on the core gameplay.

In 2014, I encountered a spinoff of 2048 called DIVE. I have played it frequently ever since, long after the hype around 2048 went away. If I need a silent, captivating distraction, chances are I’ll open the browser on my phone and play a bit. I’ve gotten quite good at the game. This post will talk about what it actually means to be good at DIVE, in excruciatingly nerdy detail. First though, an internet history lesson is in store.

Threes and 2048

Promotional image for Threes, the first puzzle game credited in most 2048 lore

In February 2014, Asher Vollmer published Threes, a number-sliding game on a 4 by 4 grid. The goal was to combine 1s with 2s to make 3s, and from there combine numbers with copies of themselves. Your moves cause every tile on the board to shift if possible, and tiles combine when pushed together. Each move spawns a new tile. Keep combining tiles and avoid running out of space, or it’s game over.

Early in a game of 2048

People liked Threes, and a few of them made their own versions. In March 2014, Gabriele Cirulli built 2048. (Sidenote, the original host site was https://gabrielecirulli.github.io/2048, which is now just a redirect. Part of the charm of the game may have been that the website name was so clearly just “a thing built by some guy”. The new host site is powered by ads, probably a better place to play it in the current year is https://2048masters.com/).

In addition to Threes, Cirulli cites inspiration from Saming and Veewo Studio who each built similar Threes clones based on powers of two. However, Cirulli’s 2048 is the one that took off.

The main difference between Threes and 2048 mechanically, is the absence of 1+2=3 as a first step. Each tile was instead a power of two, and 90% of the spawned tiles were 2. The other 10% were 4. Tiles combined with copies of themselves, allowing you to make larger and larger powers of two. This made it really easy to make progress, and was part of the appeal.

One other key difference came from the moves themselves. Instead of a single tile shift, a move in 2048 would effectively “drop” the board in the direction you moved, causing every tile to go as far as it possibly could. I think this made the combination step more intuitive.

My first encounter

I was in my 3rd year of college in 2014, and spent a lot of time in the computer lab. Come April, many of the students there would have a tab for 2048 open, and play it when their code was compiling. Not only would people get the stated goal of 2048, but they would keep playing to try to get 4096, 8192, and beyond. For the unscrupulous, we found that you could “duplicate tab” on some browsers to get a clone of the current game’s progress with an independent random seed, allowing you to effectively make a savestate for impossibly good luck.

Variants

Then came the variants. The simplest variant would just replace the powers of two by some other progression, like increasingly sexy images of Matt Bomer, or increasingly wacky doge gifs. Core gameplay was identical, save maybe the new challenge of stomaching “very matching”, “such points”, “wow” in neon letters each time you combined tiles.

The more complicated variants would actually modify gameplay. Evil 2048 used a heuristic to always find the least helpful way a new tile could spawn, changing the core strategy from statistical to deterministic, with the spawns being adversarial. 3D 2048 changed from a 4 by 4 grid to a 3 by 3 by 3 cube, with 6 different directions of motion. The amount of space being much larger at 27 tiles, this game could go on for a lot longer.

But 27 tiles pales in comparison to 64. A computer science program in Taiwan provided the world with 9007199254740992, an absurd 2048 variant with an 8 by 8 grid and the goal of reaching 253. I have to mention this variant specifically because I struck viral gold of my own by making a YouTube video about it. Behold one of those “the algorithm recommended me this video and it looked neat and was under a minute so I clicked” gems from 2014. The author is yours truly.

A video I made in 2014 that has gained over 40 million views (inexplicably, if you ask me). The quality is poor, and the gameplay is cheated. But it is still visually satisfying, and shows the “snake strategy” playing out as the longest snake in this cursed version of the game.

DIV

One evening in 2014, I opened yet another 2048 clone, this one called DIV. I was done with my work for the day, but my partner was working on a project and she was likely to be up for a while, so I hung out and played. This version seemed neat, since it let you get more exotic numbers on your board.

The premise of DIV was that you could combine any pair of tiles so long as one of them was a multiple of the other. Instead of matching like to like, DIV relaxed that criterion substantially. In fact, every tile in the original 2048 would be able to combine with every other tile. In exchange, you had to deal with randomly spawning 2s, 3s, 5s and 7s, as well as the consequences of your own decisions. Combined tiles would add, so a 32 and a 2 would make a 34. The death sentence in a DIV game was too many tiles that could only take one of 2, 3, 5 or 7.

DIV, the ugly precursor of DIVE

The idea was great, but the implementation was pretty janky. Tiles would get some color when the value on the tile was between 0 and 200, but after passing 200 they would stay black forever. Text for large values would spill over the edge of the tile. Every time you combined a + b = c, you would earn c points. This meant that you could farm a single large tile and get its value dozens of times with small additions, which kind of broke the scoring system. (sound familiar?)

I made it through exactly one game of DIV that night, over the course of a few hours. I saved a handful of screenshots to track my progress. The end of the game is shown below, with a score of 432,753.

I dug an 8 year old screenshot out of an external hard drive for this blog post. You’re welcome.

DIVE with an E

I wasn’t the only one to see potential in DIV. Enter Alex Fink, a London math professor (or technically a Reader, a distinction which only matters in the UK.. where it would also be called maths..)

Fink, with the help of some colleagues, built his own version of DIV. He named it DIVE. Here I will apologize to anyone who has been reading it like the English word dive. The official pronunciation of DIVE /dɪv/, rhymes with “give”.

Alex Fink’s DIVE provided several major improvements from its precursor.

Seeds

Three different ways to play, but we will only focus on the bottom option: any “prime” factor of a tile on the board now

There are three different ways to play, differing from each other on what can spawn, or as the site calls them, “seeds”. One option is the 2, 3, 5, 7 of DIV. The other two options are much more chaotic. After every move you make, the game will look at all the new tiles, and divide them by the existing seeds where possible. If you get to something that isn’t 1, then you have unlocked a new prime! Or at least, pseudoprime.

In the middle mode, these unlocked seeds stick around forever. So once you have taught the game that 3 exists, it won’t ever forget. But in the final mode, which is also the default and the one I will focus on exclusively in the rest of this post, you can “eliminate” seeds by removing all multiples of that seed from the board. In the example below, I make a 9 and there is no longer any tile on the board which is a multiple of 2. Then when I make a 12, since the only seed is a 3, the game divides by all the 3s that it can, and determines that 4 is the new “prime”. Then later, because I make a 6 which isn’t divisible by 4, the game determines that I have unlocked 2.

Unlocking and eliminating seeds, and showing how “prime” deserved to be in quotation marks after all

To be clear on the order of operations: seeds are recomputed before one of them spawns. After your move, the game first checks for eliminating or unlocking seeds, then selects one uniformly randomly from the options and puts it in a random open tile on the board.

Color and Texture

You may have noticed the background colors on the tiles follow a pattern. You might also have noticed at the start of the game, the tile background on the initial score of 0 is completely crazy.

There is a rule in DIVE that allows every tile to have a descriptive background. From math, every number has a unique prime factorization. In DIVE, those factors are converted to textures, and those textures blend together.

2, 3, and 5 are red, green and blue. Higher powers get higher intensity. The 2048 tile would be a dazzling bright red, while 243 is a neon green. As a mix of several 2s and 3s, 72 is a rich yellow (the mixture of red and green light). 2, 3 and 5 are the only primes to be given entire colors, but every prime between 7 and 367 gets a texture. The textures are diagonal or radial stripes. In the example game below, I try to demonstrate a variety of textures. Of course, the most textures on a single tile happens with the number 0 – a clean multiple of everything!

Note that 271, the largest seed I unlock, has the most detailed texture. This is generally true – larger number means smaller feature size in the texture.

Sadly, the textures eventually do run out. Primes larger than 367 are indistinguishable colorless blocks. Still, the textures that are included are enough to very quickly figure out the small primes dividing a certain number, even if that number is very large. For example, a glance immediately tells me that 2167 is divisible by 11, because of the circular ring of white. And in general, it’s very easy to tell in the image below what tile is divisible by what seeds.

By design, the different textures are there to make it easy to tell “at a glance” what divides what.

Aside: Synesthesia

Synesthesia is a neurological and perceptual phenomenon where a person will experience an extra sense corresponding with a normal stimulus. The obvious example here is when reading a number, some people will see associated colors or textures. A former classmate of mine talked about how when given a worksheet with a hundred different calculations on it, she was overwhelmed by the cacophony of color on the page. In her brain, the signals that helped her process a number as a number, shared neurons, electricity, something, with the signals that perceived color.

This is somewhat uncommon, but when it does happen it serves as both a blessing and a curse. I don’t claim to have synesthesia, but due to the time spent on DIVE and the consistent association of prime factors with a texture or color, I have a pretty definite mapping of number to color now. It’s far more contextual than stories I have heard from people with synesthesia, I would have to imagine the number on a tile in order for it to get its color.

From correspondence with Alex Fink, he shared the following:

I’m particularly tickled that you like the colour / texture scheme; I spent a while thinking about how to make that relieve the mental burden of factorisation and otherwise feel right.  The highest praise I ever got on that was from a synaesthete friend who said that my scheme had overwritten their colour-number assignments.

Alex Fink, creator of DIVE

So, what is a good score in DIVE?

DIVE has no fundamental maximum score like 2048. There is always the vanishingly small chance that every single time you move, the new seed it picks will combine with the tile next to it. But that doesn’t actually happen. Instead, the limits to the game are statistical.

I like to look at percentiles when considering DIVE scores. If you play a thousand games of DIVE, what are:

  • The score you beat 50% of the time (50th percentile, your 500th best game)
  • The score you beat 10% of the time (90th percentile, your 100th best game)
  • The score you beat 1% of the time (99th percentile, your 10th best game)
  • The score you beat 0.1% of the time (99.9th percentile, your high score)

This allows most of the randomness to disappear into noise, and really highlights the true signal of skill.

My Scores

My highest score is 718,184. This a legitimate score in the version of DIVE available at alexfink’s github, using the default spawn rule of “any ‘prime’ factor of a tile on the board now”. This is probably also the world record – I’ve met a few communities of avid players and nobody has reported a higher score.

But that isn’t to say that I can get anywhere near that score every time. I made a plan when writing this blog post, to record all of the games of DIVE I played until I got a game scoring over 100,000 points. This took me 676 games, so the 100k barrier is somewhere around the 99.8th to 99.9th percentile.

In so doing, I also determined that my 99th percentile is 30103, my 90th percentile is 8536, and my 50th percentile is 1552. The distribution falls off heavily, though to my credit I gave up on most of the games that got super unlucky early on and didn’t try to maximize their score. My 50th percentile would be modestly higher if I was optimizing for “average score” instead of for “time to next 100k”.

It may be discouraging to start out at the game, and be barely able to scrape out 1000 points in a lucky game. The largest area of improvement tends to be keeping control over the board state. So that is where we will start.

How to actually play DIVE

Big numbers and where to put them

Fans of 2048 may be familiar with building into a corner – keep your highest tile in the corner of the board. The complete opposite is true here. There’s a good reason for this!

In 2048, the high tile is the one with the least activity. All your routine combinations are 2+2=4, 4+4=8. There’s no benefit to putting your big tile in the open, it’s just a rock that won’t combine with anything. But in DIVE, you want to be able to combine with your highest tile frequently. And thanks to the rules of the game, you can!

There isn’t any score cheesing here, DIVE was aware enough of the “a + b = c awards c points” issue in DIV to modify that. Instead a + b = c now awards min(a, b) points, which you can reason out makes a much more sensible score scale. But even then, the high tile is often the most valuable player in the game, and you want it available.

Correct predictions

Since most 2048 players are not used to moving the entire board so frequently, this is uncharted territory. Combine that with DIVE’s mathy combination rules, and it’s very easy to mispredict what a move will do. With some practice it comes naturally. One key thing to remember: if three tiles are all pushed together and could pairwise combine, the ones that get combined are the pair further in the direction moved.

The 3 in the middle left could combine with either the 3 below it, or the 24 above it. When you move, it starts with the tiles closer to the destination. So a move down would combine 3 + 3, while a move up would combine 3 + 24. This sort of situation comes up incredibly often so I’m calling it out as the most important thing to predict correctly.

What do I want to combine?

In a good game, your highest tile is almost always a small multiple of your highest seed. The big points come when that seed spawns, and you combine it with the high tile. Ideally it takes as few moves as possible to make that happen. In the example below, I unlock 41 as a seed, and work to keep all my multiples of 41 in the open. This lets me combine them up to 41 x 10, garnering a few hundred points in the process.

Notice in this game, that once 41 exists, its value is rather arbitrary. The game could play identically if instead of making 82, we magically made 8002, and all the 41s afterward were replaced by 4001. The gameplay here shows how we keep one large tile available to score every time the big seed spawns.

Seed profile

To thrive in DIVE’s default ruleset, you need to play a specific metagame. Your primary goal needs to be to force the seed selection to be favorable. You can’t control the game’s internal random number generator. But you can work to make sure that each option that it could deal out, is kind to your board.

To that end, fewer seeds is always better. With fewer possible spawns, you can make better accommodations for each. Usually 2, 3, 5 and 7 are hard to avoid, so I would say the right number of seeds is 4 or 5. As the example gameplay above shows, this is not unreasonable to expect.

Value added

Much like 2048, the total sum of all tile values on the board before and after a move is unchanged. The only way that the sum goes up, is when something spawns. If you are spawning larger numbers, you are gaining value (and thus potential score) more quickly, and will be more likely to reach extremely high scores before getting a bad spawn sequence.

Balancing this with the previous section, you want exactly one large seed, and for the others to be small and manageable. The expected value added per spawn gets higher in two ways:

  • Eliminate one of your small seeds, increasing the chance the large one spawns.
  • Eliminate your large seed in favor of a larger seed.
A real screenshot from a game where I ended up scoring over 100,000 points.

We will get to large seed optimization soon, but first I want to talk about one more crucial concept for keeping things under control.

Safe neighbors

If you taught a computer to play the game, it would calculate several moves out into the future, and try to figure out the best way to end up with a good board. But as humans, we want to avoid calculating many moves ahead. The game is mathy enough with only one move at a time. So “safe neighbors” is a heuristic that replaces a lot of calculation, by a much more intuitive concept.

Safe neighbors are tiles which don’t combine with each other, but after adding one of the seeds to one of them, do combine (without bad consequences).

A good example is 22 and 55. If you have these tiles on your board, then you probably have 11 as a seed. Line them up next to each other. This accomplishes two things:

  • You have a little bit more control over which row or column other tiles fall into
  • When an 11 spawns, you can combine it with 55 to get 66, and then consume the 22 to get 88

Safe neighbors act as structure but will combine cleanly after a tiny change. An example from the video above would be 22 and 48 along the top row. 48 is a tricky tile to build next to, because it can so easily pick up a 3 and grow to 51, unlocking 17 which I don’t want. So I made the 22 next to it, allowing it to stay fixed in place, but with the intention to later make that 22 into a 24.

This is my best attempt to explain the delicate balance between “too many tiles is death”, and “too few tiles will make me unlock bad seeds”. It’s almost entirely intuition to me, so I probably didn’t do the concept justice, but hopefully with all the videos to follow, the concept will be shown in action some more times.

So now we’ve talked about movement strategy, and hinted toward meta strategy. Let’s dive into the number theory of DIVE. Let’s get some big numbers on the board.

Number Theory

Number theory is a branch of mathematics that looks for relationships among the integers. That’s a super broad categorization, so concrete examples would be things like:

  • Prime numbers and prime factorization
  • Behavior of integer sequences in the infinite limit
  • Equations with solutions constrained to be integers

Number theory is a strange beast – so many of the topics feel at first like you already learned about them while very young. Of course you know what a prime number is, it’s a number with no divisors besides itself and 1. But the process of actually proving things in number theory takes you on a wild journey. For example, the Prime Number Theorem is a statement about how frequently prime numbers show up as you look at larger and larger values.

As a statement, it requires only knowledge of primes, the natural logarithm, and limits. But the current “short” proof for this involves the Reimann Zeta function, which uses complex variables and holomorphic extensions, things you learn deep into higher level mathematics.

Practical number theory

I guess we are lucky in DIVE. We don’t need to consider primes all the way out to infinity, in any real game. However, we would like to be able to say for any given seed, whether having that seed unlocked is a good or bad thing. And we will do this using a bit of number theory.

Let’s start from the basics of DIVE. We have a tile with some number N on it. N has divisors, let’s pick a random one and call it d. If you combine N with d, the new tile N + d is still divisible by d. But that isn’t exciting, because d was already on the board. The other factor is the interesting one: 1 + N/d. We know it is an integer because d is a divisor of N.

1 + N/d is the factor responsible for unlocking or eliminating seeds.

Examples

  • Your very first combination in the game: 2 + 2 = 4
    • N = 2, and d = 2, so d is a divisor of N (trivially).
    • When you make 4, you have the old factor 2
    • The new factor 1 + (2/2), is also just 2 so nothing gets unlocked.
  • If you combine 80 and 2, like in the video above
    • N = 80 and d = 2
    • N + d = 82 which remains a multiple of 2
    • The new factor is 1 + (80/2) = 41, a new prime that gets unlocked.
  • If you combine 2167 with 11, which was possible in the screenshot much earlier
    • N = 2167 and d = 11 (the textures can confirm that 2167 is 11 x 197)
    • N + d = 2178, which is still a multiple of 11
    • The new factor is 1 + (2167/11) = 198, which is divisible by 2, 3, and 11. If those were all already seeds, nothing new would be unlocked. But 197 might be eliminated.

This might all be obvious math, but there is something important that will be true in every case. You take some factor of N, and you replace it by that factor plus 1. No matter what two numbers you actually are combining, there is a lens through which you are simply adding 1. And so the real question to ask, is:

What can we say about the factors of a number k + 1, based on the factors of k?

This is starting to resemble several core number theory questions. First, k and k+1 can never have any factors in common. To see this, consider that any divisor of k and k+1 also divides their difference, which is just 1. So, no number greater than 1 exists that divides them both.

Now, knowing that they have different sets of factors, we can ask other questions. Is it possible for the factors in k and k+1 to all be small? Suddenly we have entered a famous area of number theory: the abc conjecture.

The abc conjecture

Put simply, the abc conjecture says that when you take three numbers with no factors in common, satisfying a + b = c, then the distinct primes in each of them will never multiply together to something “much” smaller than c. In other words, to make the result large, you need some large prime factors in at least one of the three values.

If you take a = 1, then you get an important implication for DIVE. The prime factors in either b or c will eventually need to be large.

A couple caveats though:

  • “much” is in significant quotation marks, because the conjecture actually uses an infinite limit, which allows for a finite number of exceptions. How much smaller those exceptions are allowed to be, is part of a stronger and more difficult-to-articulate version of the conjecture.
  • Whether or not the abc conjecture is proven, is one of the weirdest pieces of academic drama I have read in a while. Suffice to say that a proof published by Mochizuki in Japan is treated within Japan as correct, but not recognized by many other countries, partly due to the complete new mathematical framework that Mochizuki had to build to prove it. If there are flaws with the reasoning (which many believe there are), then the proof is either incomplete, or worse, useless.

A nifty list

Fortunately, we can just turn to a computer and crank out all the examples of adjacent numbers with no large factors. Here I’ll treat 7 as the largest allowable prime factor.

kk+1factors of kfactors of k+1
2323
3432*2
452*25
5652*3
672*37
7872*2*2
892*2*23*3
9103*32*5
14152*73*5
15163*52*2*2*2
20212*2*53*7
24252*2*2*35*5
27283*3*32*2*7
35365*72*2*3*3
48492*2*2*2*37*7
49507*72*5*5
63643*3*72*2*2*2*2*2
80812*2*2*2*53*3*3*3
1251265*5*52*3*3*7
2242252*2*2*2*2*73*3*5*5
240024012*2*2*2*2*3*5*57*7*7*7
437443752*3*3*3*3*3*3*35*5*5*5*7

As far as humanity has determined, this is the entire list. There are not any more known pairs, and finding one would mean an enormous outlier in a rather statistically sound list of abc triples. You could go higher and allow 11 or 13 in your factors and get slightly bigger values like 10647, 10648. But the conjecture spells diminishing returns. You just can’t make k very big without needing to confront large primes in either k, or k+1.

In context

As a reminder, we are combining tiles which have k as a factor, and not the tile k itself. So when trying to determine how to stay clean when combining with an arbitrary tile, look for the largest divisor on the left, and add the other factor.

For example, we might have a 441 tile, which is 63 x 7. Combine a 7 to make 63 go to 64, and you get 448, which is 224 x 2. 224 is also on the k side of the list, so adding 2 makes 224 go to 225. The furthest down the list we get with 450 is 15 x 30, so we would need to add 30 to stay clean, which begins to be a tall order. But from there we could view 480 as 48 x 10 and add 10. 490 as 49 x 10 and add 10 again. 500 as 125 x 4 and add 4. 504 as 63 x 8 and add 8, and so on.

The climb in DIVE can always keep going. It just might require building large and precise values, which is hard to do. There are so many ways to end up forced to combine things you don’t want to. (This is part of the reason that the less popular mode where seeds are unlocked forever, is insanely difficult).

So let’s start looking at larger primes.

Climbing the Primes

As a reminder, a good seed profile is allowed to have one big seed. A massive number that, when it spawns, showers your board with points and makes your big tile even bigger.

Let’s say the big seed is a prime p, and your large tile is a small multiple of p. Let’s also assume that you’ve cleaned up enough, that the single large tile is the only multiple of p on the board. This means you could eliminate p as a seed, by changing the large tile. An example board with this property is below.

k = p

The pictured board is in position to combine 2 with 1874 in two moves. Assuming another 937 doesn’t spawn, this would eliminate 937. But is that a good idea?

When k is a large prime, k+1 will be even. So, the factors of k+1 will be smaller than k. Usually you want to avoid this. For primes like 29, this can be ok. If you take the d-th multiple of 29 and add d to it, the result is divisible by 30, and 30 has only “safe” factors. But as many new players quickly learn, primes like 37 are not nearly as kind. Bumping a factor 37 up to 38 will cause you to unlock 19, which is the perfect mix of annoying and useless.

In the case above, it would unlock 469, which is a composite seed divisible by 7. This will pose an issue if I then unlock 7, because my large value will be harder to keep away from accidental combinations. Additionally, the new seed is smaller than 937, which makes it counterproductive to switch.

So, what if k is a multiple of a large prime?

k = 2p

This is the crux of the simplest way of gaining exponential points. When you have some prime p, and 2p+1 is also prime, you can eliminate p while unlocking 2p+1. Now, your big seed spawns will carry twice the points, and allow you to grow your big tile twice as fast. With clean play, you might be able to unlock 2(2p+1)+1, and beyond.

Some extremely useful 2p+1 chains in DIVE are:

  • 41, 83, 167
  • 89, 179, 359, 719, 1419, 2879
  • 509, 1019, 2039, 4079

Below is an example game climbing the 89 chain (to mixed success). Notice how when I upgrade the seed, I am using a divisor that is half of the ratio tile/seed. That is what makes k = 2p.

k = 3p, 4p

You can get significantly better chains if you allow other small multiples of primes. 3p+1 will be even, and so the prime you get from it will be around 1.5 times larger than p, but that’s still potentially exponential growth.

I ran a computer program to find extremely long chains allowing for 3p+1 or 4p+1. The longest it found starting under 1000, is:

593, 1187, 1583, 3167, 4751, 7127, 10691, 21383, 42767, 64151

The program also determined that you can enter the 89 chain earlier, as 29, 59, 89. You can get into the 509 chain from 127. Finally, you can extend the 167 chain to 251 and 503. These are ways to use 3p+1 and 4p+1 to make the most useful chains in the game, even more accessible.

Composite seeds that are effectively prime

Composite seeds don’t always help in DIVE. However, when it comes time to consider these exponentially growing chains, they are a fantastic tool. If you can guarantee that your seeds are 2, 3, 5, 7 and one big one, then it doesn’t really matter whether the big seed is actually the product of two large-ish primes. A great example is 299. This is 23 x 13, but if you don’t have either of them unlocked when you upgrade 149, then 299 is effectively a prime.

With composites available as long as they are not divisible by 2, 3, 5 or 7, then suddenly there are many chains that go on for a very long time. For example, I was able to find a chain connecting 3989, which is 2 x 3 x 5 x 7 x 19 – 1, to 19084046309 = 2 x 315 x 5 x 7 x 19 – 1. Every step is either 2p+1 or a 3p+1, and every number is either prime, or composite with smallest prime factor greater than 50.

We aren’t at the level where anyone will ever unlock 19084046309 as a seed. But it’s fun to think about this number theory.

Graphs

I am pretty well versed in the Wolfram language, which provides nice graph visualizations. So, I built a way to visualize these chains. Vertices in the graph are seeds, and an arrow connects two seeds if you can reach one from the other as 2p+1, or optionally higher multiples. The seed is colored gray if it is prime, and red if it is composite. You can configure what to allow as the smallest factor of non-primes. The label on the edge is the smallest multiple you need, to unlock the next seed.

A graph showing ways to escalate from a 29 seed to larger seeds. The topmost edge means that 29 can be used to unlock 59, by making 4*29 = 116 and then adding 2 to get 118, unlocking 59. Similarly, 59*6 + 2 = 356, which unlocks 89, etc. Red nodes are not prime, but have no small prime factors.

In the notebook, I also allow “green edges”. These are paths where you first eliminate the large seed, but don’t unlock anything new right away. You might have just combined 1438 with 2 and made a 1440 tile. That would eliminate 719, but you don’t unlock a new seed until you make another addition to the 1440 tile. Since this is realistic to happen in a game, it’s a separate way for a seed to scale. Enabling green edges, we get much busier graphs.

Green edges involve first eliminating the seed with one merge, and unlocking the next seed with another. For example, 83 connects to 251 because 83*6 is 498, add 2 to get 500 which has only small factors, and add 2 again to get 502 which unlocks 251. The exact chain of additions is sometimes too complicated to display on one edge (e.g. 83 to 151 involves 415+5+21+7+2+3). The notebook linked above has all the customization options I could manage, to improve this.

I heavily encourage anyone interested, to play around with the notebook yourself, make a copy and tweak the numbers. The graphs tell an incredible story of number theory and interconnected primes.

When all goes wrong

Clearly all of this strategy can be foiled by a bunch of bad spawns in a row. In recording games for this blog post, I discarded many failures.

When the game inevitably becomes too chaotic to continue cleanly, I do something that I call “cashing out”. I take my biggest tile, with no regard for eliminating any seeds, and use it to unlock the biggest seed possible. That way, even if my game is on its way out, I have a chance to get a few lucky spawns for high value before it ends.

It’s sometimes possible to recover from chaos. I’ve had times where in the process of cashing out, I realize that I’ve had unusually good luck and am able to steer it back to a small number of seeds. I’ve also had times where I probably should have cashed out, but was stubbornly insistent that I could clean it up, and the game died uneventfully.

Summary of strategy

  • Keep your most active tiles on the part of the board facing the empty space, so that they can combine with spawns
  • Use ‘safe neighbors’ to help with alignment while providing quick collapse down to a small number of tiles when needed
  • Unlock large seeds by combining 2 or other small tiles, with something big
  • Composite seeds are ok if you don’t expect to also unlock their factors
  • Plan ahead when looking for large seeds, based on whether that seed scales well with np + 1 tactics
  • When trying to get/remain clean, keep the nifty list of abc triples with a = 1, in mind
  • If all seems lost, cash out

DIVE is hard, but between the movement techniques and the number theory techniques, there is an enormous skill ceiling. So a natural question might be, how far are we from the limits?

A pretty basic AI

I did build an AI for DIVE a few years ago. You can find it at https://github.com/biggiemac42/diveAI, but be warned it isn’t really designed for ease of use. Instead of interacting with the game in a browser, I reimplemented it with a basic ASCII display in the terminal. I only really wanted to focus on the lookahead and the strategy.

With a 4 move lookahead and a decent game state evaluation function, the AI can get a better average score than me, with 10,000 points being a typical game. The evaluation function isn’t even looking at np + 1 tactics, it simply wants to make its big seed big and is rewarded for keeping all other seeds small.

But where the AI truly shines, is when you turn lookahead down and let it play games as fast as it can.

Data galore

When I last played around with it, the AI was able to play millions of games in a day, and would change its lookahead dynamically based on its score. For most of the time, it was playing at “depth 0” which didn’t look at any possible random spawns, just greedily tried to analyze how much it could achieve with two moves of its own, before doing the first. On games where that panned out nicely, it would start to consider random spawns, first one (move spawn move move) and then two (move spawn move spawn move move). The distribution (log-log plot) of “how often do we get exactly this score” vs score for 90 million test games is shown below.

An old graph that I shared with Alex Fink when I was working on the AI. The y axis demonstrates probability of getting the corresponding score on the x axis. The shaded regions correspond to when the improved lookahead would kick in. The AI only spent significant “thinking time” on games that already reached a high score.

Really I should have made this graph with the probability of getting or exceeding the target score, since as written, higher scores are at a disadvantage because there are more numbers in that range. That accounts for 3 of the nearly 8 orders of magnitude difference between 1000 and 1 million point games. But I don’t know where I would find the original data, and don’t want to rerun the nearly 100 million games that went into this graph.

Highlight game

The AI has indeed scored over 20 million in a game of DIVE.

I have to include a couple caveats here.. Obviously this is not the browser game. It’s in a terminal, without the nice textures. But the gameplay is a full recreation of Fink’s DIVE, and the random number generator behaves the same at a statistical level (the AI isn’t trying to “game” the RNG).

When I first wrote the AI I literally didn’t know that you got points when you eliminated a seed. So the score displayed in the video below, undersells it a bit. Counting eliminated seeds, I recomputed it as 28,444,567 later, which is the value in the graph before.

The speed of play here is a constant value, because this is a replay. I had the AI save a text file with all the information needed to reconstruct a game, whenever it scored over a million. In the actual game when this was played “live”, the first hundred thousand points might have gone by in a second. After that point, the deeper lookahead kicked in and it would have taken a few seconds per move.

My own 676 game adventure

I find it funny that the “Human record” 3 years ago when I was playing with the AI, was only 232,533. Part of the reason it’s funny, is that I beat it outright when trying to record games for this post. This is the best game of the grind, and the only game over 100,000 points. But it makes it a significant distance past that barrier, with a score of 265,936.

Honorable mentions

If you want to watch a few more remarkable DIVE games, here are scores #2 and #3, at 87884 and 61175 respectively.

Random good-not-great game

Or if you’re someone who wants to see a representative game, and not only the cream of the crop, I picked a random game out of the mix. This scores 2350 points, and is slightly rare in that I played it all the way to game over. Many of the games I just reset the window before game over, due to some bad spawn or generally bad board state.

Screenshots

Finally, a couple of nice moments from games, captured as screenshots.

Combining two highly composite numbers with each other (and then with 36 shortly after)
Combining 1024 and 3072 to make 4096. Powers of two, but leapfrogging the iconic 2048
A moment with 343 as a seed, the third power of 7. There are many more interesting seed moments but it’s hard to find them if I didn’t save them during the game.

I would love to go through with a video scraper and answer some other questions. For example, what is the smallest seed I never unlocked in any of these games, counting composites? Not counting composites? What is the smallest number I never had on my board? What is the composite seed I unlocked with the most divisors? How many tiles did I have on my board on average? How many moves did the game last on average?

If anyone wants to help write something to analyze 22 hours of DIVE gameplay, hit me up. I can supply a lot of excellent footage.

Closing Remarks

I’ve thought about DIVE a lot, and I have to thank Alex Fink immensely for unleashing it on the world in this form. But I don’t know if I’m the furthest into this rabbit hole. I’ve met a few others, with comparable skill, along with many others who aspire to improve.

One of the best possible things I could learn when publishing this post, is that someone out there is actually better than me at DIVE and has already gotten the million point human game. It’s possible, since this isn’t a game that directly encourages people to connect with each other. With any luck, this post will change that trend. Feel free to reply in the comments with your high scores and progress!