Add files via upload
This commit is contained in:
@@ -164,7 +164,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Finally, here's a third version. It has a very straightforward approach: generate all possible output strings for the source, and then check if the target its one of the possible outputs. To generate output strings, scan left-to-right, and for every character consider both the possibility of typing the character and of replacing it by backspace, maintaining a set of all possible outputs at each step.\n",
|
||||
"Finally, below is a third version. It has a very straightforward approach: generate all possible output strings for the source, and then check if the target its one of the possible outputs. To generate output strings, scan left-to-right, and for every character consider both the possibility of typing the character and of replacing it by backspace, maintaining a set of all possible outputs at each step.\n",
|
||||
"\n",
|
||||
"If this version of the program gives the same results as a more complicated version, that gives us added confidence that all the assumptions made by the complicated version are valid, because this version does not make those assumptions."
|
||||
]
|
||||
@@ -182,7 +182,7 @@
|
||||
" return target in possible_outputs(source)\n",
|
||||
"\n",
|
||||
"def possible_outputs(source: str) -> set:\n",
|
||||
" \"\"\"All outputs that can be generated by \"\"\"\n",
|
||||
" \"\"\"All outputs that can be generated by replacing characters in `source` with `backspace`.\"\"\"\n",
|
||||
" outputs = {''}\n",
|
||||
" for c in source:\n",
|
||||
" outputs = union({out + c, out[:-1]} for out in outputs)\n",
|
||||
|
||||
Reference in New Issue
Block a user