找回密码
 欢迎注册
楼主: chyanog

[提问] N×N的方格,里面有多少个长方形?

[复制链接]
发表于 2013-3-18 16:28:38 | 显示全部楼层
22# 无心人 haskell 神级的语言,天书呀。 呵呵,被我删掉了那个回复,因此你这个指向已经不存在了,by 无心人
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2013-3-18 16:44:28 | 显示全部楼层
23# wayne 其实别人看Mathematica代码,见到@ # & /@这些符号和层层嵌套也可能会这么想
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-18 16:50:55 | 显示全部楼层
23# wayne 其实平面时候的代码还是很容易理解的 到了立体时候,要满足的条件太多了 关键还不知道自己写的条件对不对 考虑写独立程序会清晰些
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-19 08:57:16 | 显示全部楼层
点集定义 let p n = [(x, y, z)|z<-[0..n], y<-[0..n], x<-[0..n]] 正交测试 let orth (x0, y0, z0) (x1, y1, z1) (x2, y2, z2) = (x1-x0)*(x2-x0)+(y1-y0)*(y2-y0)+(z1-z0)*(z2-z0)==0
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-19 09:17:36 | 显示全部楼层
24# chyanog 我看到无心人写的haskell代码 好像每一句都是定义,而非实作。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-19 10:04:26 | 显示全部楼层
未考虑是否越界的暴力搜索 let all3 n = if n < 1 then [] else [(p0, p1, p2, p3)|let ps = p n, let l = length ps, i<-[0..l-4], j<-[i+1..l-3], k<-[j+1..l-2], m<-[k+1..l-1], let p0=ps!!i, let p1=ps!!j, let p2=ps!!k, let p3=ps!!m, orth p0 p1 p2, orth p0 p1 p3, orth p0 p2 p3] Prelude Data.Array Data.List> all3 2 [((0,0,0),(0,0,1),(0,1,0),(1,0,0)),((0,0,0),(0,0,1),(0,1,0),(2,0,0)),((0,0,0),(0,0,1),(0,2,0),(1,0,0)),((0,0,0),(0,0,1),(0,2,0),(2,0,0)),((0,0,0),(0,0,2),(0,1,0),(1,0,0)),((0,0,0),(0,0,2),(0,1,0),(2,0,0)),((0,0,0),(0,0,2),(0,2,0),(1,0,0)),((0,0,0),(0,0,2),(0,2,0),(2,0,0)),((0,0,1),(0,0,2),(0,1,1),(1,0,1)),((0,0,1),(0,0,2),(0,1,1),(2,0,1)),((0,0,1),(0,0,2),(0,2,1),(1,0,1)),((0,0,1),(0,0,2),(0,2,1),(2,0,1)),((0,0,1),(0,1,0),(0,1,2),(1,0,1)),((0,0,1),(0,1,0),(0,1,2),(2,0,1)),((0,0,1),(0,1,1),(1,0,0),(1,0,2)),((0,0,1),(0,2,1),(1,0,0),(1,0,2)),((0,1,0),(0,1,1),(0,2,0),(1,1,0)),((0,1,0),(0,1,1),(0,2,0),(2,1,0)),((0,1,0),(0,1,1),(1,0,0),(1,2,0)),((0,1,0),(0,1,2),(0,2,0),(1,1,0)),((0,1,0),(0,1,2),(0,2,0),(2,1,0)),((0,1,0),(0,1,2),(1,0,0),(1,2,0)),((0,1,1),(0,1,2),(0,2,1),(1,1,1)),((0,1,1),(0,1,2),(0,2,1),(2,1,1)),((0,1,1),(0,1,2),(1,0,1),(1,2,1)),((0,1,1),(0,2,0),(0,2,2),(1,1,1)),((0,1,1),(0,2,0),(0,2,2),(2,1,1)),((0,1,1),(0,2,0),(1,0,0),(2,2,2)),((0,1,1),(0,2,0),(1,2,2),(2,0,0)),((0,1,1),(0,2,1),(1,1,0),(1,1,2)),((0,1,1),(0,2,2),(1,0,2),(2,2,0)),((0,1,1),(0,2,2),(1,2,0),(2,0,2)),((1,0,0),(1,0,1),(1,1,0),(2,0,0)),((1,0,0),(1,0,1),(1,2,0),(2,0,0)),((1,0,0),(1,0,2),(1,1,0),(2,0,0)),((1,0,0),(1,0,2),(1,2,0),(2,0,0)),((1,0,1),(1,0,2),(1,1,1),(2,0,1)),((1,0,1),(1,0,2),(1,2,1),(2,0,1)),((1,0,1),(1,1,0),(1,1,2),(2,0,1)),((1,0,1),(1,1,1),(2,0,0),(2,0,2)),((1,0,1),(1,2,1),(2,0,0),(2,0,2)),((1,1,0),(1,1,1),(1,2,0),(2,1,0)),((1,1,0),(1,1,1),(2,0,0),(2,2,0)),((1,1,0),(1,1,2),(1,2,0),(2,1,0)),((1,1,0),(1,1,2),(2,0,0),(2,2,0)),((1,1,1),(1,1,2),(1,2,1),(2,1,1)),((1,1,1),(1,1,2),(2,0,1),(2,2,1)),((1,1,1),(1,2,0),(1,2,2),(2,1,1)),((1,1,1),(1,2,1),(2,1,0),(2,1,2))] Prelude Data.Array Data.List> length (all3 2) 49 现在我不确定,这个是否无遗漏,无重复
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-19 10:06:12 | 显示全部楼层
27# wayne 有的,每个程序正确后,我都会贴一些测试结果的 比如上面的1-30的平面上的非平行结果 我就贴出来了 我跟网上数列对了,完全相等的 一些定义我是当做记录用的,可能会改
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-19 10:24:26 | 显示全部楼层
2点加法 let addp2 (x0, y0, z0) (x1, y1, z1) (x2, y2, z2) = (x2+x1-x0, y2+y1-y0, z2+z1-z0) 3点加法 let addp3 (x0, y0, z0) (x1, y1, z1) (x2, y2, z2) (x3, y3, z3) = (x3+x2+x1-2*x0, y3+y2+y1-2*y0, z3+z2+z1-2*z0) 是否在边长n的立方体内部的测试 let inside n (x, y, z) = (x <= n) && (y <= n) && (z <= n) && (x>=0) && (y>=0) && (z>=0) 定义点的权重,方便排序 let dp n (x, y, z) = x + (n+1)*y + (n+1)*(n+1)*z
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-19 11:45:42 | 显示全部楼层
Prelude> let list3A4 n = if n < 1 then [] else [(dp0, dp1, dp2, dp3)|let ps = p n, p0<-ps, p1<-ps, p2<-ps, p3<-ps, let dp0=dp n p0, let dp1=dp n p1, let dp2=dp n p2, let dp3=dp n p3, dp0 list3A4 2 [(0,1,3,9),(0,1,3,18),(0,1,6,9),(0,1,6,18),(0,2,3,9),(0,2,3,18),(0,2,6,9),(0,2,6,18),(1,2,4,10),(1,2,4,19),(1,2,7,10),(1,2,7,19),(1,3,5,10),(1,3,5,19),(1,4,9,11),(1,7,9,11),(3,4,6,12),(3,4,6,21),(3,4,9,15),(3,5,6,12),(3,5,6,21),(3,5,9,15),(4,5,7,13),(4,5,7,22),(4,5,10,16),(4,6,8,13),(4,6,8,22),(4,6,9,26),(4,6,17,18),(4,7,12,14),(4,8,11,24),(4,8,15,20),(9,10,12,18),(9,10,15,18),(9,11,12,18),(9,11,15,18),(10,11,13,19),(10,11,16,19),(10,12,14,19),(10,13,18,20),(10,16,18,20),(12,13,15,21),(12,13,18,24),(12,14,15,21),(12,14,18,24),(13,14,16,22),(13,14,19,25),(13,15,17,22),(13,16,21,23)] Prelude> length $ list3A4 2 49 ============================================================== 暴力搜索到的符合两两正交的点集,1个顶点跟3个相邻顶点的编号,编号定义 x+(n+1)*y+(n+1)*(n+1)*z
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-3-19 14:20:23 | 显示全部楼层
let list3A9 n = [(dp0, dp1, dp2, dp3)|let ps=p n, let max=(n+1)^3-1, i<-[0..max-3], let p0=ps!!i, let dp0=dp n p0, j<-[i+1..max-2], let p1=ps!!j, let dp1=dp n p1, k<-[j+1..max-1],let p2=ps!!k, let dp2=dp n p2, orth p0 p1 p2, m<-[k+1..max], let p3=ps!!m, let dp3=dp n p3, dp2
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-11-23 20:14 , Processed in 0.023752 second(s), 14 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表