nat2::[(整数,整数)] 定义
定义列表:
nat2::[(整数,整数)]
包含所有非负数对 按已知关系排序的整数 由康托定理证明:
<前><代码>(x1,y1) < (x2,y2) <=> x1+y1< x2+y2 v (x1+y1=x2+y2 ^ x1 < x2)[^- 表示替代]
这样:
nat2 = [(0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3) ,(1,2),(2,1),(3,0),...]
提示:
定义应该适合一个 线且短于45 人物。请注意,总和 上的点的坐标 相同的对角线是恒定的。
我做了一些定义,但不确定它是否正确,您可以检查/修复/给出提示吗:
nat2::[(Integer,Integer)]
nat2=[(a,b-a)|b<-[0...],a<-[0...b]]
编辑:更改为:
nat2 :: [(Integer,Integer)]
nat2 = [(a,b-a) | b <- [0..], a <- [0..b]]
结果:
Prelude> :load "nat2.hs"
[1 of 1] Compiling Main ( nat2.hs, interpreted )
Ok, modules loaded: Main.
*Main> take 10 nat2
[(0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3),(1,2),(2,1),(3,0)]
Define a list:
nat2::[(Integer, Integer)]
that contains all pairs of nonnegative
integers ordered by the relation known
from the proof of Cantor theorem:(x1,y1) < (x2,y2) <=> x1+y1 < x2+y2 v (x1+y1=x2+y2 ^ x1 < x2)
[^- means alternative]
such that:
nat2 = [(0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3),(1,2),(2,1),(3,0),...]
Hint:
definition should fit in one
line and be shorter than 45
characters. Notice that the sum of
coordinates of points laying on on the
same diagonal is constant.
I made some definition, but am not sure if it is correct, could you check/repair/give tips:
nat2::[(Integer,Integer)]
nat2=[(a,b-a)|b<-[0...],a<-[0...b]]
EDIT: CHANGED TO:
nat2 :: [(Integer,Integer)]
nat2 = [(a,b-a) | b <- [0..], a <- [0..b]]
with result:
Prelude> :load "nat2.hs"
[1 of 1] Compiling Main ( nat2.hs, interpreted )
Ok, modules loaded: Main.
*Main> take 10 nat2
[(0,0),(0,1),(1,0),(0,2),(1,1),(2,0),(0,3),(1,2),(2,1),(3,0)]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有一个语法错误(你是否尝试运行它并检查输出?)
因为你只需要列表枚举中的两个
..
:看起来很合理,但你是最好的判断者。
You have a syntax error (did you try running it and checking the output?)
Because you only need two
..
in the list enums:Looks reasonable, but you are the best to judge.