Thursday, July 14, 2022

Enable Samba1 so Windows 95 on VirtualBox can access the network dirve

 There is a post on the web talking about that

http://www.troubleshooters.com/linux/win9x_samba.htm

but I need to refer to another one here

https://askubuntu.com/questions/1213759/allow-smb-1-with-lanman-authentication-with-samba

to make it fully work.

The key point is to check /etc/samba/smbpasswd 

Make sure that the entry doesn't look like 

james:1508:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:278AC243ABDE22263F8C90EDD3793C82:[U          ]:LCT-6A8C3B16:

 

Tuesday, May 3, 2022

TAOCP Exercise 1.2.4-35

 TAOCP

Excise 1.2.4-35

$ \lfloor \frac{ (x + m) }{n} \rfloor = \lfloor \frac{  \lfloor x \rfloor +m }{n} \rfloor $, where $x$ is real, $m$ and $n$ are integers, $n >0$


Proof:

Obviously  $\lfloor(x+m)/n \rfloor \geq \lfloor(\lfloor x \rfloor + m)/n \rfloor $, the only case that it is not equal is $(\lfloor x \rfloor +m)/n $and $(x+m)/n$ lies on different sides of an integer $k$, which means 

$$1 > k -(\lfloor x \rfloor + m ) / n > 0 $$ 

and 

$$ (x+m)/n - k > 0 $$ ......(1)

furthermore, $\lfloor x \rfloor + m $is integer, thus 

$$k - (\lfloor x \rfloor + m)/n \geq 1/n $$......(2)

from (1) and (2)

$(x+m)/n -k + k - (\lfloor x \rfloor + m)/n = (x- \lfloor x \rfloor)/n > 1/n$  which is impossible. so only equal relation is valid.


Thursday, March 28, 2013

TAOCP 5,1.1 Exercise 12

Continuing the notation of the previous exercise, prove that if \(\pi_1\) and \(\pi_2\) are permutations and if E is the smallest transitive set containing \(E(\pi_1)\cup E(\pi_2)\) then \(\bar{E}\) is transitive.

反证:假设存在\((a,b) \in \bar{E}, (b,c) \in \bar{E}\)但\((a,c) \in E\),显然\((a,b) \notin E(\pi_1)\),\((b,c) \notin E(\pi_1)\)  ,所以\(c < b < a\)并且在\(\pi_1\)中保持顺序。同理此三个数在\(\pi_2\)中也保持顺序。

现在考察(a,c),如果E中去除(a,c)传递性仍然成立,则与E为满足传递性的最小集合矛盾,所以E中必有元素(a,t)和(t,c)。(a,t)和(t,c)必然分别来自\(\pi_1\)和\(\pi_2\),不失一般性,设
\(\pi_1=\ldots c \ldots b \ldots a \ldots t \ldots \)
\(\pi_2=\ldots t \ldots c \ldots b \ldots a \ldots \)

现在有两种情况
1) b>t, 则有 \((b,t) \in E(\pi_1), (t,c) \in E(\pi_2)\) 导致\((b,c) \in  E\) 与假设\((b,c) \in \bar{E}\)矛盾。
2) b<t 则有 \((a,t) \in E(\pi_1), (t,b) \in E(\pi_2)\) 导致\((a,b) \in E\) 与假设\((a,b) \in \bar{E}\)矛盾。

所以\((a,c) \in E\)不成立,\((a,c) \in \bar{E}\),即\(\bar{E}\)具有传递性。

Monday, March 25, 2013

计算排列反演表的\(n log( n)\)算法

此题是TAOCP中的5.1.1 Exercise 26
Design an algorithm that computes the inversion table \(b_1 b_2 ... b_n\) corresponding to a given permutation \(a_1 a_2 ... a_n\) of {1,2,3..,n}, where the running time is essentially proportional to \(n log (n)\) on typical computers

书后给出的答案可能需要多读几遍才能理解
基本思路是,按二进制位考察每一个\(a_i\),从最高位开始,比如计算1到9的排列,则将所有数先分成两组,1,2,……,7为一组,8和9为一组,然后计算不同组数之间的前后关系。同组之间的前后则暂时先不计算。

