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. 问题:win10缺少一个或多个网络协议

    国庆回家,家里电脑连不上网了,诊断给出的结果是“缺少一个或多个网络协议” 网上这类问题提问的不少,回答的方法也是各种各样,一个一个试下来,发现这个方法是可行的. 1.打开设置--网络和Internet ...

  2. Java 分布式任务调度平台:PowerJob 快速开始+配置详解

    本文适合有 Java 基础知识的人群 作者:HelloGitHub-Salieri 引言 HelloGitHub 推出的<讲解开源项目>系列. 项目地址: https://github.c ...

  3. equals方法与==关系的总结

    /** * ==&&equals区别 * * ==比较的是栈内存中的值 * 对于基本类型数据,比较的是栈内存中的值 * 对于引用数据类型,比较的是栈内存中的值(值的真是含义是一个地址) ...

  4. html 转义和反转义

    public static void main(String[] args) {// String html = "<img style=\"width: 100%; hei ...

  5. 记IntelliJ IDEA创建spring mvc一次坑爹的操作!!!!

    本人刚开始学习spring mvc,遇到一问题,现在分享一下. 点击Next,创建项目完成,你会发现缺少很多东西. lib文件没有,里面的jar更没有.applicationContext.xml和d ...

  6. ajax异步上传图片&SpringMVC后台代码

    function uploadPic(){ var options = { url : "/upload/updatePic.action", type : "post& ...

  7. thymeleaf js绑定多个变量参数

    写法一: <img th:src="@{/css/bianji.png}" th:onclick="|viewById('${user.id}','${user.i ...

  8. 火车进栈(进出栈的模拟,dfs爆搜)

    这里有n列火车将要进站再出站,但是,每列火车只有1节,那就是车头. 这n列火车按1到n的顺序从东方左转进站,这个车站是南北方向的,它虽然无限长,只可惜是一个死胡同,而且站台只有一条股道,火车只能倒着从 ...

  9. Django学习路29_css样式渲染 h3 标签

    在 static 静态文件夹下创建 css 文件夹 home.css 此时 home.css 路径是 'static/css/home.css' 在 对应的 home.html 文件中添加 css 样 ...

  10. PHP date_diff() 函数

    ------------恢复内容开始------------ 实例 计算两个日期间的差值: <?php$date1=date_create("2013-03-15");$da ...