+ "You've arrived at your destination and are looking forward to seeing the site. But it's a large site and you'll need a guide.\n",
+ "\n",
+ "Each guide posts the route they'll take on a board, described the by steps they'll take. The steps are either `F` (take a step forward), `L` (turn left 90⁰ then take a step forward) or `R` (turn right 90⁰ then take a step forward). For example, the route `FFRRFLRRFR` will look like this (assuming you start facing right; the blob shows the starting point):\n",
+ "\n",
+ "\n",
+ "![Sample valid tour](question-example-tour-000-s0010-m000-trim.png)\n",
+ "\n",
+ "A sample valid tour\n",
+ "\n",
+ "while the tour `FFLLRLRLLFLR` looks like this (again, assuming you start facing right):\n",
+ "\n",
+ "![Sample valid tour](question-example-tour-001-s0012-m000-trim.png) \n",
+ "\n",
+ "A sample valid tour\n",
+ "\n",
+ "However, some of the tour guides are charlatans. They have tour that either doesn't return you to your starting place, or loops around to visit the same place more than once. For example, the tour `RRFFLLFFFFLF` doesn't return to your starting place:\n",
+ "\n",
+ "![Sample invalid tour](question-example-tour-002-s0012-m001-trim.png)\n",
+ "\n",
+ "An invalid tour\n",
+ "\n",
+ "and the tour `RRLLRRFFRFRFLR` may get you back to where you started, but only after going around a small loop:\n",
+ "\n",
+ "![Sample invalid tour](question-example-tour-003-s0014-m001-trim.png)\n",
+ "\n",
+ "A sample invalid tour\n",
+ "\n",
+ "You're only interested in valid tours, the ones that return you to your starting place and don't visit any other spot more than once. (It doesn't matter what direction you're facing when you return to your starting place, just that you return there at the end of the tour.)\n",
+ "\n",
+ "In fact, you've got your daily fitness tracker widget to keep happy. Even on holiday, you need to keep up the number of steps you take. You're interested in the total length of all the valid tours. In the examples here, the total length of the two valid tours is 10 + 12 = 22 steps.\n",
+ "\n",
+ "# Part 1\n",
+ "\n",
+ "The tours are given in [06-tours.txt](06-tours.txt), one tour per line. \n",
+ "\n",
+ "What is the total length of all the valid tours?\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "It seems you've done your guides a disservice.\n",
+ "\n",
+ "Yes, there are some charlatans around. But some of the tours a split between two guides. Each posted tour alone looks like it would be incomplete, but when you finish the first leg of a tour, you pick up a new guide and continue, eventually returning you to your starting place.\n",
+ "\n",
+ "For instance, the tours `FFRFLLFFFRLRRFFFLFLRRFLLFFFFFRFLFFFFFRLLFRFRLLFFFFF` and `FLRFFRLLFRFFFLFFLFFRFRRLLFFRLFFFFFLLFFRFRFL` are both incomplete; on its own, each tour would leave you stranded. \n",
+ "\n",
+ "![A split tour](question-example-tour-004-s0051-m001-trim.png)\n",
+ "\n",
+ "A split tour \n",
+ "\n",
+ "![More of a split tour](question-example-tour-005-s0043-m001-trim.png)\n",
+ "\n",
+ "More of a split tour\n",
+ "\n",
+ "But if you do one then the other, the complete 94-step tour is valid:\n",
+ "\n",
+ "![Split tour combined](question-example-tour-006-s0094-m000-trim.png)\n",
+ "\n",
+ "The split tour combined\n",
+ "\n",
+ "(You start the second half of the tour heading left, so turn the second picture 180⁰ to visualise it.)\n",
+ "\n",
+ "Luckily for you, tour guides only act alone or in pairs, and never in teams of three or more. \n",
+ "\n",
+ "(Because of way the initial facing changes the way a tour unfolds, it's generally the case that tour A followed by tour B is different from B followed by A.)\n",
+ "\n",
+ "# Part 2\n",
+ "\n",
+ "The tours are still given in [06-tours.txt](06-tours.txt), one tour per line. Your definition of a valid tour now includes the combination of two partial tours, so long as the combined tour never crosses itself and returns you to your staring place. With this new definition of valid tours, what is the total length of all the valid tours?"