第二遍,将所有数分成两类,每一类中又分两组,第一类有1,2,3和4,5,6,7两组,第二类有8,9两个数。计算同一类中两组的先后关系,也就是说,4,5,6,7之间的先后暂不计算,但算这4个数和1,2,3之间的先后关系。

第三遍,继续细分成4类 第一类有 两组 1,和2,3, 第二类有4,5,和6,7.第三类有8,9一组
再一遍计算同一类中两组的先后关系。

最后一遍,所有数两两分类:{1},{2,3}{4,5}{6,7}{8,9}每一类中有两个数,计算这两个数的先后关系。

将此4遍的结果加起来,就是最后的结果。


另外其实此题有更直观的解法
先建立空集S, 对排列依次做,取出排列的第i个元素\(a_i\)
求得S中比\(a_i\)大的元素个数\((rank(a_i)\), 令\({b_a}_i=rank(a_i)\)
将\(a_i\)放入S中

于是问题就转化为,是否有数据结构可以在\(log(n)\)的时间内做到插入和计算rank的操作,这是可能的,只需要简单修改平衡二叉树,例如AVL树,在每个节点保存左右子树的节点数即可。因为AVL的插入和查找都是\(log( n)\)级别的操作。而加上左右子树节点数后,查找操作可以得出当前树中比目标数大的个数的值。

Saturday, October 2, 2010

iText 的中文显示问题

iText是用Java建立pdf文档的一个库。对于中日韩字体文档,iText也有相应的支持,按照说明,只需将iTextAsian.jar放在classpath内,然后创建相应字体即可。但昨天试图建立中文pdf的时候,发现创建字体出错。

google结果只说需要正确设置classpath,这应该不是问题。

下载iText源码,然后跟踪,问题出在判断字体是否是cjk部分,接着发现在判断cjk的时候,properties文件并未正确找到,最后发现在CJKFont类里面,properties文件的位置写在com.itextpdf.text.pdf.fonts包内,而iText网站提供的iTextAsian.jar却用了com.lowagie.text.pdf.fonts做包名。

解决办法,自己做一个jar,把iTextAsian中的属性文件展开后再拷贝到正确的目录结构,然后再打包成jar,然后替换程序里引用的那个iTextAsian.jar即可。

Sunday, September 5, 2010

双彩虹






今天下午五点半开始,天空出现双彩虹,差不多持续了两个钟头。彩虹几乎是两个很完整弧形。

Saturday, August 7, 2010

纽约市长布隆伯格关于下曼哈顿清真寺的演讲

“We've come here to Governors Island to stand where the earliest settlers first set foot in New Amsterdam, and where the seeds of religious tolerance were first planted. We come here to see the inspiring symbol of liberty that more than 250 years later would greet millions of immigrants in this harbor. And we come here to state as strongly as ever, this is the freest city in the world. That's what makes New York special and different and strong.
我们来到总督岛,站立在先民第一次踏上新阿姆斯特丹之处,这也是宗教宽容的种子首次播下的地方。我们来到这里,望着这激发人心的自由的象征,二百五十年来,在这个港口,她迎接了数百万计的移民。我们来到这里,也是一如既往地,坚定宣告,这是世界上最自由的城市。这即是纽约独特、不同和强盛的缘由。

“Our doors are open to everyone. Everyone with a dream and a willingness to work hard and play by the rules. New York City was built by immigrants, and it's sustained by immigrants -- by people from more than 100 different countries speaking more than 200 different languages and professing every faith. And whether your parents were born here or you came here yesterday, you are a New Yorker.
我们的大门对所有人敞开。包括所有怀揣着梦想,以及乐意艰苦工作,遵守规则的人。纽约市是移民建立的,也是移民支撑起来的,这些人们来自一百多个国家,操着两百多种语言,持有各种信仰。不管是你的双亲生长于此,还是你昨天才来,你都是纽约人。

“We may not always agree with every one of our neighbors. That's life. And it's part of living in such a diverse and dense city. But we also recognize that part of being a New Yorker is living with your neighbors in mutual respect and tolerance. It was exactly that spirit of openness and acceptance that was attacked on 9/11, 2001.

我们不一定总是赞同每一位邻居。这是现实。这也是在这么一个多元而又稠密的城市生活的一部分。但我们同样意识到,当一个纽约人的一部分,就是要同你的邻人在互相尊重容忍下共同生活。也就是这种开放和接受的精神,在2001年9月11日遭到了攻击。
“On that day, 3,000 people were killed because some murderous fanatics didn't want us to enjoy the freedoms to profess our own faiths, to speak our own minds, to follow our own dreams, and to live our own lives. Of all our precious freedoms, the most important may be the freedom to worship as we wish. And it is a freedom that even here -- in a city that is rooted in Dutch tolerance -- was hard-won over many years.
当日,3000人丧生,因为某些疯狂凶徒不想让我们享有拥有自己信仰,表达自己意愿,实现自己梦想,过自己生活的自由。在我们所有珍贵的自由里,最重要的大概就是按自己的意愿信教的自由。这种自由,即便是在这里,在一个植根于荷兰式的宽容的城市,也是经过长年的奋斗取得的。

“In the mid-1650s, the small Jewish community living in lower Manhattan petitioned Dutch governor Peter Stuyvesant for the right to build a synagogue, and they were turned down. In 1657, when Stuyvesant also prohibited Quakers from holding meetings, a group of non-Quakers in Queens signed the Flushing Remonstrance, a petition in defense of the right of Quakers and others to freely practice their religion. It was perhaps the first formal political petition for religious freedom in the American colonies, and the organizer was thrown in jail and then banished from New Amsterdam.
1650年代中期,住在下曼哈顿的小小犹太社区向荷兰总督Peter Stuyvesant 请愿,要修一座犹太教堂,他们被拒绝了。1657年,Stuyvesant又禁止贵格教徒集会,皇后区的一群非贵格教徒签署了《法拉盛抗议书》,这是捍卫贵格以及其他群体自由行使宗教的请愿书。这可能是在美洲殖民地第一次为宗教自由而进行的政治请愿,组织者被投入监狱后又被逐出新阿姆斯特丹。

“In the 1700s, even as religious freedom took hold in America, Catholics in New York were effectively prohibited from practicing their religion, and priests could be arrested. Largely as a result, the first Catholic parish in New York City was not established until the 1780s, St. Peter's on Barclay Street, which still stands just one block north of the World Trade Center site, and one block south of the proposed mosque and community center.
1700年代,即使在宗教自由在美国扎根的时候,纽约的天主教徒仍然被禁止进行他们自己的宗教活动,神父也有被抓的危险。其后果就是,纽约市的第一个天主教教区直到1780年代才得以建立。教区座堂,圣彼得教堂设在Barclay街,现在仍矗立在世贸中心北仅仅一个街区,也即是现今要建立的清真寺和社区以南一个街区处。

“This morning, the city's Landmark Preservation Commission unanimously voted to extend -- not to extend -- landmark status to the building on Park Place where the mosque and community center are planned. The decision was based solely on the fact that there was little architectural significance to the building. But with or without landmark designation, there is nothing in the law that would prevent the owners from opening a mosque within the existing building.
今天上午,市标志建筑保护委员会全票通过,不再将计划中要改建为清真寺和社区中心的Park广场建筑物立为标志性建筑。这项决定,仅仅是基于那幢建筑物并无太大建筑上的意义这一事实上做出的。但是不管是否是标志性建筑,都没有法律禁止房主在那里开设清真寺。

“The simple fact is, this building is private property, and the owners have a right to use the building as a house of worship, and the government has no right whatsoever to deny that right. And if it were tried, the courts would almost certainly strike it down as a violation of the U.S. Constitution.
事实很简单,那幢楼是私有地产,屋主有权将其用做宗教场地,政府绝无权力否认屋主的权益。如果此事诉诸法庭,几乎可以肯定法庭将会认定这是侵犯美国宪法。

“Whatever you may think of the proposed mosque and community center, lost in the heat of the debate has been a basic question: Should government attempt to deny private citizens the right to build a house of worship on private property based on their particular religion? That may happen in other countries, but we should never allow it to happen here.
不管你对构想中的清真寺和社区中心怎么想,在激烈争论中被人忘却的是一个基本问题:政府应不应该禁止公民在自己拥有的地产上,按自己所属的宗教信仰,建立宗教场所?或许别的国家会禁止,但我们绝对不应该让这种事情发生在这里。

“This nation was founded on the principle that the government must never choose between religions or favor one over another. The World Trade Center site will forever hold a special place in our city, in our hearts. But we would be untrue to the best part of ourselves and who we are as New Yorkers and Americans if we said no to a mosque in lower Manhattan.
这个国家得以建立的基本原则,就是政府绝不可在宗教中扶持一支打压一支。世贸遗址在我们城市,在我们心中,将永远占据一个特殊位置。可是,如果我们容不下在下曼哈顿设一座清真寺,我们就是在背叛自己最大的善,背叛我们作为纽约人,作为美国人的身份。

“Let us not forget that Muslims were among those murdered on 9/11, and that our Muslim neighbors grieved with us as New Yorkers and as Americans. We would betray our values and play into our enemies' hands if we were to treat Muslims differently than anyone else. In fact, to cave to popular sentiment would be to hand a victory to the terrorists, and we should not stand for that.
让我们不要忘了,在9/11遇难者中,也有穆斯林,我们的穆斯林邻人,同作为纽约人,美国人,和我们一起哀悼。如果我们区别对待穆斯林,那就是背离自己的价值,而正中敌人的下怀。实际上,如果陷入感情用事之地,就等于将胜局奉送给恐怖分子,我们绝不能容忍此事。

"For that reason, I believe that this is an important test of the separation of church and state as we may see in our lifetimes, as important a test. And it is critically important that we get it right.
因此,我相信,此刻是对政教分离原则的重要考验,可能是我们此生中可见证的最重要考验。至关紧要的是我们也必须通过这次考验。

"On Sept. 11, 2001, thousands of first responders heroically rushed to the scene and saved tens of thousands of lives. More than 400 of those first responders did not make it out alive. In rushing into those burning buildings, not one of them asked, 'What God do you pray to?' (Bloomberg's voice cracks here a little as he gets choked up.) 'What beliefs do you hold?'
2001年9月11日,众多救护人员英勇的冲向现场,拯救了成千上万条性命。400多位救护人员献身。在冲入烈火焚烧的大厦的时候,没人问:“你向那个神祈祷?”“你信仰什么?”

"The attack was an act of war, and our first responders defended not only our city, but our country and our constitution. We do not honor their lives by denying the very constitutional rights they died protecting. We honor their lives by defending those rights and the freedoms that the terrorists attacked.
那场袭击即是战争行为,我们的救护人员捍卫的不仅是我们的城市,也是我们的国家和宪法。我们不能以否定他们献身保卫的宪法原则来纪念他们。恐怖分子所攻击的权利和自由,我们要捍卫它们,以慰英灵。

"Of course, it is fair to ask the organizers of the mosque to show some special sensitivity to the situation, and in fact their plan envisions reaching beyond their walls and building an interfaith community. But doing so, it is my hope that the mosque will help to bring our city even closer together, and help repudiate the false and repugnant idea that the attacks of 9/11 were in any ways consistent with Islam.
当然,要求建造清真寺的组织者对事态保持一些特别的敏感,这也不为太过,事实上他们的计划构想了不拘于壁垒,建设一个跨种信仰社区的前景。我希望,此清真寺能帮助我们城市更紧密的团结在一起,并帮助消弭9/11袭击是和伊斯兰有相承关系的虚假恶念。

"Muslims are as much a part of our city and our country as the people of any faith. And they are as welcome to worship in lower Manhattan as any other group. In fact, they have been worshipping at the site for better, the better part of a year, as is their right. The local community board in lower Manhattan voted overwhelmingly to support the proposal. And if it moves forward, I expect the community center and mosque will add to the life and vitality of the neighborhood and the entire city.
穆斯林同其他信仰的人们一样,是我们城市和我们国家的一部分。和其他族群一样,我们也欢迎他们在下曼哈顿进行宗教活动。事实上他们已经在那里正当行使他们的宗教权利有近一年了。下曼哈顿地方社区委员会以压倒多数通过了提议。如果事态继续顺利进行,我期待社区中心和清真寺将会对附近小区,以及整个城市带来新的生机和活力。

"Political controversies come and go, but our values and our traditions endure, and there is no neighborhood in this city that is off-limits to God's love and mercy, as the religious leaders here with us can attest."
政治争议来去无常,但我们的价值和传统长存,在这个城市,没有一个社区不能享有神的仁爱,此间的宗教领袖可为此立证。