Consider an image, fully-detailed, perfectly square, but initially represented as but a single, uniform pixel, the average of all of its contents. Naturally, one would wish to see more - more details, more pixels, more depth, but receiving all of this information instantaneously, perfectly, can be so... boring.
Instead, let us explore the image, piece by piece, quadrant by quadrant. The first pixel is given to us for free, and to see more, we must explore it - digging deeper, one 'pixel' may be split into four, each being the average of the top-left, top-right, bottom-left, and bottom-right subspaces it covers respectively, all equal in size. Each of these, we may then, in turn, explore, revealing more and more detail as we go, until the pixels revealed are, in fact, pixels, yielding no further detail than themselves.
In this way, what was once a fixed, linear journey - row by row, column by column - has become something much richer! There are many different ways one could reveal the full landscape, many different paths one could take to reveal each detail. For a image, or a image, there is but one way forward, but for a image, there are ways to reveal everything! One touch on the center to reveal distinct 'pixels', which can, of course, be explored in different orders to reveal the entire contents of the landscape. However, this number gets much richer, very quickly.
A image can be fully explored in ways. That's right, over quadrillion paths can be taken.
Let be the number of ways a landscape can be fully explored. The number has over three-hundred thousand decimal digits, so calculating it is no mere pencil-and-paper operation.
What is the digit-sum of ?
Inspired by this class of interactive animation .
(Took me a while to find a link! Hard to search for, these were somewhat popular a couple years ago.)
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
It is impossible to approach this problem without both a healthy knowledge of combinatorics, and an arbitrary-size-integer programming language at your disposal. Even with these, some memoization tactics, and well-structured recursion, go a long way.
It's clear from the problem statement that the function we're considering here is absolutely explosive, so any approach which computes it linearly, or even in polynomial time, is likely to take far too long. We need to identify a succinct, recursive relationship that defines the number we're looking for.
Let f ( n ) be the number of ways there are to fully explore an image of size 2 n × 2 n . We seek the digit-sum of f ( 9 ) , and to get that, we'll need to compute f ( 9 ) . We'll set f ( 0 ) = 1 and f ( 1 ) = 1 as our base-cases, and let recursion decide the rest.
We immediately denote a useful auxiliary function, s ( n ) , the number of steps it takes to fully explore a landscape of size 2 n × 2 n . It should be clear that s ( n ) is merely the geometric series:
s ( n ) = 1 + 4 1 + 4 2 + . . . + 4 n − 1 = 4 − 1 4 n − 1
Exploring the first pixel of an image of size 2 n × 2 n immediately reveals four pixels of size 2 n − 1 × 2 n − 1 , and this shall be the basis of our recursion. All of the sub-regions are disjoint, each one can be fully-revealed in s ( n − 1 ) steps, and in f ( n − 1 ) different ways. How many ways can we take these 4 s ( n − 1 ) steps?
Clearly, we can take steps within the different regions in any order we like - one step in top-left, then two in bottom-left, one in top-right, one in top-left again, three in bottom-right... the number of ways we can make these moves, recognizing distinction only in terms of the quadrants they are made in, is equal to the quadrinomial coefficient :
( s ( n − 1 ) , s ( n − 1 ) , s ( n − 1 ) , s ( n − 1 ) 4 s ( n − 1 ) ) = ( s ( n − 1 ) ! ) 4 ( 4 s ( n − 1 ) ) !
Independently, within each quadrant, we can order the steps made in that quadrant in f ( n − 1 ) ways. Therefore, we have the recursive relationship:
f ( n > 1 ) = ( s ( n − 1 ) , s ( n − 1 ) , s ( n − 1 ) , s ( n − 1 ) 4 s ( n − 1 ) ) ⋅ f 4 ( n − 1 )
By caching the values for f ( n ) , and computing the quadrinomial efficiently, we can compute f ( 9 ) in just a handful of seconds on a modern computer.
And the digit sum of f ( 9 ) is 1 6 6 3 2 6 3