麻省理工学院公开课-人工智能 公开课笔记1
程序员文章站
2022-07-12 13:52:36
...
Lecture 1: Introduction and Scope
What is Artificial Intelligence
Artificial Intelligence is about
algorithms enabled by
constraints exposed by
representations that support
models targeted at
thinking, perception and action.
The problem about the farmer crossing the river
A farmer with his fox, his grain and his goose wants to cross a river.
There is a leaky little boat that can only carry the farmer and one of his four possessions.
#!/usr/bin/env python
# coding=utf-8
sideA = [["fox", 1], ["goose", 1], ["grain", 1]] # initial state
sideB = [["fox", 0], ["goose", 0], ["grain", 0]]
size = len(sideA)
last_one = -1 # 判断避免重复运输时使用
def judge(side):
if side[1][1] == 1 and side[0][1] + side[2][1] == 1: # constraints
return False
else:
return True
def a_to_b():
global last_one
for i in range(size):
if sideA[i][1] == 1 and i != last_one:
sideA[i][1] -= 1
if judge(sideA):
sideB[i][1] += 1
last_one = i
print("%s, A—>B" % sideA[i][0])
break
else:
sideA[i][1] += 1
def b_to_a():
global last_one
if not judge(sideB):
for j in range(size):
if sideB[j][1] == 1 and j != last_one:
sideB[j][1] -= 1
sideA[j][1] += 1
last_one = j
print("%s, B—>A" % sideB[j][0])
break
else:
if success():
print("任务完成")
else:
print("空船,B->A")
def show(side):
existed_list = []
for each_side in side:
if each_side[1] == 1:
existed_list.append(each_side)
return existed_list
def success():
if sideB[0][1] + sideB[1][1] + sideB[2][1] == 3:
return True
else:
return False
def main():
while 1:
print("A岸上有", show(sideA))
print("B岸上有", show(sideB))
a_to_b()
print("A岸上有", show(sideA))
print("B岸上有", show(sideB))
b_to_a()
if success():
break
if __name__ == '__main__':
main()
上一篇: spring boot数组型属性的配置
下一篇: 来自麻省理工的信息抽取
推荐阅读
-
斯坦福大学深度学习公开课cs231n学习笔记(7)神经网络防止数据过拟合:损失函数和正则化
-
韩顺平_PHP软件工程师玩转算法公开课(第一季)01_算法重要性_五子棋算法_汉诺塔_回溯算法_学习笔记_源代码图解_PPT文档整理
-
韩顺平_PHP软件工程师玩转算法公开课(第一季)01_算法重要性_五子棋算法_汉诺塔_回溯算法_学习笔记_源代码图解_PPT文档整理
-
Stanford公开课《编译原理》学习笔记(1~4课)
-
麻省理工公开课《计算机科学及编程导论》中文笔记(第1讲)
-
【线性代数公开课MIT Linear Algebra】 实际应用——python中的线性代数(1)
-
麻省理工学院公开课-人工智能 公开课笔记1
-
Stanford公开课《编译原理》学习笔记(2)递归下降法
-
【Algorithms公开课学习笔记5】排序算法part2——归并排序
-
【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记41 Animation动画_html/css_WEB-ITnose