August 23, 2006
我只想说,我操!
原来站点违规被封是这个样子的。
Filed by
charlie
at 1:37 am under Life
No Comments
早上看到Zoho Blogs中 Insert Stylesheets in Zoho Writer。真不错。
这是我一直很期待的功能,曾经在Zoho的论坛上提出过,主要是把它当作Blog或者其他网页编辑器的时候,能够基本上“所见即所得”:
Could each of my document appears with my own CSS file?
The CSS file could be updated to Zoho or just a web file link.
So I can use these CSS files as the real template for documents.
If styles could be automatic import from Workpress/ Blogger template of user’s site, the Zoho Writer would be a perfect front end of bloggers.
很快得到回应:
Great suggestion. We will work on it, and try and get it out as quickly as possible.
Thanks,
Sridhar
起码说明了他们的研发团队是热情有活力的,于是从此我开始从Writely转向Zoho。虽然Writely的后台比较硬。
大体上认为Zoho比Writely好在以下的功能上吧:
从Davies大侠那里看到这个问题。这个问题是Thumbjive招聘工程师时要求随简历要一同提交。去年春天我还没毕业时,也解了这个问题,并且去Thumbjive面试了。当时也是用Python解的,面试我的法国工程师还很高兴我懂Python这个东西。实际上当时刚刚接触Python,现在看起来当时写的代码,实在是太不Python style了。
参考Davies的解法,总结一下这个问题的解决过程。
原题在Thumbjive网站的招聘页面中。
You have four colored cubes. Each side of each cube is a single color, and there are four colors: blue (B), red (R), green (G) and yellow (Y) Describing the six faces as front, back, left, right, top, bottom, the cube colors are:
|
Cube
|
Front
|
Back
|
Left
|
Right
|
Top
|
Bottom
|
|
1
|
R
|
B
|
G
|
Y
|
B
|
Y
|
|
2
|
R
|
G
|
G
|
Y
|
B
|
B
|
|
3
|
Y
|
B
|
R
|
G
|
Y
|
R
|
|
4
|
Y
|
G
|
B
|
R
|
R
|
R
|
The objective is to find ways to stack the four cubes as a vertical column so that each side of the column is showing all four colors.
有四个立方体,每个有六个面,涂上了四种颜色。要求摞成一个长条,并使其四个侧面都有四种不同的颜色。
我想这里主要要解决两个事情:
对于1,Davies定义了两个立方体的动作,侧面转一圈和翻个。 然后汇成一个角的三个面作为初始状态,分别翻个,转一圈。正好得到了24种可能位置。比我当时考虑的强,我定义了x,y轴两个方向的旋转,并且用这两个动作连续旋转立方体,虽然能遍历所有的状态,但是显然有冗余。
我定义的旋转遍历:
# a serial of cube rotation
# make sure that the cube placed in all possible position
all_seq = [2,1,1,1,1, # following with 4 transform 1 means unchanged
2,1,1,1,1,
2,1,1,1,1,
2,1,1,1,1, # no position change
1,2,
1,1,1,1,
1,1,
1,1,1,1]
对于2,Davies枚举了所有可能排列,应该是一种宽度优先算法吧。如果只要求得到一个解,而不给出所有解的前提下,深度优先搜索能更快。不过我原来的脚本写得太滥了,运行速度明显慢很多。于是在他的脚本基础上,我写了个深度优先的算法solve2,可以代替Davies的solve来用。
def solve2(belows, aboves=[[]]):
”’ 060805, charlie, depth first solution ”’
belows = [b for b in belows] # copy object as a ‘pass-by-value’ argu of function
nodes = combine(aboves, turn(belows.pop(0)))
if not nodes: return False
if not belows: return nodes # all cubes placed
return reduce( lambda x,n: x or solve2(belows, [n]),
nodes , False )
实际效果上也没快多少,可能是搜索树的深度比较浅,没啥效果吧。
另外有写得不好的地方,就是搞不懂pass-by-value传参应该怎么弄比较好;和找不到一个代替逻辑运算符or的函数, 只好lambda了一个。
最后贴一下去年我写的脚本,不值得一看,权且留念。
Filed by
charlie
at 6:50 pm under Engineer, Python
1 Comment