before

#设定路径列表Path
def find_path2(heightmap, x, y, water_level=557,path=[]):
#global path
#设定坐标 右0 左1 上2 下3
right_point=heightmap[x][y+1]
left_point=heightmap[x][y-1]
above_point=heightmap[x-1][y]
below_point=heightmap[x+1][y]
#zip[*]
go_path=[right_point,left_point,above_point,below_point]
go_path1 = ['right','left','above','below']
#circle log
print("现在点的值为:%d 最小值为索引:%s 最小值为:%d"
%(heightmap[x][y],go_path1[go_path.index(min(go_path))],
go_path[go_path.index(min(go_path))]))
if min(go_path) > water_level:
if min(go_path) <= heightmap[x][y]:
if go_path.index(min(go_path)) == 0: #right
path.append((x,y+1))
find_path2(heightmap, x, y+1, water_level=water_level)
if go_path.index(min(go_path)) == 1: #left
path.append((x,y-1))
find_path2(heightmap, x, y-1, water_level=water_level)
if go_path.index(min(go_path)) == 2: #above
path.append((x-1,y))
find_path2(heightmap, x-1, y, water_level=water_level)
if go_path.index(min(go_path)) == 3: #below
path.append((x+1,y))
find_path2(heightmap, x+1, y, water_level=water_level)
return path
return path def sun(heightmap, x, y, water_level=0):
way = []
way.clear()
way.append(find_path2(heightmap, x, y, water_level=water_level))
return way find_path2(test,0,0,water_level=0)
sun(test,1,0,water_level=0) test = ((10,10,10,10)
,(10,9,8,10)
,(10,10,3,10)
,(10,10,10,10)
)

问题在于

find_path2递归调用自身,path局部变量没有释放内容

after

#设定路径列表Path
def find_path3(heightmap, x, y,water_level):
#global path
#设定坐标 右0 左1 上2 下3
right_point=heightmap[x][y+1]
left_point=heightmap[x][y-1]
above_point=heightmap[x-1][y]
below_point=heightmap[x+1][y]
#zip[*]
go_path=[right_point,left_point,above_point,below_point]
go_path1 = ['right','left','above','below']
#circle log
print("现在点的值为:%d 最小值为索引:%s 最小值为:%d"
%(heightmap[x][y],go_path1[go_path.index(min(go_path))],
go_path[go_path.index(min(go_path))]))
if min(go_path) > water_level:
if min(go_path) <= heightmap[x][y]:
if go_path.index(min(go_path)) == 0: #right
return(x,y+1)
#path.append((x,y+1))
#find_path2(heightmap, x, y+1, water_level=water_level)
if go_path.index(min(go_path)) == 1: #left
return(x,y-1)
#path.append((x,y-1))
#find_path2(heightmap, x, y-1, water_level=water_level)
if go_path.index(min(go_path)) == 2: #above
return(x-1,y)
#path.append((x-1,y))
#find_path2(heightmap, x-1, y, water_level=water_level)
if go_path.index(min(go_path)) == 3: #below
return(x+1,y)
#path.append((x+1,y))
#find_path2(heightmap, x+1, y, water_level=water_level)
return None
print("the current number is less then the water_level")


def route(heightmap, x, y, water_level=0):
route = []
next_step = find_path3(heightmap, x, y,water_level)
while next_step:
route.append(next_step)
x,y = next_step
next_step = find_path3(heightmap, x, y,water_level)
return route


test = ((10,10,10,10)
,(10,9,8,10)
,(10,10,3,10)
,(10,10,10,10)
)

find_path3(test,2,2,water_level=1)
route(test,2,2,water_level=0)

分步骤进行,不用调用自身后,route变量首先置为空了

												

