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 ...
随机推荐
- jpa随手笔记
jpa注解1.设置Pojo为实体@Entity //标识这个pojo是一个jpa实体 2.设置表名@Table(name = "users") //指定表名为users 3.设置主 ...
- Web For Pentester靶场(xss部分)
配置 官网:https://pentesterlab.com/ 下载地址:https://isos.pentesterlab.com/web_for_pentester_i386.iso 安装方法:虚 ...
- DEX文件解析--7、类及其类数据解析(完结篇)
一.前言 前置技能链接: DEX文件解析---1.dex文件头解析 DEX文件解析---2.Dex文件checksum(校验和)解析 DEX文件解析--3.d ...
- /dev/mapper/VolGroup00-LogVol00 满了,根目录存储垃圾文件导致磁盘满了
登录系统,df -H 发现磁盘存储快满了 解决办法 1. 使用命令查出根目录下大的垃圾文件 使用 du -sh /* | sort -nr 查看根目录下的的大文件,找的不要的 rm -rf 使用 fi ...
- 设计模式:fly weight模式
目的:通过共享实例的方式来避免重复的对象被new出来,节约系统资源 别名:享元模式 例子: class Char //共享的类,轻量级 { char c; public: Char(char c) { ...
- 初识Http
HTTP是一个用在计算机世界里的协议,它确立了一种计算机之间交流通信的规范,以及相关的各种控制 和错误处理方式. HTTP专门用来在两点之间传输数据,不能用于广播.寻址或路由. HTTP传输的是文 ...
- spring notes
************************ nexus is a tool of warehouse managementfirst nexus search local warehous ,i ...
- android获取各种系统路径的方法
链接https://blog.csdn.net/qq_26296197/article/details/51909423 通过Environment获取的 Environment.getDataDir ...
- 使用 Azure Blob Stoage 实现一个静态文件服务器
什么是Azure Blob Stoage Azure Blob Stoage 是微软Azure的对象存储服务.国内的云一般叫OSS,是一种用来存储非结构化数据的服务,比如音频,视频,图片,文本等等.用 ...
- 缓存利器、Lua模块下的共享内存
上一节讲到了worker进程的共享内存,它利用丰富的指令使数据的缓存操作变得非常简单,但它也存在一些缺点. 1.worker进程之间会有锁竞争,在高并发的情况下会增加性能开销.2.只支持Lua布尔值. ...