使用流寻找最佳方法 - 方案
我对Scheme比较陌生,并且在流方面遇到了一些问题。我只知道如何制作自然数流,没有更复杂的。我想也许它们在这种情况下会有用。所以,基本上,我有这个矩阵:
[0 0 0 0 0 S 0 0] [0 0 0 0 x 0 x 0] [0 0 0 0 x 0 0 x] [0 0 0 x 0 0 0 x] [0 0 0 x 0 0 0 x] [0 0 xx 0 0 0 0] [0 0 D 0 0 0 0 0]
其中 x = 可访问路径 S = 来源 D = 目的地
我要做的就是在可到达的路径上一次仅水平、垂直和对角移动一格,从 S 到达 D。到目前为止,我只创建了一个位置列表,其中包含源位置、可访问路径和目的地位置。 有没有办法使用流来选择正确的路径?如果这对我来说太复杂而无法理解,您建议什么其他方法?
I'm relatively new to Scheme and I'm having a few problems with streams. I only know how to make a stream of natural numbers, nothing more complex. I thought maybe they'll be of use in this case. So, basically, I have this matrix:
[0 0 0 0 0 S 0 0]
[0 0 0 0 x 0 x 0]
[0 0 0 0 x 0 0 x]
[0 0 0 x 0 0 0 x]
[0 0 0 x 0 0 0 x]
[0 0 x x 0 0 0 0]
[0 0 D 0 0 0 0 0]
where x = accessible paths
S = source
D = destination
What I have to do is get from S to D by traveling only horizontally, vertically and diagonally one square at a time on the accessible paths. Until now, I've only created a list of positions that contains the source's position, the accessible paths and the destination's position.
Is there a way of choosing the correct path by using streams? And if that is too complex for me to understand, what other method do you suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为流对理解这个问题有实质性贡献。你面临的是一个搜索问题——你正在寻找可能性空间中的一系列动作。我鼓励您查看 HtDP,第 28 节 介绍了一个非常相似的问题。
I don't think that streams contribute substantially to an understanding of this problem. What you have is a search problem--you're looking for a sequence of moves in a space of possibilities. I would encourage you to take a look at HtDP, section 28 for a look at a very similar problem.