There is no walkthrough as such for Write or Remember. Just an explanation of how many combinations of reading and writing there are. I shared it to share my general ideas and also to make myself remember to write more than I remember. Also, I had a few silly computational tricks, like tracking certain patterns, that I wanted to show off.

How many valid R and W sequences are there for any number N? You cannot have 2 R's in a row. Call this F(N).

It may sound odd, but we'll start with zero. There is one, the empty sequence.

With one, there is R or W.

With two, there is RR or WR or RW.

With three, it may be easier to see which of the 2^3 don't work. WWR, RWW, WWW. Others are okay.

F(0) = 1
F(1) = 2
F(2) = 3
F(3) = 5

With 4, it's trickier. Now what I'll do is go through from RRRR to WWWW as if we were going through binary numbers from 0000 to 1111.

RRRR
RRRW
RRWR
RWRR
RWRW
WRRR
WRRW
WRWR

Let's do 5, just so we have enough data.

RRRRR
RRRRW
RRRWR
RRWRR
RRWRW
RWRRR
RWRRW
RWRWR
WRRRR
WRRRW
WRRWR
WRWRR
WRWRW

F(4) = 8
F(5) = 13

Those of you who remember some mathematics may recognize these numbers. But let's try a thought experiment.

You may notice F(x) = F(x-1) + F(x-2). And you'd be right, and you can extrapolate this. This creates the Fibonacci Sequence, and I still cringe when I think of how central it was to The Da Vinci Code. But the question is why?

Well, this reddit article on DVC links to both a "discussion" of Dan Brown's writing style and a sequel: https://www.reddit.com/r/books/comments/ove0p8/recently_finished_origin_by_dan_brown_and_its/ and that's why I cringe.

Oh. Wait. You mean why on the mathematical bits, not on why I cringe at Dan Brown? Okay, then. This won't be as funny as the links above, but it may be illuminating.

Notice that any sequence of length X can have a W slapped in front of it, making a valid sequence of length X+1. Do you notice anything about the number of sequences of length X starting with R? They are F(x-2), at least empirically. And here's the thing.

1. every valid sequence must start with a W, or with an RW.
2. every sequence Y of length X that starts with a W can map to a sequence of length X-1, e.g. Y without the first W, and vice versa.
3. every sequence Y of length X that starts with a RW can map to a sequence of length X-2, e.g. Y without the first RW, and vice versa.

So F(x) = F(x-1) + F(x-2).

Okay, so what about your second book? Here, you've changed up your style. You can't write three times in a row, and you can't remember three times in a row.

So what is F(x) in this case? There are two ways to do it. First, let's calculate the recursive formula.

F(1) = 2
F(2) = 4
F(3) = 6 as WWW and RRR don't work.
F(4) = 10. WWWW, WWWR, WRRR, RWWW, RRRW, RRRR aren't viable. You may start to see a pattern here, but let's try one more.

For F(5) we start with WWWWW and count in binary as if W were 1 and R were 0. If this seems a bit odd, well, just take everything of length 4 and slap an R or W after it.

The list is WWRWW, WWRWR, WWRRW, WRWWR, WRWRW, WRWRR, WRRWW, WRRWR, RWWRW, RWWRR, RWRWW, RWRWR, RWRRW, RRWWR, RRWRW, RRWRR which has a count of 16!

By now it may seem like F(x) is the Fibonacci series, doubled. But how can we prove it?

Let W(x) be the number of valid sequences starting with W and R(x) be the number of valid sequences starting with R. We can see that W(x) = R(x). Let's say the inverse of a sequence is just that sequence with R's and W's flipped. Then if a sequence doesn't have 3 R's or W's in a row, neither does its inverse, and vice versa.

Now we claim W(x) = R(x-1) + R(x-2).

We assume here that x >= 3, so that we don't have to deal with sequences of length zero.

If something starts with W, it can start with 1 W or 2, but not 3. If it starts with 1 W, it matches up with a sequence of length x-1 that starts with R (take the W off the front end.) Similarly anything of length x-1 starting with R, if you put a W on the front end, you have a corresponding x-length sequence starting with W.

Apply similar logic for something starting with 2 W's.

Now since W(y) = R(y), W(x) = W(x-1) + W(x-2). There we go again! The Fibonacci sequence, sort of, but with different base cases F(1) = 2 and F(2) = 4.

But there's another way! Let's say we have a sequence S of W's and R's of length x. Then define T(S) as follows:

--entry 1 of T is w
--if entry x of S is w, then entry x+1 of T is different from entry x of T.
--if entry x of S is r, then entry x+1 of T is the same as entry x of T.

Now if S has 2 r's in a row, then T will have 3 of some letter in a row. But if it does not, T will not.

In other words, we have a one-to-one correspondence between chapter X of part 1 and one-half of chapter X+1 of part 2, since you could start with w or r. Clearly any difference in S means a difference in T and vice versa.

It took me some time to think of this, and I didn't think of it until I got some bug reports, but I'm proud of it.

An example is below.

book 1 chapter 4     book 2 chapter 5
            wwww <=> rwrwr, wrwrw
            wwwr <=> rwrww, wrwrr
            wwrw <=> rwrrw, wrwwr
            wwrr <=> rwrrr, wrwww (INVALID)
            wrww <=> rwwrw, wrrwr
            wrwr <=> rwwrr, wrrww
            wrrw <=> rwwwr, wrrrw (INVALID)
            wrrr <=> rwwww, wrrrr (INVALID)
            rwww <=> rrwrw, wwrwr
            rwwr <=> rrwrr, wwrww
            rwrw <=> rrwwr, wwrrw
            rwrr <=> rrwww, wwrrr (INVALID)
            rrww <=> rrrwr, wwwrw (INVALID)
            rrwr <=> rrrww, wwwrr (INVALID)
            rrrw <=> rrrrw, wwwwr (INVALID)
            rrrr <=> rrrrr, wwwww (INVALID)
