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 ...
随机推荐
- 什么是A站、B站、C站、D站、E站、F站、G站、HIJKLM站N站?
A站AcFun弹幕视频网,简称“A站”,成立于2007年6月,取意于Anime Comic Fun,是中国大陆第一家弹幕视频网站.A站以视频为载体,逐步发展出基于原生内容二次创作的完整生态,拥有高质量 ...
- CUDA Programming Guide 学习笔记
CUDA学习笔记 GPU架构 GPU围绕流式多处理器(SM)的可扩展阵列搭建,每个GPU有多个SM,每个SM支持数百个线程并发执行.目前Nvidia推出了6种GPU架构(按时间顺序,详见下图):Fer ...
- p44_IP数据包格式
一.IP数据报格式 二.IP分片 数据链路层每帧可封装数据有上限,IP数据超过的要分片. 标识:同一数据报的分片使用同一标识 标志: 片偏移(13bit):用于还原数据报顺序,指出某片在原分组1中的相 ...
- MySQL数据库---表的操作
存储引擎 表就是文件,表的存储引擎就是文件的存储格式,即数据的组织存储方式. 字段类型 1.整数类型 整数类型:TINYINT SMALLINT MEDIUMINT INT BIGINT 作用:存储年 ...
- 如何证明sleep不释放锁,而wait释放锁?
wait 加锁示例 public class WaitDemo { private static Object locker = new Object(); public static void ma ...
- 初步知道scss 简化css复杂层级
简介:今天在调试前端样式的时候,el-button组件位置需要调整并且 需要改字体大小 .直接上了一个 font-text:20px; 发现没作用,谷歌调试发现并未作用到组件里的<span> ...
- ImportError: /lib64/libm.so.6: version `GLIBC_2.23' not found (required by /usr/local/python37/lib/python3.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)
一 问题背景 这个错误的出现往往与我前面的一篇文章 ImportError: /lib64/libm.so.6: version `CXXAB_1.3.8.' not found (required ...
- 2016A06寒假作业 全排列
又是一个全排列哈, 注意注意,这个题不是十三个数字都需要,但原理是一样的 一开始把for的边界写错了(每次其实应该从k开始,还没看出来orz) #include <iostream> #i ...
- 你不知道的JavaScript 上卷 2/11
第一部分——作用域和闭包 第一章 作用域是什么 1.几乎所有编程语言最基本的功能之一,就是能够储存变量当中的值,并且能在之后对这个值进行访问或修改.事实上,正是这种储存和访问变量的值的能力将状态带给了 ...
- Mybatis-Plus中Wrapper的方法
public interface EntityService extends IService<TbEntity>{ }entityService.update(entity,Condit ...