 Okay, so solving Pokemon Blue with a huge regular expression, I'm going to tell you about this problem because I've been obsessed with it for like three years. I saw somebody tweet about the last session saying like, Bang Bang Khan has this underlying theme of trying to make sense of the world with tools. This is not that talk. This talk is a frantic, highly obsessed talk about a problem that I believe exists and nobody else does. Right, okay. So I don't have time to explain all the practicalities. I should, I should set a timer is what I should set because otherwise I will go over. Okay, so I don't have time to really explain all the practicalities. It's like a huge problem as it turns out. So what I'm going to do is I'm going to give a brief explanation of what the game is. Explain what my claim means. What do I mean when I say solve Pokemon Blue? Try to convince you it can be done and give you some intuition for how and then pretty much everything else I'm just going to like punt, right? Okay, so Pokemon Blue, it's Game Boy game. It came out in like 1996 or 1995. Basically you play an 11-year-old boy. You want to be the best Pokemon trainer on the planet. And so one day you wake up and you tell your mom and she's like, yeah, okay, that's fine. Go fight strangers. Yeah. Go home Sunday, right? And so you meet this funny old guy and the funny old guy gives you like one of these Pokemon he's captured and you just start wandering the world, right? So as you wander the world, you encounter Pokemon, you try to capture them. You bump into people and then you fight them dual style, right? And whoever's like Pokemon faints the last or like doesn't faint, like they win and they get all the experience points and that's how you like level up, okay? So, okay, so if you're like me, like after like an hour and you realize that the game is really just like wandering around in the grass trying to like find Pokemon, right? It's like, it's like 18 hours of this, right? And it's like, what? Like I'm an adult. Like I don't have time for this stuff, right? Like I have to think about adult things like, like, you know, like tax exemptions and like listen to jazz and other stuff, right? Like, I just like what I wanted to is I want to think really hard about the moves that I'm going to make. I want to write them down, right? So like L, D, R, A, left down, right? A button. And then I want to put that into a regular expression. And I want the regular expression to accept if and only if that moves that is a winning game of Pokemon blue, okay? So there are lots of advantages to this approach. You can check it into Git, for example. You can do pull requests. You can do code review. You can be like you wanted to turn left there, actually, just so you know. And, but most importantly, and the crux of my, my claim that you want to solve, that we're trying to solve Pokemon blue is the regular expression actually precisely specifies all winning games of Pokemon blue. So it's not a little better. Like, it's a lot better, right? Like your alternative is pressing buttons for like 20 hours until you find a particular winning, you know, moves that. And if you think that, that's not that big of a deal. You're like, why, why should I care about this problem? Just listen. Okay, so, so there are 4.83 million copies of Pokemon blue that were sold, 5.02 million copies of Pokemon red, which is basically an identical game. If you assume that the average player spent 12 hours on this, right? Then in aggregate, the human race has spent 118,200,000 person hours on this, right? Think about that. It's like the potato blight for your brain, right? Like, like, it's just, it's just a thing that's swept across the country giving people smaller homework scores and like, and stuff like that. And some people never recovered, right? Like, think about that. It's, it had a profound impact on our, on like the way that we process stuff. And I just believe that, like, if we're to time travel back to 1994, what I'm proposing is we could actually write this regular expression down, put it on a bunch of CDs and just give that to the kids for Christmas, right? Or, or whatever, whatever, whatever the relevant December holiday or a birthday is, right? So I'm just saying, you know, like in aggregate, we'd be better off. Okay, but this is all a digression. Okay, so like, how is this even possible? So I'm going to make two claims, okay? First claim, Pokemon Blue is a finite, it has a finite number of states, okay? So the game is a grid. You press left, you go left, one square, you press right, you go one square. There's no continuous part, right? Like, still original Super Mario Brothers, you're like marching along in a line, right? Pokemon Blue is not like that. There are a finite number of things that you can do. Claim two, it turns out that there is a formal correspondence between regular expressions and finite state machines. I don't have time to explain it or to prove it, but there's the smart guy who wrote this nice book. You can go read it if you want. Okay, so what exactly do I mean? Let's clarify some things. Okay, so when I say finite state machine, I mean a collection of states where there's like a well-structured transition function that tells you how you transition between the states, okay? So in this case, you have a very simple finite state machine, and you start in the initial state, you press A, you go to the middle state, then you press B, and you go to the accept state, okay? And then if you do anything else, you reject, right? So if you think about it, this is kind of like this regular expression, AB, right? It's not a complex example, but I think what we're going to try and do is just show how you would actually transform this into that regular expression. So at the outset, I'll say because the talk is only like 10 minutes, assuming I speak really fast, sorry, Mirabai, who does the transcriptions. We need to sort of simplify the model and come up with something that I can actually explain in 10 minutes. We want a smaller version of Pokemon Blue, I'm calling it Pokemon Mu. Not Pokemon Mu, Pokemon Mu, right? Okay, and then after that, hopefully I'll have time to give you some hints about what you need to actually solve this in a practical way. Okay, so basically Pokemon Mu, we're going to restrict ourselves to finding regular expressions that solve mazes, okay? So you take this small ASCII maze, the hashtag things, those are walls, the S is the start, the E is the exit. This is a slightly more complicated version of the previous state machine. Basically, it allows you to travel back from the middle state. So you can go like right one and then left and then right and then left. But the trick is you have to go to rights in order to get to the accept, right? So like this accepts like right move, right move, that takes you to the accept state. Right, left, right, left, right, right, right, that takes you to an accept state. But like right, left doesn't, right? So you think about what this would look like in a regular expression. It should look something like this. You have RL star, right? So you can do RL as much as you want as long as you end with two Rs, right? Okay, hopefully this makes sense. So now the question of like, how do we actually formalize that transformation? So we want to take the state machine, we want to turn it into a regular expression. Basically, we're going to use an algorithm known as the state removal method. The intuition is like, what if we remove this middle state, right? Like, how could we make an equivalent regular expression? So basically, you can see like if you look at this like the edge from the start to the end state would just end up being like RR, right? So RR now becomes one edge. The RL thing that we saw before just becomes like a self-loop on the initial state. So you can go RL, RL, RL, RR, right? So there's, this is an even more embellished version of the same thing. In real Pokemon, if you're up against a wall and you try to move into the wall, you don't go like through the wall, right? Like you bounce off the wall and you end up where you started, right? So for example, in the start state S, if you go up, you don't like go through the wall, you just end up in start state again. So we've added these little funny self-circles to indicate what the self-transitions are for each of these squares. This only makes it slightly more complex. So you can basically take the same approach in principle, which is like you still have this RL thing, but in the middle of it you have, you can also go like, like if you just trace along the map, you can go right, up, up, up, up, up, left, right? And you end up back at the same start, the same start space, right? So it's not super important that you understand all the intricacies of this, just that you understand conceptually that there is a transformation and the transformation makes sense because you're trying to just like collapse all of these edges down into a single, a single edge. So once you, once you find, you know, once you find that self-loop transition, you can combine it with the original self-loop. So you can go, oh, by the way, the N I forgot to take out, so don't worry about the N, there's no N transition. But the, but now we have like a regular expression. You look at this regular expression that's read at the top here, where we've added this new self-loop transition. This specifies all of the ways that you can start at the starting place and end up back at the start, right? So, so that's what it signifies. So the remaining thing to do is to try and connect the start and the end position. You apply something similar, basically the intuition is you want to go right and then down, but along the way you could go like right, right, right, right, right, down, right? Or like any number of these things. So, so this right down, right, and then right up star thing that you see is just trying to capture that idea that you can, once you hit that node, if you, if you like sort of hit the wall a bunch of times, you can do that as much as you want before you go down and you win. So, Pokemon Mu has, because it's so simple, like the data model is fairly simple, you basically have like four or five types of, of square. I don't, so basically it's like entrance, exit, wall, grass, ground. The transition model for this is pretty simple. You basically have, you know, you have one, one transition for each button. So each button represents you doing something to Pokemon blue. So like if you press up, you go up one square. If you press down, you go down one square. We added or and concat, which is like this regular expression stuff you see at the top right here. So, and that's so that we can collapse the states down. So I don't have time to explain what this algorithm does. It's actually pretty concise, relative to like what I expected. If you want to understand it, you can come find me after the talk. I think the important thing to recognize here is that, not necessarily that you understand how this transition happens, but what is crazy is like, or, well, I should say, what is surprising is that these, well, maybe not surprising. I guess it was, it's not surprising like, like when you think about it, like obviously these are going to get huge, but it was surprising to me when I received this AWS bill, which is for $9,000. So I explain this to the nice people at AWS that this was a mistake, and it turns out if they believe you, sometimes they just expunged the debt. So, okay, so practicalities. Okay, so I just want to cover really quickly some of the things, some of the ways this state model differs from the actual Pokemon blue state model. So in particular, like Pokemon blue is like much more complex, right? Like, not only does your location matter, but all the objects locations in the entire game matter, whether you pick them up matter, how many of each item you're holding, which Pokemon you have, what their moves are, what their levels are, all of this. Basically anything you would want to encode in a state file, like a save file, you need to represent that inside the state, which just makes the state space explode. The thing that is important to recognize is that a core, the fundamental notion of equality between these states is what helps us develop a sensible transition function. So two states are equal if and only if all of these values are the same between two states, right? So the transition function is actually, I think, the most interesting part, which I'm sad I can't talk about. So first of all, it's really complex. You can't get this information necessarily from map data. Sometimes you have to read the code, which is like Z80 assembly. Like, so like if you talk to somebody and they're like, oh, follow me to this other place, you're like, oh, great, thanks for, right? Like, it becomes really hard because then you have to figure out how to wire that transition up manually. But the most interesting thing is like, how do you deal with randomness? Because you are walking through the grass and you have these random encounters. So when I first started this, I just assumed like a random seed and then that makes the rest of the random numbers deterministic, but then that explodes your state space exponentially and you never finish processing it. I realized later that you can use probabilistic regular expressions where the transitions are probabilistic. If you wanna talk about that, I will talk your fucking ear off about that. Yeah, okay, so I think you get the point, right? It's actually a lot easier now. I did this like originally for like last year's talks, but like in the interim, like the open source disassemblies of Pokemon have gotten super good, so you don't have to like, you know, like open up a hex editor and be like, what the heck am I doing, right? So if you wanted to do this like you could, it's definitely not complete. Like I'm trying as hard as I can to save all those hours for us. At the end of the day, I would say it's kind of effective. So sorry for the false advertising and that's all I got.