find the lowest number location的更多相关文章

  1. codewars--js--the highest and lowest number + JS 字符串和数组相关知识

    本文参考: http://blog.csdn.net/tyrionj/article/details/78653426 http://www.runoob.com/jsref/jsref-obj-st ...

  2. BOM 子对象,history,location,screen

    history:包括浏览器访问过的 url 属性:返回浏览器访问过的历史记录数 方法:back(); forward(); go(number) location:包含当前 url 的相关信息 属性: ...

  3. TypeScript中 typeof ArrayInstance[number] 剖析

    假设这样一个场景,目前业务上仅对接了三方支付 'Alipay', 'Wxpay', 'PayPal', 实际业务 getPaymentMode 会根据不同支付方式进行不同的付款/结算流程. const ...

  4. uC/OS-II任务(OS_task)块

    /*************************************************************************************************** ...

  5. uC/OS-II之系统函数20160526

    任务管理 1 OSTaskCreate() 建立一个新任务.任务的建立可以在多任务环境启动之前,也可以在正在运行的任务中建立.中断处理程序中不能 建立任务.一个任务可以为无限循环的结构. 函数原型:I ...

  6. OS_TASK.C

    /*************************************************************************************************** ...

  7. JDK8下Object类源码理解

    JDK8中Object类提供的方法: package java.lang; /** * Class {@code Object} is the root of the class hierarchy. ...

  8. java.lang.Long 类源码解读

    总体阅读了Long的源码,基本跟Integer类类似,所以特别全部贴出源码,直接注释进行理解. // final修饰符 public final class Long extends Number i ...

  9. NGINX Load Balancing - HTTP Load Balancer

    This chapter describes how to use NGINX and NGINX Plus as a load balancer. Overview Load balancing a ...

随机推荐

  1. P4017 最大食物链计数 (拓扑排序)

    看到拓扑排序感觉非常遥远的复杂,不喜欢图.看了拓扑排序的原理,很像广搜. 以本题样例为例: 了解一下 出度 和 入度 5的出度为3 入度为 0 ,3的出度为2  入度为2…… for循环 找到秃头 5 ...

  2. 9.CSMA_CD协议

    先听再说,边听边说 载波监听多点接入/碰撞检测CSMA/CD( carrier sense multiple access with collision detection) CD:碰撞检测(冲突检测 ...

  3. IDEA 2020.1.2 idea 2020.1.3下载 安装 一键破解

    IDEA 2020.1.2 idea 2020.1.3下载 安装 破解 本项目只做个人学习研究之用,不得用于商业用途!若资金允许,请点击链接购买正版,谢谢合作!学生凭学生证可免费申请正版授权!创业公司 ...

  4. 题解 洛谷 P4189 【[CTSC2010]星际旅行】

    一个比较直接的想法就是对每个点进行拆点,拆成入点和出点,限制放在入点和出点相连的边上,然后跑最大费用最大流即可. 但是这样复杂度无法接受,所以考虑模拟费用流来解决本题. 发现 \(H\) 都大于等于该 ...

  5. python中的subprocess.Popen()使用详解---以及注意的问题(死锁)

    从python2.4版本开始,可以用subprocess这个模块来产生子进程,并连接到子进程的标准输入/输出/错误中去,还可以得到子进程的返回值. subprocess意在替代其他几个老的模块或者函数 ...

  6. Btree索引和Hash索引

    B-Tree 索引 BTree索引是最常用的mysql数据库索引算法,因为它不仅可以被用在=,>,>=,<,<=和between这些比较操作符上,而且还可以用于like操作符, ...

  7. 03_Linux介绍、命令

    学于黑马和传智播客联合做的教学项目 感谢 黑马官网 传智播客官网 微信搜索"艺术行者",关注并回复关键词"软件测试"获取视频和教程资料! b站在线视频 Linu ...

  8. 前端网(http://www.qdfuns.com/)不能访问了

    前端网(http://www.qdfuns.com/)不能访问了 之前写的一些知识点也找不到了,有点难受.... 这说明知识点还是放在本地电脑稳一点,多备份,云端时刻在变化... 希望博客园别也用着用 ...

  9. PHP array_reduce() 函数

    实例 发送数组中的值到用户自定义函数,并返回一个字符串: <?phpfunction myfunction($v1,$v2){return $v1 . "-" . $v2;} ...

  10. PHP is_readable() 函数

    定义和用法 is_readable() 函数检查指定的文件是否可读. 如果文件可读,该函数返回 TRUE. 语法 is_readable(file) 参数 描述 file 必需.规定要检查的文件. 提 ...