From c75679e94a1c4c13781169c2df6559f337be2c2f Mon Sep 17 00:00:00 2001 From: Peter Norvig Date: Mon, 1 Jan 2018 16:41:46 -0800 Subject: [PATCH] Countdown.ipynb updated with Littman Countdown --- ipynb/Countdown.ipynb | 52 ++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/ipynb/Countdown.ipynb b/ipynb/Countdown.ipynb index dc61328..a756429 100644 --- a/ipynb/Countdown.ipynb +++ b/ipynb/Countdown.ipynb @@ -2876,16 +2876,16 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'2.0+(1*8), 2.0-(1-8), (2.0-1)*8, (2*0)-(1-8), √(2.0*18), -2.0-(1-8), √(-2.0+18), 2.0+(1^8), 20-18, 2.0-(1^8)'" + "'2.0+(1*8), 2.0-(1-8), (2.0-1)*8, (2*0)-(1-8), √(2.0*18), -2.0-(1-8), √(-2.0+18), 2.0+(1^8), 20-18, 2.0-(1^8), 2*(0/18)'" ] }, - "execution_count": 75, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } @@ -2896,7 +2896,7 @@ "\n", "def littman_countdown(year):\n", " \"Return a Littman countdown for the year.\"\n", - " return ', '.join(littman(year, i) for i in range(10, 0, -1))\n", + " return ', '.join(littman(year, i) for i in range(10, -1, -1))\n", "\n", "def littman(year, i):\n", " \"Return a string that makes i with the digits of year.\"\n", @@ -2917,31 +2917,37 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 82, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{2011: '20/(1+1), 20-11, -2.0+(1/.1), (2.0+1)!+1, √(20-11)!, (2.0+1)!-1, 2.0*(1+1), √(20-11), 2+(0/11), 2.0/(1+1)',\n", - " 2012: '20/(1*2), (2.0+1)^2, 20-12, 2.0+(1/.2), 2.0*(1+2), 2.0+(1+2), 2.0*(1*2), 2.0-(1-2), 2+(0/12), -.20+1.2',\n", - " 2013: '20/(-1+3), (2.0+1)*3, 2.0*(1+3), 20-13, 2.0+(1+3), 20/(1+3), 2.0-(1-3), (2.0-1)*3, 2+(0/13), (2.0+1)/3',\n", - " 2014: '2.0*(1+4), (2.0+1)^√4, 2.0/(1/4), 2.0+(1+4), 20-14, 20*(1/4), 20/(1+4), -20-(1-4!), 2+(0/14), .20*(1+4)',\n", - " 2015: '2.0*(1*5), √(201-5!), 2.0+(1+5), 2.0+(1*5), (.20*15)!, 20-15, 20/(1*5), .20*15, 2+(0/15), 2*(0.1*5)',\n", - " 2016: '2*(0-(1-6)), 2.0+(1+6), 2.0*√16, 2.0-(1-6), √(20+16), 20/√16, 20-16, 2.0+(1^6), 2+(0/16), .20*(-1+6)',\n", - " 2017: '2.0+(1+7), 2.0+(1*7), 2.0-(1-7), (2.0-1)*7, (20-17)!, -2.0+(1*7), -2.0-(1-7), 20-17, 2+(0/17), 2.0-(1^7)',\n", - " 2018: '2.0+(1*8), 2.0-(1-8), (2.0-1)*8, (2*0)-(1-8), √(2.0*18), -2.0-(1-8), √(-2.0+18), 2.0+(1^8), 20-18, 2.0-(1^8)',\n", - " 2019: '20-(1+9), (2.0-1)*9, (2*0)-(1-9), -2.0+(1*9), -2.0-(1-9), 20/(1+√9), 2.0-(1-√9), 2.0+(1^9), 2+(0/19), 20-19'}" - ] - }, - "execution_count": 76, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "2011:\n", + "20/(1+1), 20-11, -2.0+(1/.1), (2.0+1)!+1, √(20-11)!, (2.0+1)!-1, 2.0*(1+1), √(20-11), 2+(0/11), 2.0/(1+1), 2*(0/11)\n", + "2012:\n", + "20/(1*2), (2.0+1)^2, 20-12, 2.0+(1/.2), 2.0*(1+2), 2.0+(1+2), 2.0*(1*2), 2.0-(1-2), 2+(0/12), -.20+1.2, 2*(0/12)\n", + "2013:\n", + "20/(-1+3), (2.0+1)*3, 2.0*(1+3), 20-13, 2.0+(1+3), 20/(1+3), 2.0-(1-3), (2.0-1)*3, 2+(0/13), (2.0+1)/3, 2*(0/13)\n", + "2014:\n", + "2.0*(1+4), (2.0+1)^√4, 2.0/(1/4), 2.0+(1+4), 20-14, 20*(1/4), 20/(1+4), -20-(1-4!), 2+(0/14), .20*(1+4), 2*(0/14)\n", + "2015:\n", + "2.0*(1*5), √(201-5!), 2.0+(1+5), 2.0+(1*5), (.20*15)!, 20-15, 20/(1*5), .20*15, 2+(0/15), 2*(0.1*5), 2*(0/15)\n", + "2016:\n", + "2*(0-(1-6)), 2.0+(1+6), 2.0*√16, 2.0-(1-6), √(20+16), 20/√16, 20-16, 2.0+(1^6), 2+(0/16), .20*(-1+6), 2*(0/16)\n", + "2017:\n", + "2.0+(1+7), 2.0+(1*7), 2.0-(1-7), (2.0-1)*7, (20-17)!, -2.0+(1*7), -2.0-(1-7), 20-17, 2+(0/17), 2.0-(1^7), 2*(0/17)\n", + "2018:\n", + "2.0+(1*8), 2.0-(1-8), (2.0-1)*8, (2*0)-(1-8), √(2.0*18), -2.0-(1-8), √(-2.0+18), 2.0+(1^8), 20-18, 2.0-(1^8), 2*(0/18)\n", + "2019:\n", + "20-(1+9), (2.0-1)*9, (2*0)-(1-9), -2.0+(1*9), -2.0-(1-9), 20/(1+√9), 2.0-(1-√9), 2.0+(1^9), 2+(0/19), 20-19, 2*(0/19)\n" + ] } ], "source": [ - "{y: littman_countdown(y) \n", - " for y in range(2011, 2020)}" + "for y in range(2011, 2020):\n", + " print('{}:\\n{}'.format(y, littman_countdown(y)))" ] } ],