find the lowest number location
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的更多相关文章
- codewars--js--the highest and lowest number + JS 字符串和数组相关知识
本文参考: http://blog.csdn.net/tyrionj/article/details/78653426 http://www.runoob.com/jsref/jsref-obj-st ...
- BOM 子对象,history,location,screen
history:包括浏览器访问过的 url 属性:返回浏览器访问过的历史记录数 方法:back(); forward(); go(number) location:包含当前 url 的相关信息 属性: ...
- TypeScript中 typeof ArrayInstance[number] 剖析
假设这样一个场景,目前业务上仅对接了三方支付 'Alipay', 'Wxpay', 'PayPal', 实际业务 getPaymentMode 会根据不同支付方式进行不同的付款/结算流程. const ...
- uC/OS-II任务(OS_task)块
/*************************************************************************************************** ...
- uC/OS-II之系统函数20160526
任务管理 1 OSTaskCreate() 建立一个新任务.任务的建立可以在多任务环境启动之前,也可以在正在运行的任务中建立.中断处理程序中不能 建立任务.一个任务可以为无限循环的结构. 函数原型:I ...
- OS_TASK.C
/*************************************************************************************************** ...
- JDK8下Object类源码理解
JDK8中Object类提供的方法: package java.lang; /** * Class {@code Object} is the root of the class hierarchy. ...
- java.lang.Long 类源码解读
总体阅读了Long的源码,基本跟Integer类类似,所以特别全部贴出源码,直接注释进行理解. // final修饰符 public final class Long extends Number i ...
- NGINX Load Balancing - HTTP Load Balancer
This chapter describes how to use NGINX and NGINX Plus as a load balancer. Overview Load balancing a ...
随机推荐
- 计算机网络学习socket--day3
1.REUSEADDR(地址重复利用) 1.REUSEADDR解决服务器关闭后重新绑定地址,在day3中知道服务器端必须绑定地址 2.服务器端尽可能使用REUSEADDR 3.在绑定之前尽可能调用se ...
- 为什么阿里、头条、美团这些互联网大厂都在用Spring Boot?
前言 自 2014 年发布至今,Spring Boot 的搜索指数 一路飙升.没错 Spring Boot 越来越火了,作为一名行走一线的 Java 程序员,你可能在各个方面感受到了 Spring B ...
- python3利用cryptography 进行加密和解密
我们的日常工作中,一定会遇到需要加密的数据,比如:密码.私密信息... ... 我们不仅要对他们进行加密,更需要对他们进行解密,因为毕竟我们的用户应该不会看得懂加密过后的字符串吧!!! 在python ...
- Redis之字典
概念 字典,又称为符号表.关联数组或映射(map),是一种用于保存键值对(key-value pair)的抽象数据结构.字典中每个键都是独一无二的,程序可以根据键来更新值,或者删除整个键值对. 用途 ...
- 年薪30W+高薪测试技术要掌握哪些?
职业技能一 1. 软件测试: 1) 熟练灵活地运用等价类.边界值.判定表法.因果图法等各种方法设计测试用例,包括单元测试.集成测试.系统测试用例设计. 2) 牢固掌握了软件测试计划.测试日报.测试报告 ...
- 详解 CmProcess 跨进程通信的实现
CmProcess 是 Android 一个跨进程通信框架,整体代码比较简单,总共 20 多个类,能够很好的便于我们去了解跨进程实现的原理. 个人猜测 CmProcess 也是借鉴了 VirtualA ...
- 使用Thanos实现Prometheus指标联邦
本文来自Rancher Labs Prometheus是CNCF中已经毕业的项目之一,主要用于监控和告警.在Kubernetes生态中,它是应用最为广泛的监控和告警工具之一.Rancher用户可以通过 ...
- css的一些小技巧。修改input样式
在第一次正式写项目的时候,遇到了几个布局的小技巧.记录一下. 我们常常会遇到图片和文字对齐的一种样式.比如 这样的样式,我们写的时候有时候会出现不对齐的情况.我们有俩种方法 一种就是flex的布局,还 ...
- Squeeze-and-Excitation Networks(SENet)详解
一.SENet简介 Squeeze-and-Excitation Networks(SENet)是由自动驾驶公司Momenta在2017年公布的一种全新的图像识别结构,它通过对特征通道间的相关性进行建 ...
- Bug--Tomcat Error start child
添加Quartz之后报错 下面的Cause by: More than one fragment with the name [spring_web] was found. This is not l ...