From 507d42f8f1ca1ec911672350b1d389c5b9d1dd40 Mon Sep 17 00:00:00 2001 From: Peter Norvig Date: Sun, 19 Apr 2020 16:09:08 -0700 Subject: [PATCH] Add files via upload --- ipynb/Cheryl.ipynb | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/ipynb/Cheryl.ipynb b/ipynb/Cheryl.ipynb index d9d01ca..4f1b23a 100644 --- a/ipynb/Cheryl.ipynb +++ b/ipynb/Cheryl.ipynb @@ -62,7 +62,18 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'May'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "month('May 15')" ] @@ -71,7 +82,18 @@ "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'15'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "day('May 15')" ] @@ -129,7 +151,18 @@ "cell_type": "code", "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'May 15', 'May 16', 'May 19'}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "told('May')" ] @@ -196,7 +229,7 @@ "\n", "Here is the main function, `cheryls_birthday`, which computes the subset of dates in the global variable `dates` that satisfy statements 3 through 5. We will define a **statement** as a boolean function that takes a single date as input and returns true if the statement would be true in the condition that the given date is Cheryl's actual birthday. So a statement only has to consider one date at a time. But the code within a statement may have to consider the belief states of Albert and Bernard, to determine if the statement is true.\n", "\n", - "The function `satisfy` takes a collection of dates and some statement(s) and returns the subset that satisfies all the statements:" + "The function `satisfy` takes a collection of dates and some statement(s) and returns the subset of dates that satisfies all the statements." ] }, { @@ -240,7 +273,7 @@ "outputs": [], "source": [ "def albert1(date) -> bool:\n", - " \"\"\"Albert: I don't know when Cheryl's birthday is, but I know that Bernard does not know too.\"\"\"\n", + " \"Albert: I don't know when Cheryl's birthday is, and I know that Bernard does not know.\"\n", " albert_beliefs = told(month(date))\n", " return not know(albert_beliefs) and not satisfy(albert_beliefs, bernard_knows)\n", "\n",