{"id":7826,"date":"2024-07-04T21:01:01","date_gmt":"2024-07-04T13:01:01","guid":{"rendered":""},"modified":"2024-07-04T21:01:01","modified_gmt":"2024-07-04T13:01:01","slug":"\u300aDesign of Computer Programs\u300b\u5b66\u4e60\u7b14\u8bb0\uff082 - 1\uff09Back of the Envelope - Lesson 2","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7826.html","title":{"rendered":"\u300aDesign of Computer Programs\u300b\u5b66\u4e60\u7b14\u8bb0\uff082 - 1\uff09Back of the Envelope - Lesson 2"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

Back of the Envelope<\/h2>\n

envelope n.\u4fe1\u5c01\uff08\u91d1\u5c71\u8bcd\u9738\uff09<\/p>\n

Lesson 2<\/h3>\n

\u89c6\u9891\u94fe\u63a5\uff1a
Lesson 2 - Udacity<\/p>\n

1. \u7ec3\u4e60\uff1aZebra Puzzle <\/h4>\n

zebra n.\u6591\u9a6c<\/p>\n

puzzle n.\u96be\u9898<\/p>\n

Zebra Puzzle - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

napkin n.\u9910\u5dfe\u7eb8<\/p>\n

profit n.\u5229\u6da6 vi.\u83b7\u5229<\/p>\n

porous adj.\u80fd\u6e17\u900f\u7684\uff1b\u6613\u7a7f\u8fc7\u7684<\/p>\n

cliche n.\u9648\u8bcd\u6ee5\u8c03<\/p>\n

calculation n.\u8ba1\u7b97\uff1b\u4f30\u8ba1\uff1b\u6df1\u601d\u719f\u8651<\/p>\n

virtue n.\u7f8e\u5fb7\uff1b\u5fb7\u884c\uff1b\u957f\u5904<\/p>\n

methodology n.\u65b9\u6cd5\u5b66\uff1b\u65b9\u6cd5\u8bba<\/p>\n

brute n.\u6b8b\u5fcd\u7684\uff1b\u65e0\u7406\u6027\u7684<\/p>\n

a brute force solution \u86ee\u529b\u89e3\uff08\u6765\u81ea\u4e8e\u767e\u5ea6\u7ffb\u8bd1\uff09<\/p>\n

inhabitant n.\u5c45\u6c11\uff0c\u4f4f\u6237\uff1b\u52a8\u7269<\/p>\n

nationality n.\u56fd\u7c4d\uff1b\u56fd\u5bb6\uff1b\u90e8\u843d<\/p>\n

notion n.\u6982\u5ff5\uff0c\u89c2\u5ff5<\/p>\n

assignment n.\u5206\u914d\uff1b\u4efb\u547d\uff1b\u59d4\u6d3e<\/p>\n

spaniard n.\u897f\u73ed\u7259\u4eba<\/p>\n

generic adj.\u5c5e\u6027\u7684\uff1b\u4e00\u822c\u7684<\/p>\n

subjective adj.\u4e3b\u89c2\u7684\uff1b\u4e2a\u4eba\u7684<\/p>\n

plausible adj.\u8c8c\u4f3c\u771f\u5b9e\u7684\uff1b\u8c8c\u4f3c\u6709\u7406\u7684<\/p>\n

mutually adv.\u4e92\u76f8\u5730<\/p>\n

exclusive adj.\u4e13\u7528\u7684\uff1b\u9ad8\u7ea7\u7684\uff1b\u6392\u5916\u7684\uff1b\u5355\u72ec\u5730<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u8fd9\u662f\u4e00\u4e2a\u6709\u4ef7\u503c\u7684\u6280\u80fd\u3002\u5728\u771f\u5b9e\u7684\u751f\u6d3b\u4e2d\uff0c\u53ef\u4ee5\u505a\u5feb\u901f\u7684\u3001\u810f\u7684\u4f30\u8ba1\uff0c\u5bf9\u8ba1\u7b97\u673a\u7a0b\u5e8f\u5458\u6765\u8bf4\uff0c\u7279\u522b\u6709\u7528\u3002\u5b83\u5141\u8bb8\u7a0b\u5e8f\u5458\uff0c\u6709\u4e00\u4e2a\u5077\u61d2\u7684\u91cd\u8981\u7684\u957f\u5904\u3002\u5b83\u5141\u8bb8\u6211\u4eec\uff0c\u4e5f\u5c31\u662f\uff0c\u6211\u4eec\u5c06\u53ef\u4ee5\u63d0\u51fa\u6211\u4eec\u80fd\u591f\u60f3\u51fa\u7684\u6700\u7b80\u5355\u7684\u8bbe\u8ba1\uff0c\u5728\u4e00\u4e2a\u4fe1\u5c01\u80cc\u9762\u786e\u8ba4\uff0c\u90a3\u4e2a\u8bbe\u8ba1\uff0c\u5bf9\u4e8e\u6211\u4eec\u5c3d\u529b\u53bb\u505a\u7684\u4e8b\u60c5\uff0c\u662f\u8db3\u591f\u9ad8\u6548\u7684\uff0c\u7136\u540e\u6211\u4eec\u53ef\u4ee5\u505c\u6b62\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u505c\u6b62\u4e86\u3002\u6211\u4eec\u4e0d\u5fc5\u5c1d\u8bd5\u4f7f\u5b83\u66f4\u590d\u6742\u3002<\/p>\n

\u8fd9\u6574\u4e2a\u8bfe\u7a0b\u662f\u5173\u4e8e\u7ba1\u7406\u590d\u6742\u5ea6\uff0c\u7ba1\u7406\u590d\u6742\u5ea6\u7684\u6700\u91cd\u8981\u7684\u65b9\u5f0f\u4e4b\u4e00\u662f\uff0c\u5ffd\u7565\u5b8c\u6574\u6027\uff0c\u4ec5\u4ec5\u53ea\u641e\u6700\u7b80\u5355\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5982\u679c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u505a\uff0c\u7136\u540e\u6211\u4eec\u5c31\u4f1a\u671d\u5411\u66f4\u597d\u7684\u8bbe\u8ba1\u3002\u8fd9\u4e2a\u8bfe\u7a0b\uff0c\u6211\u4eec\u5c06\u4f1a\u5b66\u4e60\u5982\u4f55\u90a3\u6837\u505a\uff0c\u6211\u4eec\u5c06\u4f1a\u5b66\u4e60\u5982\u4f55\u4f30\u8ba1\uff0c\u4f60\u4f55\u65f6\u662f\u8db3\u591f\u9ad8\u6548\u7684\uff0c\u6211\u4eec\u5c06\u5b66\u4e60\u4f55\u65f6\u505c\u6b62\uff0c\u5e76\u4e14\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7a0b\u5e8f\u66f4\u9ad8\u6548\u3002<\/p>\n

\u6211\u5c06\u4ee5\u4e00\u4e2a\u5e7f\u4e3a\u4eba\u77e5\u7684Zebra Puzzle\u96be\u9898\u5f00\u59cb\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u8bf4\u660e\u4e66\u3002\u6211\u4eec\u5c06\u5c1d\u8bd5\u89e3\u51b3\u8fd9\u4e2a\u96be\u9898(address this puzzle \u89e3\u51b3\u8fd9\u4e2a\u96be\u9898\u3002\u767e\u5ea6\u7ffb\u8bd1)\uff0c\u67e5\u770b\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u60f3\u51fa\u4e00\u4e2a\u7a0b\u5e8f\u3001\u89e3\u51b3\u5b83\uff0c\u5e76\u4e14\uff0c\u63a2\u7d22\u6211\u4eec\u5982\u4f55\u63d0\u51fa\u90a3\u4e2a\u89e3\u51b3\u65b9\u6848\u7684\u65b9\u6cd5\u8bba\uff0c\u8fd8\u6709\uff0c\u51b3\u5b9a\u8db3\u591f\u597d\u7684\u89e3\u51b3\u65b9\u6848\u7684\u8fc7\u7a0b\uff0c1\u4e2a\u86ee\u529b\u89e3\u662f\u5426\u53ef\u4ee5\u8d77\u4f5c\u7528\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u9605\u8bfb\u8fd9\u4e2apuzzle\u7684\u8bf4\u660e\u4e66\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5f00\u59cb\u5206\u6790\u5b83\u3002\u7b2c1\u4e2a\u6982\u5ff5\u662f\u623f\u5b50houses\u3002\u6211\u4eec\u88ab\u544a\u77e5\uff0c\u67095\u4e2a\u623f\u5b50houses\u3002\u5e76\u4e14\uff0c\u7136\u540e\uff0c\u8fd9\u91cc\u6709\u8fd9\u4e9b\u623f\u5b50\u7684\u4f4f\u6237\u7684\u8d22\u4ea7\u7279\u6027(properties n.\u7279\u6027\uff1b\u8d22\u4ea7\uff1b\u6240\u6709\u6743\uff1b\u623f\u5730\u4ea7)\u548c\u623f\u5b50\u81ea\u8eab\u7684\u8d22\u4ea7\u7279\u6027\u3002\u6240\u4ee5\uff0c\u8fd9\u91cc\u6709\u56fd\u7c4d\u3001\u623f\u5b50\u7684\u989c\u8272\u3001\u5b83\u4eec\u62e5\u6709(\u623f\u5b50\u3001\u8fd8\u662f\u4f4f\u6237\uff1f)\u7684\u5ba0\u7269\uff0c\u4ed6\u4eec\u559d\u7684\u996e\u6599\uff0c\u4ed6\u4eec\u62bd\u7684\u70df\u3002\u5e76\u4e14\uff0c\u7136\u540e\uff0c\u9664\u4e86properties\u4e4b\u5916\uff0c\u5bf9\u4e8e\u623f\u5b50\uff0c\u8fd9\u91cc\u6709\u4e00\u4e2aproperties\u7684\u5206\u914d(assignment)\u7684\u6982\u5ff5\u3002\u6ca1\u5173\u7cfb\uff0c\u65e0\u6240\u8c13\uff0c\u4f60\u53ef\u4ee5\u8003\u8651\u90a3\u4e2a\u3002\u4f60\u53ef\u4ee5\u8003\u8651\u5b83as\u50cf\u662f\uff0c\u5206\u914d\u623f\u5b50\u53f7\u78012\u7ea2\u989c\u8272\uff0c\u6216\u8005\u8003\u8651\u5b83\u4f5c\u4e3aas\u5206\u914d\u7ea2\u8272\u7ed9\u623f\u5b50\u53f7\u78012\u3002\u7136\u540e\uff0c\u67091\u4e2a\u4f4d\u7f6e\u7684\u6982\u5ff5\uff0c\u4f4d\u7f6e1\u52305\uff0c\u63d0\u5230\u7b2c1\u4e2a\u623f\u5b50\u7684\u60f3\u6cd5\u3001\u4e2d\u95f4\u7684\u623f\u5b50\u3001\u76f8\u90bb\u7684\u3001\u7d27\u63a5\u7684\u53f3\u8fb9\u7684\u3002<\/p>\n

\u6211\u8ba4\u4e3a\u90a3\u8986\u76d6\u4e86\u51fa\u73b0\u5728\u8bf4\u660e\u4e66\u4e2d\u7684\u7edd\u5927\u90e8\u5206\u3002\u8ba9\u6211\u4eec\u56de\u5230\u5b83\uff0c\u68c0\u67e5\u5b83\u662f\u5426\u8d77\u4f5c\u7528\u3002\u6240\u4ee5\u6211\u6b63\u5728\u770b\u5927\u91cf\u7684\u6982\u5ff5\uff0c\u6211\u4eec\u5df2\u7ecf\u8986\u76d6\u5230\u7684\uff1a5\u4e2a\u623f\u5b50\u3001\u82f1\u56fd\u4eba\u3001\u7ea2\u623f\u5b50\u3001\u897f\u73ed\u7259\u4eba\u3001\u72d7\u3002\u73b0\u5728\uff0c\u6709\u5c11\u91cf\u7684\u5355\u8bcd\uff0c\u6211\u4eec\u6ca1\u6709\u8986\u76d6\uff0c\u6bd4\u5982\u201c\u4f4f\u8fdb\u53bb\u201d\u3001\u201c\u62e5\u6709\u201d\u8fd9\u4e9b\u4e1c\u897f(things like lives in and owns the)\u3002\u6211\u4eec\u5728\u4e00\u822c\u610f\u4e49\u4e0a\u8986\u76d6\u4e86\u5b83\u4eec\uff0c\u5c31\u662f\u8bf4\uff0c\u8fd9\u662f\u4e00\u4e2a\u4ece\u82f1\u56fd\u4eba\u52301\u4e2a\u623f\u5b50\u7684\u5206\u914d\uff0c\u72d7\u52301\u4e2a\u623f\u5b50\u7684\u5206\u914d\uff0c\u4f46\u662f\uff0c\u95ee\u9898\u662f\uff0c\u6211\u4eec\u662f\u5426\u9700\u8981\u533a\u5206\u4e0d\u540c\u7c7b\u578b\u7684\u5206\u914d\uff1f<\/p>\n

\u6240\u4ee5\uff0c\u95ee\u9898\u662f\uff0c\u6211\u4eec\u662f\u5426\u6f0f\u6389\u4e86\uff0c\u9644\u7740\u4e861\u4e2a\u8bf4\u660e\u76841\u4e2aproperty\u540d\u79f0\u7684\u6982\u5ff5\uff1f<\/p>\n

\u6240\u4ee5\uff0c\u4f8b\u5982\uff0cproperty name\u4f1a\u662f\u56fd\u7c4d\u548cthe description is lived in\u3002\u6211\u4eec\u662f\u5426\u9700\u8981\u50cf\u90a3\u6837\u547d\u540d\u5b83\u4eec\uff0c\u6216\u8005\uff0c\u6211\u4eec\u662f\u5426\u4ec5\u4ec5\u9700\u89811\u4e2aproperty\u7ec4\u7684\u6982\u5ff5\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u91cc\u6709\u8fd9\u4e9b\u82f1\u56fd\u4eba\u3001\u897f\u73ed\u7259\u4eba\u3001\u632a\u5a01\u4eba\u3001\u65e5\u672c\u4eba\u3001\u4e4c\u514b\u5170\u4eba\u548c\u4ed6\u4eec5\u4e2a\u4e00\u8d77\u7684properties\uff0c\u4f46\u662f\u6211\u4eec\u4e0d\u9700\u8981\u4ed6\u4eec\u7684\u540d\u5b57\uff0c\u6216\u8005\uff0c\u6211\u4eec\u662f\u5426\u53ef\u4ee5\u65e0\u89c6\u8fd9\u4e2a\u7ec4\u7684\u6982\u5ff5(this notion of grouping altogether)\uff1f\u8fd9\u662f\u6709\u70b9\u4e3b\u89c2\u7684\u2014\u20141\u4e2a\u597d\u7684\u8bbe\u8ba1\u9009\u62e9\u662f\u4ec0\u4e48\u6837\u7684\uff1f\u2014\u2014\u4f46\u662f\uff0c\u544a\u8bc9\u6211\uff0c\u8fd93\u4e2a\u79cd\uff0c\u4f60\u8ba4\u4e3a\u54ea\u4e2a\u662f\u8c8c\u4f3c\u6709\u7406\u7684\u3001\u6216\u8005\u5408\u7406\u7684\u8bbe\u8ba1\u9009\u62e9\uff0c\u7136\u540e\u68c0\u67e5\u6240\u6709\u63d0\u4f9b\u7684\u3002<\/p>\n

\u6982\u5ff5\u6e05\u5355<\/p>\n

\"\u300aDesign<\/p>\n

\u25a0 property<\/span> name \/ description \u25a0 property<\/span> group<\/span> \u25a1 ignore group<\/span><\/code><\/pre>\n

\u6211\u7684\u7b54\u6848\u662f\uff0c\u5b9a\u4e49property names\uff0c\u5c06\u4f1a\u662f1\u4e2a\u597d\u7684\u9009\u62e9\u3002\u5b83\u53ef\u80fd\u4f1a\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\uff0c\u5728\u8fd9\u4e2a\u7a0b\u5e8f\u7684\u5b9a\u4e49\u4e2d\uff0c\u53d1\u751f\u4e86\u4ec0\u4e48\u3002\u5b9a\u4e49\u6ca1\u6709\u540d\u5b57\u7684\u7ec4(groups without groups)\uff0c\u4e5f\u5c06\u662f\u597d\u7684(\u9009\u62e9)\u3002\u65e0\u89c6groups\uff0c\u6211\u8ba4\u4e3a\u5c06\u4e0d\u4f1a\u5de5\u4f5c\u3001\u8d77\u4f5c\u7528\uff0c\u5e76\u4e14\u8fd9\u91cc\u67091\u4e2a\u95ee\u9898\u3002\u6211\u4eec\u5fc5\u987b\u77e5\u9053\uff0c\u5982\u679cred\u88ab\u5206\u914d\u7ed9\u623f\u5b50\u53f7\u78012\uff0c\u7136\u540e\uff0cblue\u4e0d\u80fd\u88ab\u5206\u914d\u7ed9\u623f\u5b50\u53f7\u78012\uff0c\u4f46\u662forange juice\u53ef\u4ee5\u88ab\u5206\u914d\u7ed9\u623f\u5b50\u53f7\u78012\u3002\u6240\u4ee5\uff0cproperties\u653e\u8fdb1\u4e2a\u7ec4group\u4e2d\u7684\u60f3\u6cd5\uff0c\u662f\u4e92\u76f8\u5730\u3001\u5355\u72ec\u5730\uff0cproperties\u5728\u7ec4\u4e4b\u5916\u4e0d\u662f(So there\u2019s this idea that properties within a group are mutually exclusive and properties outside of the group are not.)\u3002\u5728\u67d0\u79cd\u610f\u4e49\u4e0a\uff0c\u6211\u4eec\u9700\u8981\u8868\u73b0\u90a3\u4e2a\u3002<\/p>\n

Zebra Puzzle \u7684\u8bf4\u660e<\/h5>\n

Zebra Puzzle - \u7ef4\u57fa\u767e\u79d1<\/p>\n

1 There are five houses.
1 \u67095\u4e2a\u623f\u5b50\u3002
2 The Englishman lives in the red house.
2 \u82f1\u56fd\u4eba\u4f4f\u5728\u7ea2\u623f\u5b50\u91cc\u3002
3 The Spaniard owns the dog.
3 \u897f\u73ed\u7259\u4eba\u6709\u72d7\u3002
4 Coffee is drunk in the green house.
4 \u7eff\u623f\u5b50\u91cc\uff0c\u559d\u5496\u5561\u3002
5 The Ukrainian drinks tea.
5 \u4e4c\u514b\u5170\u4eba\u559d\u8336
6 The green house is immediately(\u7acb\u5373\uff1b\u76f4\u63a5\u5730\uff1b\u7d27\u63a5\u5730) to the right of the ivory(\u8c61\u7259\u8272\u7684) house.
6 \u7eff\u623f\u5b50\u7d27\u6328\u7740\u8c61\u7259\u8272\u623f\u5b50\u7684\u53f3\u8fb9\u3002
7 The Old Gold smoker owns snails(\u6162\u6027\u5b50\uff1b\u8717\u725b).
7 \u53e4\u91d1\u8272\u7684\u70df\u6c11\u6027\u5b50\u6162\u3002
8 Kools are smoked in the yellow house.
8 \u9ec4\u8272\u623f\u5b50\u91cc\u5728\u5438Kools\u3002
9 Milk is drunk in the middle house.
9 \u4e2d\u95f4\u7684\u623f\u5b50\u91cc\uff0c\u5728\u559d\u725b\u5976\u3002
10 The Norwegian lives in the first house.
10 \u632a\u5a01\u4eba\u4f4f\u5728\u7b2c1\u4e2a\u623f\u5b50\u91cc\u3002
11 The man who smokes Chesterfields(\u957f\u6c99\u53d1) lives in the house next to the man with the fox.
11 \u62bd\u957f\u6c99\u53d1\u70df\u7684\u4eba\uff0c\u4f4f\u5728\u5e26\u7740\u72d0\u72f8\u7684\u4eba\u7684\u623f\u5b50\u65c1\u8fb9\u3002
12 Kools are smoked in a house next to the house where the horse is kept.
12 \u5438Kools\u7684\u623f\u5b50\uff0c\u6328\u7740\u517b\u9a6c\u7684\u623f\u5b50\u3002
13 The Lucky Strike(lucky strike \u597d\u5f69\uff0c\u9e3f\u8fd0\u5f53\u5934) smoker drinks orange juice.
13 \u597d\u8fd0\u70df\u6c11\u559d\u6a58\u5b50\u6c41\u513f\u3002
14 The Japanese smokes Parliaments.
14 \u65e5\u672c\u4eba\u62bd\u8bae\u4f1a(Parliaments)\u70df\u3002
15 The Norwegian lives next to the blue house.
15 \u632a\u5a01\u4eba\u4f4f\u5728\u84dd\u8272\u623f\u5b50\u65c1\u8fb9\u3002
Who drinks water? Who owns the zebra?
\u8c01\u559d\u6c34\uff1f\u8c01\u62e5\u6709\u6591\u9a6czebra\uff1f
Each house is painted a different color, and their inhabitants(\u5c45\u6c11\uff1b\u4f4f\u6237) are of different nationalities, own different pets, drink different beverages(\u996e\u6599) and smoke different brands of American cigarettes.
\u6bcf\u4e2a\u623f\u5b50\u88ab\u6d82\u6210\u4e00\u4e2a\u4e0d\u540c\u7684\u989c\u8272\uff0c\u5e76\u4e14\u5b83\u4eec\u7684\u4f4f\u6237\u662f\u4e0d\u540c\u56fd\u7c4d\u7684\uff0c\u62e5\u6709\u4e0d\u540c\u7684\u5ba0\u7269\uff0c\u559d\u4e0d\u540c\u7684\u996e\u6599\uff0c\u62bd\u4e0d\u540c\u54c1\u724c\u7684\u7f8e\u56fd\u70df\u3002<\/p>\n

2. \u7ec3\u4e60\uff1aWheres The Spaniard <\/h4>\n

Wheres The Spaniard - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

crux n.\u6838\u5fc3\uff1b\u5173\u952e\uff1b\u75c7\u7ed3<\/p>\n

deduce vt.\u63a8\u65ad\uff0c\u63a8\u8bba<\/p>\n

deduction n.\u63a8\u7406\uff1b(\u63a8\u7406\u6240\u5f97\u51fa\u7684)\u7ed3\u8bba<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u6574\u4e2a\u95ee\u9898\u7684\u6838\u5fc3\u662f\u8fdb\u884c\u5206\u914d\u3002\u67092\u79cd\u65b9\u5f0f\u505a\u8fd9\u4ef6\u4e8b\u60c5\u3002\u6211\u4eec\u53ef\u4ee5\u63a8\u7406\uff0c\u4ec0\u4e48\u5206\u914d\u5fc5\u987b\u662f\u771f\u7684(what assignment must be true)\u2014\u2014\u5b83\u5fc5\u987b\u662f\u8fd9\u79cd\u60c5\u51b5\uff0c\u82f1\u56fd\u4eba\u57281\u4e2a\u786e\u5b9a\u7684\u623f\u5b50\u91cc\u3002\u6216\u8005\u6211\u4eec\u53ef\u4ee5\u4ec5\u4ec5\u5c1d\u8bd5\u4e0d\u540c\u7684\u53ef\u80fd\u6027\u2014\u2014\u5c1d\u8bd5\u628a\u82f1\u56fd\u4eba\u653e\u8fdb\u623f\u5b501\uff0c\u7136\u540e\u623f\u5b502\uff0c\u7136\u540e\u623f\u5b503\uff0c\u7136\u540e\u770b\u770b\u54ea\u4e2a\u8d77\u4f5c\u7528\u3002\u4f60\u5fc5\u987b\u5f88\u806a\u660e\uff0c\u8ba1\u7b97\u51fa\u3001\u89e3\u51b3\u3001\u60f3\u51fa\uff0c\u600e\u6837\u505a\u8fd9\u4e9b\u63a8\u7406\uff0c\u5e76\u4e14\uff0c\u6211\u4e0d\u60f3\u5c1d\u8bd5\u53d8\u5f97\u90a3\u4e48\u806a\u660e\u3002\u6211\u60f3\u770b\u770b\uff0c\u901a\u8fc7\u4ec5\u4ec5\u5c1d\u8bd5\u6240\u6709\u7684\u53ef\u80fd\u6027\uff0c\u5982\u679c\u6211\u80fd\u5f97\u5230\uff0c\u8ba9\u8ba1\u7b97\u673a\u505a\u8fd9\u4ef6\u4e8b\uff0c\u6240\u4ee5\u6211\u4e0d\u7528\u8fd9\u6837\u505a\u3002\u6240\u4ee5\uff0c\u8ba9\u6211\u4eec\u8fbe\u5230\u90a3\u4ef6\u4e8b\uff0c\u5e76\u4e14\uff0c\u8ba9\u6211\u4eec\u8bf4\uff0c\u6211\u4eec\u5c06\u5c1d\u8bd5\u6240\u6709\u7684\u53ef\u80fd\u6027\u3002<\/p>\n

\u5e76\u4e14\uff0c\u6240\u4ee5\uff0c\u9996\u5148\u6211\u4eec\u628a\u82f1\u56fd\u4eba\u653e\u8fdb\u623f\u5b501\uff0c\u5e76\u4e14\uff0c\u7a0d\u540e\uff0c\u6211\u4eec\u5c06\u5c1d\u8bd5\u628a\u4ed6\u653e\u8fdb\u623f\u5b502\u30013\u30014\u30015\u3002\u73b0\u5728\uff0c\u897f\u73ed\u7259\u4eba\u600e\u4e48\u6837\uff1f\u5982\u679c\u82f1\u56fd\u4eba\u5728\u623f\u5b501\uff0c\u5bf9\u4e8e\u897f\u73ed\u7259\u4eba\uff0c\u6211\u4eec\u5e94\u8be5\u5c1d\u8bd5\u4ec0\u4e48\u53ef\u80fd\u6027\uff1f\u7ed9\u6211\u4f60\u6700\u597d\u7684\u56de\u7b54\uff1a<\/p>\n

\u25a1 1,2,3,4,5 \u25a1 1 \u25a1 2 \u25a0 2,3,4,5<\/code><\/pre>\n

3. \u7ec3\u4e60\uff1aCounting Assignments <\/h4>\n

Counting Assignments - Design of Computer Programs - YouTube<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u57285\u4e2aproperties\u76841\u4e2aclass\u91cc\u9762\uff0c\u8fd9\u4e2aclass\u5fc5\u987b\u8986\u76d65\u4e2a\u623f\u5b50\uff0c\u4f46\u662f\u662f\u4ee5\u4efb\u4f55\u987a\u5e8f\u3002\u6211\u4eec\u53ef\u4ee5\u4ee5\u591a\u5c11\u79cd\u65b9\u5f0f\u505a\u90a3\u79cd\u5206\u914d\uff1f\u6362\u53e5\u8bdd\u8bf4\uff0c\u8fd9\u91cc\u67095\u79cdproperties\uff0c\u57281\u4e2aproperty group\u91cc\u9762\uff0c\u5e76\u4e14\uff0c\u8fd9\u91cc\u67091\u4e2a\u53ef\u80fd\u7684\u5206\u914d\u3002<\/p>\n

\u6709\u591a\u5c11\u79cd\u5206\u914d\u8fd9\u4e9bproperties\u7684\u4e0d\u540c\u5206\u914d\u65b9\u5f0f\uff1f\u5e76\u4e14\uff0c\u628a\u5b83\u4eec\u548c\u623f\u5b50\u5339\u914d\u8d77\u6765\uff1f<\/p>\n

\"\u300aDesign<\/p>\n

\u25a1 5 \u25a1 5\u7684\u5e73\u65b9 <\/span>= 25 \u25a1 2\u76845\u6b21\u65b9 = 32 \u25a0 5! = 120<\/span><\/code><\/pre>\n

\u6211\u7684\u7406\u89e3\uff1a
\u7b2c1\u4e2a\u623f\u5b50\u67095\u79cd\u9009\u62e9\uff0c\u7b2c1\u4e2a\u623f\u5b50\u653e\u597d\u4e86\u989c\u8272\u4e4b\u540e\uff0c\u7b2c2\u4e2a\u623f\u5b50\u5c31\u53ea\u67094\u79cd\u9009\u62e9\u4e86\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u5206\u914d\u65b9\u5f0f\u516c\u67095 x 4 x 3 x 2 x 1 = 120\u79cd\u3002<\/p>\n

4. \u7ec3\u4e60\uff1aMultiple Properties <\/h4>\n

Multiple Properties - Design of Computer Programs - YouTube<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u4f46\u662f\uff0c\u6211\u4eec\u4e0d\u662f\u53ea\u67091\u4e2aproperty class\uff1b\u6211\u4eec\u67095\u4e2aproperty classes\u3002\u6211\u4eec\u6709\u56fd\u7c4d\u3001\u5ba0\u7269\u3001\u7b49\u7b49\u3002\u5e76\u4e14\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u6211\u4eec\u60f3\u521b\u5efa\u6240\u6709\u4e0d\u540c\u7684\u65b9\u5f0f\uff0c\u5c06\u6240\u6709\u76845\u79cdproperties\u5206\u914d\u7ed95\u4e2a\u623f\u5b50\uff0c\u6240\u4ee5\uff0c\u6bcf1\u4e2a\u623f\u5b50\u5c06\u4f1a\u67091\u4e2a\u989c\u8272\u30011\u4e2a\u56fd\u7c4d\u30011\u4e2a\u5ba0\u7269\uff0c\u7b49\u7b49\u3002\u5728\u8fdb\u884c\u5206\u914d\u7684\u6bcf1\u79cd\u53ef\u80fd\u7684\u65b9\u5f0f\u4e2d\uff0c\u6570\u91cf\u662f\u591a\u5c11\uff1f<\/p>\n

\u25a1 5<\/span> X<\/span> 5<\/span>!<\/span> \u25a1 (5<\/span>!<\/span>)\u7684\u5e73\u65b9 \u25a0 (5<\/span>!<\/span>)\u76845<\/span>\u6b21\u65b9 \u25a1 5<\/span>!<\/span>!<\/span><\/code><\/pre>\n

\u6211\u7684\u7406\u89e3\uff1a\u5bf9\u4e8e5\u4e2a\u623f\u5b50\uff0c\u6bcf1\u79cdproperty\u7684\u53ef\u80fd\u7684\u65b9\u5f0f\u90fd\u662f5!\uff0c\u73b0\u5728\u67095\u79cdproperties\uff0c\u6240\u4ee5\uff0c\u5171\u67095!\u76845\u6b21\u65b9\u3002<\/p>\n

5. \u7ec3\u4e60\uff1aBack Of The Envelope <\/h4>\n

Back Of The Envelope - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

approximately adv.\u8fd1\u4f3c\u5730\uff0c\u5927\u7ea6<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

(5!)\u76845\u6b21\u65b9\uff0c\u5927\u7ea6\u662f\u591a\u5c11\uff1f<\/p>\n

\u25a1 1 million \u25a0 20 billion \u25a1 5 trillion<\/code><\/pre>\n

Peter\u7684\u4f30\u7b97\u65b9\u6cd5\uff1a
5!\u662f120\u3002\u8ba9\u6211\u4eec\u5bf9120\u53d6\u6574\u5230100\u3002100\u76845\u6b21\u65b9\u7b49\u4e8e100,0000,0000\uff0c\u4e5f\u5c31\u662f10billion\u3002\u5e76\u4e14\uff0c\u6211\u4eec\u8981\u505a\u53d6\u6574\u7684\u9006\u5411\u64cd\u4f5c\uff0c\u53ef\u80fd\u662f20billion\u7684\u67d0\u4e2a\u4f4d\u7f6e\u3002\u5b9e\u9645\u7b97\u51fa\u7684\u7ed3\u679c\u662f24.9billion\uff0c\u6240\u4ee5\uff0c\u90a3\u4e0d\u662f\u4e2a\u574f\u7684\u4f30\u8ba1\u3002<\/p>\n

6. \u7ec3\u4e60\uff1aLeaving Happy Valley <\/h4>\n

Leaving Happy Valley - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

infeasible adj.\u4e0d\u53ef\u5b9e\u884c\u7684<\/p>\n

brute force approach \u86ee\u529b\u8ba1\u7b97\u6cd5<\/p>\n

contour
n.\u5916\u5f62\uff0c\u8f6e\u5ed3\uff1b\u6982\u8981
adj.\u663e\u793a\u8f6e\u5ed3\u7684\uff1b<\/p>\n

peak n.\u6700\u9ad8\u70b9\uff1b\u5c16\u7aef<\/p>\n

wilderness n.\u8352\u91ce\uff1b\u4ee4\u4eba\u56f0\u60d1\u7684\u4e1c\u897f<\/p>\n

in terms of \u6839\u636e\uff1b\u7528\u2026\u7684\u8bdd\uff1b\u5c31\u2026\u800c\u8a00<\/p>\n

concrete n.\u5177\u4f53\u7684\uff0c\u5b9e\u9645\u7684<\/p>\n

deep down \u5728\u5185\u5fc3\u6df1\u5904<\/p>\n

somehow \u4ee5\u67d0\u79cd\u65b9\u5f0f\uff0c\u7528\u67d0\u79cd\u65b9\u6cd5<\/p>\n

proof n.\u8bc1\u660e\uff1b\u68c0\u9a8c<\/p>\n

be up to \u80dc\u4efb\uff0c\u4ece\u4e8b\u4e8e<\/p>\n

simultaneously adv.\u540c\u65f6\u5730\uff1b\u4e00\u9f50<\/p>\n

go through \u901a\u8fc7\uff1b\u68c0\u67e5\uff1b\u5b8c\u6210<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u6211\u4eec\u73b0\u5728\u5728\u8fd9\u4e2arange\u91cc\u9762\uff0c\u6211\u4eec\u53ef\u80fd\u53ef\u4ee5\u5b8c\u6210\uff0c\u4f46\u662f\u6211\u4eec\u4e0d\u786e\u5b9a\u3002\u6211\u4eec\u7684\u8ba1\u7b97\u673a\u6bcf\u79d2\u80fd\u591f\u505a\u5927\u7ea610\u4ebf\u7684\u6307\u4ee4\uff0c\u6216\u8005\uff0c\u57281\u4e2a\u597d\u7684\u79d2\u4e0a\u9762\u2014\u2014\u90a3\u5c31\u662f\uff0c\u5b83\u4eec\u6ca1\u6709\u6d6a\u8d39\u8fd91\u79d2\uff0c\u9875\u9762\u9519\u8bef\u6216\u8005cache miss\u3002\u5982\u679c\u7b54\u6848\u5df2\u7ecf\u8f6c\u53d8\u6210\u5728millions\u91cc\u9762\uff0c\u6211\u4eec\u53ef\u4ee5\u8bf4\uff0c\u201c\u597d\u6781\u4e86\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u3002\u201d\u5982\u679c\u8f6c\u53d8\u6210\u5728trillions\u91cc\u9762\uff0c\u6211\u4eec\u4f1a\u8bf4\uff0c\u201c\u8fd9\u5b8c\u5168\u662f\u4e0d\u53ef\u884c\u7684\u3002\u6211\u4eec\u9700\u89811\u4e2a\u66f4\u597d\u7684\u89e3\u51b3\u65b9\u6848\u3002\u201d\u4f46\u662f\uff0c\u5982\u679c\u5b83\u5728billions\u4e2d\u95f4\u7684\u67d0\u4e2a\u5730\u65b9\uff0c\u7136\u540e\u6211\u4eec\u4e0d\u662f\u5f88\u786e\u5b9a\u3002\u6211\u4eec\u6700\u597d\u5c1d\u8bd5\uff0c\u91cd\u65b0\u5b9a\u4e49\u8fd9\u4e2a\u7ed3\u679c\uff0c\u4e00\u70b9\u4e00\u70b9\u5730\uff0c\u6765\u544a\u77e5\uff0c\u8fd9\u4e2a\u86ee\u529b\u89e3\u5c06\u662f\u5426\u53ef\u4ee5\u8d77\u4f5c\u7528\u3002<\/p>\n

\u5e76\u4e14\uff0c\u6839\u636e\u6267\u884c\u65f6\u95f4\uff0c\u50cf1\u4e2a\u8f6e\u5ed3\u56fe\u4e00\u6837\uff0c\u8003\u8651\u8fd9\u4e2a\u89e3\u51b3\u65b9\u6848\u7684\u7a7a\u95f4\u3002\u5e76\u4e14\uff0c\u5728valley\u7684\u8fd9\u91cc\u7684\u5185\u5fc3\u6df1\u5904\uff0c\u53ea\u6709millions\u6761\u6307\u4ee4\u9700\u8981\uff0c\u53bb\u5b8c\u6210\u8fd9\u4e2a\u7b54\u6848\uff0c\u7136\u540e\u6211\u4eec\u771f\u7684\u5f00\u5fc3\uff0c\u56e0\u4e3a\u6211\u4eec\u77e5\u9053\u90a3\u4f1a\u8fd0\u884c\u5730\u975e\u5e38\u5feb\u3002\u5e76\u4e14\uff0c\u5728happy valley\u4e4b\u5916\uff0c\u6709\u8fd9\u4e9b\u9ad8\u7684\u5c16\u7aef\u70b9\uff0c\u6211\u4eec\u6709trillions\u6761\u8ba1\u7b97\u9700\u8981\uff0c\u5e76\u4e14\uff0c\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u4f1a\u4f24\u5fc3\u3002\u5982\u679c\u6211\u4eec\u56f0\u5728\u5916\u9762\u8fd9\u4e9b\u57df\u91cc\u9762\uff0c\u6211\u4eec\u5c06\u5fc5\u987b\u4ee5\u67d0\u79cd\u65b9\u5f0f\uff0c\u627e\u52301\u4e2a\u8def\u5f84\u8fdb\u5165\uff0c\u56e0\u4e3a\u6211\u4eec\u4e0d\u80fd\u4ec5\u4ec5\u76f4\u63a5\u4e0a\u3001\u8ba1\u7b97\uff0c\u5f53\u6211\u4eec\u5728\u5916\u9762trillions\u65f6\u3002\u5728\u4e2d\u95f4\u8fd9\u91cc\uff0c\u6211\u4eec\u9700\u8981billions\u6761\u6307\u4ee4\uff0c\u53bb\u5b8c\u6210\u6211\u4eec\u7684\u8ba1\u7b97\uff0c\u7136\u540e\u6211\u4eec\u4e0d\u662f\u5f88\u786e\u5b9a\u3002\u53ef\u80fd\u6211\u4eec\u5728\u8fd9\u91cc\u5f88\u5f00\u5fc3\uff0c\u5e76\u4e14\u6211\u4eec\u53ef\u4ee5\u5f85\u5728\u8fd9\u4e2a\u57df\u91cc\u9762\u3002\u53ef\u80fd\u6211\u4eec\u60f3\u627e\u5230\u6211\u4eec\u7684\u8def\u5f84\uff0c\u901a\u8fc7\u4ee4\u4eba\u56f0\u60d1\u7684\u80cc\u540e\uff0c\u8fdb\u5165happy valley\u3002\u8fd9\u53d6\u51b3\u4e8e\u95ee\u9898\u3002\u5e76\u4e14\u6211\u4eec\u5c06\u5c1d\u8bd5\uff0c\u6839\u636e\u8fd9\u4e2a\u7a7a\u95f4\uff0c\u770b\u5f85\u95ee\u9898\uff0c\u5c1d\u8bd5\u627e\u5230\u6211\u4eec\u7684\u8def\u5f84back\u8fdb\u5165\uff0c\u4f46\u662f\u77e5\u9053\u5408\u9002\u505c\u6b62\uff0c\u5f53\u6211\u4eec\u5df2\u7ecf\u8db3\u591f\u63a5\u8fd1\u7684\u65f6\u5019\u3002<\/p>\n

\"\u300aDesign<\/p>\n

\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u4fdd\u6301\u601d\u8003\uff0c\u8fdb\u884c\u4e00\u4e2a\u5206\u914d\uff0c\u610f\u5473\u7740\u4ec0\u4e48\u3002\u5173\u4e8e\u5b83\uff0c\u5c1d\u8bd5\u66f4\u5177\u4f53\u4e9b\u3002\u5982\u679c\u6211\u4eec\u60f3\u5206\u914dred\u7ed9\u623f\u5b50\u53f7\u78011\uff0c\u8ba9\u6211\u4eec\u60f3\u60f3\uff0c\u6211\u4eec\u80fd\u591f\u4ee5\u54ea\u4e9b\u65b9\u5f0f\u5b9e\u73b0\u3002\u8fd9\u91cc\u67091\u79cd\u53ef\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u8bf4\uff0c\u6211\u4eec\u5c06\u67091\u4e2a\u5173\u4e8e\u623f\u5b50\u7684\u6570\u7ec4\u3001\u6392\u5217(an array of houses)\u3002\u6211\u4eec\u53d6\u5f97\u65701\uff0c\u5e76\u4e14\uff0c\u6211\u4eec\u628ared\u589e\u52a0\u5230\u5b83\u7684properties\u96c6\u5408\u4e0a\u3002\u90a3\u610f\u5473\u7740\uff0c\u6bcf1\u4e2a\u623f\u5b50\u88ab\u8868\u793a\u4e3a1\u4e2a\u96c6\u5408(set)\u3002\u8fd9\u91cc\u6709\u53e6\u4e00\u4e2a\u53ef\u80fd\u6027\uff0c\u6211\u4eec\u53d6\u5f97\u65701\uff0c\u6211\u4eec\u8bbe\u7f6e\u5b83\u7684\u989c\u8272\u5c5e\u6027property\u7b49\u4e8ered\u3002\u8fd9\u91cc\u6bcf1\u4e2a\u623f\u5b50\u5c06\u5fc5\u987b\u88ab\u8868\u793a\u4e3a1\u4e2a\u7528\u6237\u5b9a\u4e49\u7684custom class(\u5b50\u7c7b\uff1f)\uff0c\u6709\u7740\u989c\u8272\u548c\u56fd\u7c4d\u7b49\u7b49\u5c5e\u6027(properties)\u3002\u8fd9\u91cc\u6709\u7b2c3\u4e2a\u53ef\u80fd\u6027\u3002\u6211\u4eec\u67091\u4e2a\u53d8\u91cf\uff0c\u53eb\u505ared\uff0c\u6211\u4eec\u4ec5\u4ec5\u5206\u914d\u90a3\u4e2a\u6570\u4e3a1\u3002\u6240\u4ee5\uff0c\u8fd9\u91cc\uff0c\u6211\u4eec\u628a\u5c5e\u6027properties\u5206\u914d\u7ed9\u623f\u5b50houses\uff0c\u5e76\u4e14\uff0c\u5728\u8fd9\u4e2a\u91cc\u9762\uff0c\u6211\u4eec\u628ahouses\u5206\u914d\u7ed9\u4e86\u5c5e\u6027properties\u3002<\/p>\n

\u73b0\u5728\uff0c\u6211\u60f3\u8981\u4f60\u68c0\u67e5\u6240\u6709\u7684\u65b9\u6cd5\uff0c\u4f60\u8ba4\u4e3a\u4f1a\u662f\u5408\u7406\u7684\u8bbe\u8ba1\uff0c\u7528\u4e8e\u5b9e\u73b0\u5206\u914d\u3002<\/p>\n

\u25a0 house[1<\/span>], add<\/span>('red'<\/span>) set<\/span>() \u96c6\u5408 \u25a0 house[1<\/span>], color = 'red'<\/span> House() \u5b50\u7c7b \u25a0 red = 1<\/span><\/code><\/pre>\n

\u6211\u7684\u60f3\u6cd5\uff1a
\u7528\u7b2c2\u4e2a\u7b54\u6848\uff0c\u7c7b\u6765\u7ba1\u7406\u5c5e\u6027\u3002<\/p>\n

Peter\u7684\u7b54\u6848\uff1a
3\u4e2a\u90fd\u53ef\u4ee5\uff0c\u4f46\u662f\u6700\u597d\u7528\u7b2c3\u4e2a\uff0c\u56e0\u4e3a\u591f\u7b80\u5355\u3002\u6240\u4ee5\u6211\u5c06go with\u90a3\u4e2a\uff0c\u76f4\u5230\u6211\u80fd\u8bc1\u660e\u90a3\u4e2a\u7b80\u5355\u7684\uff0c\u4e0d\u8d77\u4f5c\u7528\uff0c\u5e76\u4e14\uff0c\u6211\u4eec\u5c06go to\u66f4\u590d\u6742\u7684\u4e00\u4e9b\u4e1c\u897f\u3002<\/p>\n

\u73b0\u5728\uff0c\u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u547d\u540d\u4e86properties\u3002\u6211\u4eec\u8ba8\u8bba\u4e86\uff0c\u4f60\u662f\u5426\u5fc5\u987b\u505a\u90a3(\u6307\u6700\u7b80\u5355\u7684\u90a3\u4e2a)\u7684\u53ef\u80fd\u6027\u3002\u8fd9\u91cc(\u6700\u7b80\u5355\u7684red = 1)\uff0c\u6211\u4eec\u6ca1\u6709\u547d\u540d\u5b83\u4eec\uff0c\u5e76\u4e14\uff0c\u6240\u4ee5\uff0c\u5b83\u4f1a\u80dc\u4efb\u4f5c\u4e3a\u7a0b\u5e8f\u5458\u3001\u53bb\u7ba1\u7406\u5c5e\u6027\u7ec4(the groups of properties)\u3002\u8fd9\u91cc\u67091\u79cd\u65b9\u5f0f\uff0c\u6211\u53ef\u4ee5\u505a\u5b83\u3002<\/p>\n

\u6211\u53ef\u4ee5\u540c\u65f6\u5730\u5206\u914d\u8fd95\u4e2a\u5c5e\u6027(properties)\uff0c\u8fd95\u4e2a\u5c5e\u6027\uff0c\u57285\u4e2a\u623f\u5b50\u7684\u989c\u8272\u7684\u76f8\u540c\u7684\u7ec4\u4e2d\u3002
(red, green, ivory, yellow, blue) = [1, 2, 3, 4, 5]<\/code>\u5f53\u7136\uff0c\u8fd9\u53ea\u4f1a\u662f1\u79cd\u53ef\u80fd\u7684\u5206\u914d\u3002\u5728\u6211\u5c1d\u8bd5\u4e86\u8fd9\u4e2a\u4e4b\u540e\uff0c\u6211\u5c06\u5fc5\u987b\u5c1d\u8bd5\u53e6\u4e00\u4e2a\u5206\u914d\u2014\u2014\u53ef\u80fd\u662f[1, 3, 2, 4, 5]<\/code>\u2014\u2014\u5e76\u4e14\uff0c\u6211\u5c06\u5fc5\u987b\u68c0\u67e5\u6240\u6709\u7684\u53ef\u80fd\u6027\u3002\u4f60\u80fd\u60f3\u51fa\u90a3\u6837\u505a\u76841\u4e2a\u597d\u7684\u65b9\u5f0f\u5417\uff1f\u4ec0\u4e48\u58f0\u660e(statement \u58f0\u660e\uff1b\u9648\u8ff0)\u6216\u8005\u5176\u4ed6\u7684\u5b9e\u73b0\uff0c\u4f60\u53ef\u4ee5\u63d0\u51fa\u6765\uff0c\u4ee5\u4f7f\u5f97\u8fd95\u79cd\u5c5e\u6027properties\u3001\u68c0\u67e5\u6240\u6709\u7684\u53ef\u80fd\u7684\u623f\u5b50\u7684\u7ec4\u5408\uff1f<\/p>\n

7. \u7ec3\u4e60\uff1aOrdering Houses <\/h4>\n

\u5bf9\u623f\u5b50\u8fdb\u884c\u6392\u5e8f
Ordering Houses - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

state vt.\u9648\u8ff0\uff0c\u58f0\u660e\uff1b\u89c4\u5b9a<\/p>\n

permutation n.\u6392\u5217\uff0c\u5e8f\u5217<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u8fd9\u91cc\u6709\u4e2a\u89e3\u51b3\u529e\u6cd5\u3002<\/p>\n

\u9996\u5148\uff0c\u6211\u4eec\u5c06\u5b9a\u4e49\u8fd9\u4e9b\u623f\u5b50\u3002say\u8fd9\u91cc\u67095\u4e2a\u623f\u5b50\u3002\u5728\u95ee\u9898\u4e2d\uff0c\u65701\u88ab\u58f0\u660e\u3002
\u7136\u540e\u6211\u4eec\u4f1a\u8bf4\uff0corderings\u662f\u8fd9\u4e9b\u623f\u5b50\u7684\u53ef\u80fd\u7684\u987a\u5e8f\u7684\u4e00\u4e9b\u96c6\u5408\uff0c\u6240\u4ee5[1, 2, 3, 4, 5]<\/code>\u5c06\u4f1a\u662forderings\u76841\u4e2a\u5143\u7d20\uff0c[2, 1, 3, 4, 5]<\/code>\u5c06\u4f1a\u662f\u53e6\u4e00\u4e2a\u5143\u7d20\uff0c\u7b49\u7b49\u3002
\u5e76\u4e14\uff0c\u7136\u540e\uff0c\u6211\u4eec\u4ec5\u4ec5\u4f7f\u75281\u4e2afor\u58f0\u660e\uff0c\u4ee5\u5728property group\u4e2d\uff0c\u8fed\u4ee3\u8fd95\u4e2a\u53d8\u91cf\uff0cthrough\u6240\u6709\u53ef\u80fd\u7684orderings\uff0c\u5e76\u4e14\u7136\u540e\u653e\u8fdb\u8fd9\u91cc\u6211\u4eec\u7684\u4ee3\u7801\u3002<\/p>\n

\u73b0\u5728\uff0c\u95ee\u9898\u662f\uff0c\u51fd\u6570F\u7ed9\u4e86\u6211\u4eec\u6240\u6709\u7684orderings\uff0c\u51fd\u6570F\u662f\u4ec0\u4e48\uff1f\u662f\u6392\u5217\u51fd\u6570(permutation functions)\u3001\u7ec4\u5408\u51fd\u6570(combination functions)\u3001\u9636\u4e58\u51fd\u6570(factorial functions)\u3001\u6216\u8005\u5176\u4ed6\u4ec0\u4e48\uff1f<\/p>\n

permutation functions \u8fd9\u4e2a combination functions factorial<\/span> functions else<\/span><\/code><\/pre>\n

Peter\u7684\u7b54\u6848\uff1a
permutation functions\u3002\u90a3\u4e2a\u6240\u6709\u53ef\u80fd\u7684orderings\u7684\u5b9a\u4e49\uff0c\u88ab\u79f0\u4e3apermutations\u3002<\/p>\n

8. \u7ec3\u4e60\uff1aLength Of Orderings <\/h4>\n

Length Of Orderings - Design of Computer Programs - YouTube<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u7ed3\u679c\u662f\uff0cPython\u6709\u4e00\u4e2apermutation\u51fd\u6570\u5728itertools\u6a21\u7ec4\u4e2d\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5import\u90a3\u4e2a\uff0c\u6216\u8005\u4f60\u53ef\u4ee5\u81ea\u5df1\u5199\u4e00\u4e2a\u3002\u5982\u679c\u4f60\u505a\u4e86\u90a3\u4e2a\uff0corderings\u7684\u957f\u5ea6\u4f1a\u662f\u4ec0\u4e48\uff1f<\/p>\n

Peter\u7684\u7b54\u6848\uff1a
\u7b54\u6848\u662f120\uff0c\u6216\u80055!\u3002<\/p>\n

9. \u7ec3\u4e60\uff1aEstimating Runtime <\/h4>\n

Estimating Runtime - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

arrange vt.\u6574\u7406\uff1b\u628a\u2026\u5206\u7c7b<\/p>\n

constraint n.\u9650\u5236\uff1b\u7ea6\u675f<\/p>\n

check out \u83b7\u5f97\u8bc1\u660e\uff1b\u5f97\u5230\u8bc1\u5b9e<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u8865\u5145\uff1apermutations()\u51fd\u6570\u7684\u7528\u6cd5\u3002<\/p>\n

\u73b0\u5728\uff0c\u5047\u8bbe\u6211\u4eec\u6574\u7406\u6211\u4eec\u7684\u7a0b\u5e8f\u50cf\u8fd9\u6837\u3002<\/p>\n

import<\/span> itertools houses = [1<\/span>, 2<\/span>, 3<\/span>, 4<\/span>, 5<\/span>] orderings = list(itertools.permutations(houses)) for<\/span> (red, green, ivory, yellow, blue) in<\/span> orderings: for<\/span> (Englishman, Spaniard, Ukrianian, Japanese, Norwegian) in<\/span> orderings: for<\/span> (dog, snails, fox, horse, ZEBRE) in<\/span> orderings: for<\/span> (coffee, tea, milk, oj, WATER) in<\/span> orderings: for<\/span> (OldGold, Kools, Chesterfields, LuckyStrike, Parliaments) in<\/span> orderings: # constraints go here<\/span> # 1 sec<\/span> # 1 min<\/span> # 1 hour is right<\/span> # 1 day<\/span><\/code><\/pre>\n

\u6211\u4eec\u8bbe\u7f6e\u4e86houses\uff0c\u6211\u4eec\u6709\u6240\u6709120\u4e2d\u53ef\u80fd\u7684orderings\u76841\u4e2a\u5217\u8868\uff0c\u5e76\u4e14\uff0c\u7136\u540e\uff0c\u6211\u4eec\u57284\u4e2aproperty group\u4e2d\uff0c\u8fed\u4ee35\u4e2aproperties\u4e2d\u7684\u6bcf1\u4e2a\uff0cthrough all those orderings\u3002\u5e76\u4e14\uff0c\u6240\u6709\uff0c\u73b0\u5728\uff0c5\u7ea7\u5d4c\u5957\u6df1\u5165\u6211\u4eec\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u5df2\u7ecf\u5f97\u5230\u4e86\u6240\u670925\u79cdproperties\u76841\u4e2a\u5206\u914d\u3002\u5b83\u4eec\u4e2d\u7684\u6bcf1\u4e2a\u90fd\u88ab\u5206\u914d\u7ed9\u8fd9\u4e9b\u623f\u5b50\u76841\u4e2a\uff0c\u5e76\u4e14\uff0c\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u68c0\u67e5\u7ea6\u675f\uff0c\u6bd4\u5982\uff0c\u82f1\u56fd\u4eba\u4f4f\u5728red house\u91cc\u9762\uff0c\u897f\u73ed\u7259\u4eba\u62e5\u6709\u72d7\uff0c\u7b49\u7b49\u3002\u90a3\u4e9b\u5168\u90fd\u53ef\u4ee5go there\u3002\u5982\u679c\u6211\u4eec\u53d1\u73b0\u6709\u4e9b\u4e8b\u60c5\u5f97\u5230\u8bc1\u5b9e\uff0c\u6211\u4eec\u53ef\u4ee5\u4ec5\u4ec5\u62a5\u544a\uff0c\u6211\u4eec\u5f97\u5230\u4e861\u4e2a\u7b54\u6848\u3002\u73b0\u5728\uff0c\u6211\u60f3\u8981\u4f60\u56de\u5230\u4f60\u7684\u4fe1\u5c01\u80cc\u9762\uff0c\u5e76\u4e14\uff0c\u544a\u8bc9\u6211\uff0c\u5982\u679c\u6211\u4eec\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u5199\u8fd9\u4e2a\u7a0b\u5e8f\uff0c\u5e76\u4e14\uff0c\u7528\u6240\u6709\u8fd9\u4e9b\u7ea6\u675f\u586b\u5145\u8fd9\u4e2a\u4ee3\u7801\uff0c\u5e76\u4e14\u8fd0\u884c\u5b83\uff0c\u4f60\u8ba4\u4e3a\uff0c\u5b83\u5927\u6982\u4f1a\u82b1\u591a\u4e45\uff0c\u627e\u52301\u4e2a\u89e3\u51b3\u529e\u6cd5\uff1f\u5927\u7ea61\u79d2\u30011\u5206\u949f\u30011\u4e2a\u5c0f\u65f6\u3001\u8fd8\u662f1\u5929\uff1f<\/p>\n

10. \u7ec3\u4e60\uff1aRed Englishman <\/h4>\n

Red Englishman - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

gigahertz n.\u5146\u8d6b\u5179<\/p>\n

fairly adv.\u76f8\u5f53\u5730\uff1b\u5b8c\u5168\uff1b\u6e05\u695a\u5730<\/p>\n

typical adj.\u5178\u578b\u7684\uff1b\u4ee3\u8868\u6027\u7684<\/p>\n

ridiculous adj.\u8352\u5510\u7684\uff0c\u611a\u8822\u7684<\/p>\n

all the way \u4e00\u8def\u4e0a\uff0c\u4e00\u76f4\uff0c\u5b8c\u5168\uff1b<\/p>\n

definitely adv.\u660e\u786e\u5730\uff1b\u786e\u5207\u5730\uff1b\u80af\u5b9a\u5730<\/p>\n

somehow adv.\u4ee5\u67d0\u79cd\u65b9\u5f0f\uff0c\u7528\u67d0\u79cd\u65b9\u6cd5<\/p>\n

figure out \u8ba1\u7b97\u51fa\uff1b\u89e3\u51b3\uff1b\u60f3\u51fa<\/p>\n

aside adv.\u5728\u65c1\u8fb9\uff1b\u65c1\u767d\uff1b\u79bb\u9898\u8bdd<\/p>\n

be sort of \u6709\u70b9<\/p>\n

identically adv.\u76f8\u7b49\u5730\uff0c\u540c\u4e00\u5730<\/p>\n

turn out \u7ed3\u679c\u662f\uff1b\u5173\u6389\uff1b\u5236\u9020<\/p>\n

identical \u540c\u4e00\u7684\uff1b\u76f8\u540c\u7684<\/p>\n

differ by \u4e0e\u2026\u76f8\u5dee<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

(5!)\u76845\u6b21\u65b9\uff0c\u662f240\u4ebf(24billion)\u3002\u5e76\u4e14\uff0c\u5982\u679c\u6211\u4eec\u5047\u8bbe\u6211\u4eec\u67091\u4e2a2.4GHz\u7684\u8ba1\u7b97\u673a\uff0c\u5b8c\u5168\u5177\u6709\u4ee3\u8868\u6027\uff0c\u7136\u540e\u5982\u679c\uff0c\u8fd9\u5168\u90e8\u53ef\u4ee5\u88ab\u7f16\u8bd1\u8fdb1\u6761\u8ba1\u7b97\u673a\u6307\u4ee4\uff0c\u7136\u540e\uff0c\u5b83\u4f1a\u82b110\u79d2\u3002\u4f46\u662f\uff0c\u5f53\u7136\uff0c\u90a3\u662f\u8352\u5510\u7684\u3002\u4f60\u4e0d\u4f1a\u505a\u6240\u6709\u7684\u90a3\u4e9b\uff0c\u57281\u6761\u6307\u4ee4\u91cc\u9762\u3002\u5982\u679c\u5b83\u662f100\u6761\u6307\u4ee4\uff0c\u7136\u540e\u90a3\u610f\u5473\u7740\uff0c\u5b83\u4f1a\u662f1000\u79d2\uff0c\u5927\u6982\u662f16\u5206\u949f\uff0c\u4f46\u662f\uff0c\u90a3\u770b\u8d77\u6765\u592a\u77ed\u3002\u5b83\u53ef\u80fd\u5c06\u662f\u66f4\u50cf1000\u6761\u6307\u4ee4\uff0c\u901a\u8fc7\u4e00\u76f4\u505a\u6240\u6709\u8fd9\u4e9b(\u6307\u51e0\u4e2afor\u5faa\u73af)\u3001\u53bb\u5b8c\u6210\u5b83\uff0c\u5e76\u4e14\uff0c\u7136\u540e\uff0c\u68c0\u67e5\u7ea6\u675f\uff0c\u5e76\u4e14\uff0c\u6240\u4ee5\uff0c\u90a3\u5c06\u662f\u5927\u7ea6160\u5206\u949f\u3002\u5e76\u4e14\uff0c\u6240\u4ee51\u5c0f\u65f6\u52303\u5c0f\u65f6\u3002\u6211\u4eec\u5c06\u53ef\u80fd\u8bf4\uff0c2\u62163\u4e2a\u5c0f\u65f6\uff0c\u5728\u90a3\u91cc\u7684\u67d0\u4e2a\u5730\u65b9\u3002\u53ef\u80fd\u662f1\u5c0f\u65f6\u5de6\u53f3\u3002\u6211\u4eec\u4e0d\u80fd\u771f\u5b9e\u5730\u8bf4\u660e\uff0c\u56e0\u4e3a\u8fd9\u53ea\u662f1\u4e2a\u4f30\u7b97\u3002\u4f46\u662f\uff0c\u5b83\u80af\u5b9a\u5c06\u4f1a\u662f\u5728\u5c0f\u65f6\u8303\u56f4\u5185\uff0c\u4e0d\u662f\u5728\u5206\u949f\u6216\u8005\u5929\u8303\u56f4\u5185\u3002<\/p>\n

\u5b9e\u9645\u4e0a\uff0c\u6211\u786e\u5b9e\u8fd0\u884c\u4e86\u8fd9\u4e2a\u7a0b\u5e8f\uff0c\u5e76\u4e14\uff0c\u7a0d\u540e\uff0c\u6211\u4eec\u5c06\u4f1a\u56de\u6765\uff0c\u5e76\u4e14\uff0c\u770b\u770b\uff0c\u5728\u90a3\u91cc\uff0c\u4ee5\u67d0\u79cd\u65b9\u5f0f\u7684\u8fd9\u4e2a\u4f30\u8ba1\uff0c\u4f1a\u591a\u597d\u5730\u89e3\u51b3\u3002<\/p>\n

\u8ba9\u6211\u53ea\u662f\u8bf4\uff0c\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u5b66\u4e60\u4e86\uff0c\u8fd9\u4f1a\u82b1\u8d39\uff0c\u4ee5\u67d0\u79cd\u65b9\u5f0f\u7684\u4e00\u5c0f\u65f6\u7684\u8303\u56f4\uff0c\u4e0d\u8981\u5c1d\u8bd5\u5728\u8fd9\u91cc(\u6307Udacity\u7f51\u9875)\u8fd0\u884c\uff0c\u56e0\u4e3a\u5728\u51e0\u79d2\u540e\uff0c\u8fd9\u4e2a\u8ba1\u7b97\u4f1a\u8d85\u65f6\u3002<\/p>\n

\u4f46\u662f\uff0c\u9996\u5148\u6211\u4eec\u5fc5\u987b\u60f3\u51fa\uff0c\u600e\u6837\u505a\u6240\u6709\u7684\u7ea6\u675f(constraints)\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u5df2\u7ecf\u505a\u4e86constraint\u65701\uff0c\u8fd9\u91cc\uff0chouses = [1, 2, 3, 4, 5]\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u505aconstraint number 2\uff0c\u8fd9\u91cc\uff0c\u82f1\u56fd\u4eba\u751f\u6d3b\u5728red house\u91cc\u9762\u3002\u5e76\u4e14\uff0c\u6211\u4eec\u60f3\u8981\u5199\u4e00\u4e9bif\u8bed\u53e5\uff0c\u53bb\u68c0\u67e5\u82f1\u56fd\u4eba\u662f\u5426\u751f\u6d3b\u5728red house\u91cc\u9762\uff0c\u5e76\u4e14\uff0c\u5982\u679c\u662f\u8fd9\u6837\uff0c\u6211\u4eec\u7ee7\u7eed\uff1b\u5982\u679c\u4e0d\u662f\uff0c\u6211\uff0c \u653e\u5f03\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u5982\u4f55\u68c0\u67e5\uff0c\u8fd9\u662f\u5426\u662f\u771f\u7684\uff0c\u82f1\u56fd\u4eba\u4f4f\u5728red ouse\u91cc\u9762\uff1f\u6240\u4ee5\uff0c\u5982\u679c\uff0c\u5e76\u4e14\uff0c\u6211\u60f3\u8981\u4f60\u586b\u5165\u4e00\u4e9b\u8868\u8fbe\u5f0f\u5728\u8fd9\u91cc\u3002\u6211\u4eec\u5c06\u4ec5\u4ec5\u8bf4\uff0c\u8fd9\u662fconstraint number 2\u3002\u544a\u8bc9\u6211\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9\u91cc\u586b\u4ec0\u4e48\u3002<\/p>\n

import<\/span> itertools houses = [1<\/span>, 2<\/span>, 3<\/span>, 4<\/span>, 5<\/span>] orderings = list(itertools.permutations(houses)) for<\/span> (red, green, ivory, yellow, blue) in<\/span> orderings: for<\/span> (Englishman, Spaniard, Ukrianian, Japanese, Norwegian) in<\/span> orderings: for<\/span> (dog, snails, fox, horse, ZEBRE) in<\/span> orderings: for<\/span> (coffee, tea, milk, oj, WATER) in<\/span> orderings: for<\/span> (OldGold, Kools, Chesterfields, LuckyStrike, Parliaments) in<\/span> orderings: if<\/span> (Englishman == red): #2<\/span> # 1 sec<\/span> # 1 min<\/span> # 1 hour is right<\/span> # 1 day<\/span><\/code><\/pre>\n

Peter\u7684\u7b54\u6848\uff1a
\u7b54\u6848\u662f\uff0c\u6211\u4eec\u6240\u6709\u5fc5\u987b\u8981\u505a\u7684\u662f\uff0c\u68c0\u67e5\u82f1\u56fd\u4eba\u548cred\u662f\u5426\u5df2\u7ecf\u88ab\u5206\u914d\u4e86\u76f8\u540c\u7684\u623f\u5b50\u53f7\u7801\u3002\u5e76\u4e14\uff0c\u6211\u4eec\u4ec5\u4ec5\u505a\u90a3\u4ef6\u4e8b\uff0c\u8bf4if(Englishman == red)\u3002\u5e76\u4e14\uff0c\u6211\u5e94\u8be5\u6807\u8bb0\u4e3a1\u4e2aaside\uff0c\u5982\u679c\u4f60\u60f3\u8981\u53d8\u5f97\u6709\u70b9\u806a\u660e\uff0c\u5e76\u4e14\u4f7f\u5b83\u770b\u8d77\u6765\u66f4\u50cf\u82f1\u8bed\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u8bf4if (Englishman is red)\uff0c\u56e0\u4e3a\u662f\u68c0\u67e52\u4e2a\u5bf9\u8c61\u662f\u5426\u662f\u76f8\u540c\u7684\u5bf9\u8c61\u3002==<\/code>\u68c0\u67e5\u4ed6\u4eec\u662f\u5426\u662f\u76f8\u540c\u7684\u503c\u3002\u5e76\u4e14\uff0c\u8fd9\u7ed3\u679c\u662f\uff0cPython\u5904\u7406\u5c0f\u7684\u6574\u6570\uff0c\u50cf1\u30012\u30013\u30014\u30015\uff0c\uff0c\u4f5c\u4e3a1\u4e2a\u5355\u72ec\u7684\u76f8\u540c\u7684\u5bf9\u8c61\u3002\u6240\u4ee5\u8fd9\u4e2ais<\/code>\uff0c\u4f1a\u548c\u8fd9\u91ccequals<\/code>\u8d77\u4e00\u6837\u7684\u4f5c\u7528\u3002<\/p>\n

11. \u7ec3\u4e60\uff1aNeighbors <\/h4>\n

Neighbors - Design of Computer Programs - YouTube<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n

\u73b0\u5728\uff0c\u5728\u6211\u4eec\u7ee7\u7eed\u5230constraint number 3\u4e4b\u524d\uff0c\u6211\u60f3\u8981\u5f80\u56de\u8d70\u4e00\u70b9\uff0c\u5e76\u4e14\u8bf4\uff0c\u8fd9\u91cc\u8fd8\u67092\u4e2a\u6211\u4eec\u6ca1\u6709\u63d0\u5230\u7684\u6982\u5ff5\uff1abeing next to\u7684\u6982\u5ff5\uff0c\u5e76\u4e14\u7d27\u6328\u7740\u53f3\u8fb9(the concepts of being next to and immediately to the right of)\u3002\u7d27\u6328\u7740\u53f3\u8fb9(immediately to the right of\u2014\u2014well)\uff0c\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u4f7f\u7528\u4e86\u623f\u5b50\u53f7\u7801\uff0c\u4ee5\u5206\u914d\u623f\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u8bf4\uff0c\u623f\u5b501\u662f\u7d27\u6328\u7740\u623f\u5b502\u7684\u53f3\u8fb9\uff0c\u5982\u679c\u4ed6\u4eec\u76f8\u5dee1\uff0c\u5982\u679ch1 - h2\u662f1\u3002\u6240\u4ee5\u623f\u5b50\u53f7\u78013\u662f\u7d27\u6328\u7740\u623f\u5b50\u53f7\u78012\u7684\u3002\u6211\u60f3\u8981\u4f60\u505a\u7684\u4e8b\uff0c\u662f\u4e3anextto<\/code>\u586b\u5165\u4ee3\u7801\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c2\u4e2a\u623f\u5b50\u662f\u4e92\u76f8\u76f8\u90bb\u7684\u3002<\/p>\n

import<\/span> itertools houses = [1<\/span>, 2<\/span>, 3<\/span>, 4<\/span>, 5<\/span>] orderings = list(itertools.permutations(houses)) def<\/span> imright<\/span>(h1, h2)<\/span>:<\/span> \"House h1 is immediately right of h2 if h1-h2 == 1\"<\/span> return<\/span> h1-h2 == 1<\/span> def<\/span> nextto<\/span>(h1, h2)<\/span>:<\/span> \"Two houses are next to each other if they differ by 1.\"<\/span> return<\/span> abs(h1-h2) == 1<\/span> ## code here<\/span><\/code><\/pre>\n

\u6211\u7684\u7406\u89e3\u662f\uff0c\u53ea\u8981h1\u548ch2\u7684\u5dee\u7684\u7edd\u5bf9\u503c\u662f1\uff0c\u90a3\u4e48\u80af\u5b9a\u662f\u76f8\u90bb\u7684\u3002<\/p>\n

12. Slow Solution <\/h4>\n

Slow Solution - Design of Computer Programs - YouTube<\/p>\n

\u8865\u5145\u89c6\u9891\u4e2d\uff0c\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u8bcd\u6c47<\/h5>\n

stick with \u7ee7\u7eed\u505a\uff1b\u63d2\u6ee1<\/p>\n

state \u89c4\u5b9a\uff1b\u9648\u8ff0\uff0c\u8868\u660e<\/p>\n

\u89c6\u9891\u4e2d\u7684\u4e00\u957f\u4e32\u7684\u4ee3\u7801\uff0c\u6709\u70b9\u96be\u4ee5\u7406\u89e3\uff0c\u8fd9\u91cc\uff0c\u6211\u5148\u4e0a\u4e00\u6bb5\u6211\u81ea\u5df1\u7684\u4ee3\u7801\uff0c\u7136\u540e\u518d\u5bf9\u89c6\u9891\u4e2d\u7684\u5927\u6bb5\u4ee3\u7801\uff0c\u505a\u4e00\u70b9\u89e3\u8bfb\u3002<\/p>\n

def<\/span> f<\/span>()<\/span>:<\/span> list1 = [4<\/span>, 5<\/span>, 6<\/span>] list2 = [1<\/span>, 2<\/span>, 3<\/span>, 4<\/span>] return<\/span> ((i1, i2) for<\/span> i1 in<\/span> list1 for<\/span> i2 in<\/span> list2 if<\/span> i1 == i2) '''\u6362\u884c\u7684\u5f62\u5f0f\uff1a return ((i1, i2) for i1 in list1 for i2 in list2 if i1 == i2 ) '''<\/span> print<\/span> f() print<\/span> next(f()) -------------------- \u8f93\u51fa\uff1a <generator object <genexpr> at 0x7facbe3cc6e0<\/span>> (4<\/span>, 4<\/span>)<\/code><\/pre>\n

\u5982\u4e0a\u7684\u4ee3\u7801\uff0c\u610f\u4e49\u6bd4\u8f83\u660e\u786e\uff0c\uff0c\u4e3b\u8981\u770breturn\u4e2d\u7684\u8bed\u53e5\u7684\u542b\u4e49\uff1a\u5206\u522b\u5faa\u73af\u3001\u8fed\u4ee3\u3001\u904d\u5386list1\u548clist2\u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u5982\u679clist1\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\uff0c\u4e0elist2\u5217\u8868\u4e2d\u7684\u67d0\u4e2a\u5143\u7d20\u76f8\u7b49\uff0c\u5219\u8fd4\u56de\u8fd92\u4e2a\u76f8\u7b49\u7684\u5143\u7d20\u3002\u6ce8\u610f\uff0c\u8fd9\u91ccreturn\u8bed\u53e5\u662f\u5706\u62ec\u53f7\uff0c\u56e0\u6b64\uff0c\u8fd4\u56de\u7684\u662f\u751f\u6210\u5668\u8868\u8fbe\u5f0f\uff0c\u5373generator object\u3002\u8c03\u7528\u4e86next(f())\u540e\uff0c\u53ef\u4ee5\u8f93\u51fa\u8fd92\u4e2a\u503c\u3002<\/p>\n

\u5173\u4e8e\u5982\u4e0b\u7684\u4ee3\u7801\uff0c\u6211\u7684\u7406\u89e3\uff1a
1. \u9996\u5148\u9700\u8981\u9605\u8bfb1. \u7ec3\u4e60\uff1aZebra Puzzle<\/code>\u4e2d\uff0c\u5bf9\u4e8eZebra Puzzle<\/code>\u89c4\u5219\u7684\u6587\u5b57\u63cf\u8ff0\u3002
2. #2<\/code>\u5230#15<\/code>\u7684if\u8bed\u53e5\uff0c\u5b9e\u9645\u4e0a\u662f\u628a\u5bf9\u5e94\u5e8f\u53f7\u7684\u89c4\u5219\uff0c\u8f6c\u6362\u4e3a\u4e86\u4ee3\u7801\u3002
3. return\u8bed\u53e5\u4e2d\u7684\u4ee3\u7801\uff0c\u5176\u5b9e\u53ef\u4ee5\u5408\u4e3a1\u884c\uff0c\u542b\u4e49\u76f8\u540c\u3002\u6574\u4e2areturn\u8bed\u53e5\u7684\u542b\u4e49\u662f\uff0c\u5bf9\u989c\u8272\u3001\u56fd\u7c4d\u3001\u52a8\u7269\u3001\u996e\u6599\u3001\u70df\u7684\u54c1\u724c\uff0c\u5728orderings\u4e2d\uff0c\u8fdb\u884c\u904d\u5386\uff0c\u7136\u540e\uff0c\u5982\u679c\u6ee1\u8db3Zebra Puzzle<\/code>\u89c4\u5219(\u5373\u8fd9\u4e9bif\u8bed\u53e5)\uff0c\u5219\u8fd4\u56de(WATER, ZEBRA)\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u7684next()\u3002
4. orderings\u662f5\u4e2a\u623f\u5b50\u7684\u53f7\u7801\u7684\u6240\u6709\u7684\u5168\u6392\u5217\u60c5\u51b5\u3002
5. \u5bf9\u4e8e\u4e0b\u6bb5\u4ee3\u7801\uff0c\u6211\u5b58\u5728\u7591\u95ee\u7684\u5730\u65b9\u662f\uff0c\u4e3a\u4f55\u8981\u7528\u5355\u4e2a\u4e0b\u5212\u7ebf_<\/code>\u4f5c\u4e3a\u53d8\u91cf\u540d\uff0c\u5e76\u4e14\uff0c3\u4e2a\u4e0b\u5212\u7ebf\uff0c\u6700\u7ec8\u53ea\u67091\u4e2a\u8d4b\u503c\u4e86\u3002<\/p>\n

\u672c\u6bb5\u89c6\u9891\u7684\u6838\u5fc3\u90e8\u5206\u7684\uff0c\u6211\u7684\u7ffb\u8bd1<\/h5>\n
def<\/span> zebra_pu<\/span><\/span><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u300aDesign of Computer Programs\u300b\u5b66\u4e60\u7b14\u8bb0\uff082 - 1\uff09Back of the Envelope - Lesson 2BackoftheEnvelopeenvelopen.\u4fe1\u5c01\uff08\u91d1\u5c71...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7826"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7826"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7826\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}