十兔子的故事 zz

| Thursday, November 19, 2009
这个推理果然很牛啊 各种无厘头

==================

【史上最经典推理之一】兔子谋杀案(推理)
大兔子病了,
二兔子瞧,
三兔子买药,
四兔子熬,
五兔子死了,
六兔子抬,
七兔子挖坑,
八兔子埋,
九兔子坐在地上哭泣来,
十兔子问它为什么哭?
九兔子说,
五兔子一去不回来!
有看出门道的没?

正常推理:这是一件密谋杀兔事件。
1.首先,兔子也是有阶级的,大兔子病了,要治它的病,就必须不惜一切代价,甚至牺牲一只兔子做药引。

2.病的是大兔子,五兔子却突然死了,显然是被做成了药引。

3."买药"其实是黑话,因为实际上只需要一些简单的草药,主要是药引,所以这个"买药"指的是去杀掉做药引的兔子,三兔子是一个杀手。

4.做药引的为什么是五兔?因为哪只兔子适合做药引是由医生决定的,二兔子就是医生。

5.可以推出,二兔子借刀杀兔搞死了五兔子,他们之间有什么过解呢?可能是情杀,因为一只母兔。

6.谁是母兔呢?想一下,女人爱哭的天性,所以九兔是母兔,九兔也知道了真相,所以才哭,因为她爱的是五兔。

7."六兔子抬",这明显是病句,一只兔子怎么抬?他显然是被抬,因为他死了,所以才会被抬。抬他的两只兔子随后一个挖坑,一个埋尸。没错,抬他来的就是七八两只兔子!

8.六兔子是被七八两只兔子杀的吗?不是,他是被杀手三兔子杀死的。三兔子本来不想杀他,五兔子和六兔子关系非常好,当时他们正好在一起,并联手抵抗,所以三兔子才把他们一起杀了。

9.
最后一点分析了,也许是多余。事情是这样的,三兔和五六两兔打斗过程中,引来了七八两兔。当五六被杀死后,三兔已没有力气,况且七八平时都很听话,不会告
密的。所以三兔就放过了七八两兔,并让他们把六兔抬走,埋了。七八一看,命保住了,反正事情也发生了,无法挽回,只好照办理。
 

大家会发现,每相临的两只兔子关系都是微妙的。

1-2 大兔子像皇上,二兔子就是他身边进谗言的小人。
3-4三兔子是杀手,四兔子药师,他俩都是助纣为虐型的,四兔经常给皇帝做一些壮阳药什么的,把皇上搞生病了,又亲自熬兔子药引。
5-6一对好朋友,经常在一起吟诗做对,不惧怕恶势力,五兔很有才华,怪不得被九兔所爱又被二兔嫉妒呢,物以类聚,六兔也很有才,可惜都属于文人,两个人的武工加一起也没打过三兔。
7-8也是一对好朋友,但属于随风倒型的,为了保住命,什么事都肯做,本质不算坏,但经常被坏人指始做坏事。
9-10在女人哭的时候,身边一定会有爱她的男人,而她的哭泣一定是为了她爱的男人。可惜,爱她的兔子和她爱的兔子不是一只兔子。很明显了吧,十兔暗恋九兔,关心她,看到她哭,他当然要去问原因。

后记1:回看第5条,情杀不是随便猜出来的,观全局,二兔位高权重,但即便这样,也有他得不到的东西,那就是真爱。所以他杀五兔的原因很可能是这个,而且五兔正直,应该平时就经常与他作对,所以才起了杀心。

后记2:其实五兔死的非常惨,因为二兔疯狂妒忌他,所以不想让他成为一个正常的男人。再说皇上吃了药师的药,荒淫无度,哪里最虚弱大家应该都知道吧,所谓吃什么补什么,其实五兔被做成药引的部位应该是...

推理的补充
(1)作为一个完整的故事,必然要有因果关系,这个故事有了果(即情杀,下面再谈),但没有因,所以显得不完整,就是大兔子为什么病了?无缘无故的病了便引发了以下的血案么?显然不是.

(2)
从一个严密的逻辑上来看,这个故事中所有人物的出现(兔子)都是有联系的,且每一个按序列排下来的兔子之间都存在因果关系(动机),比如:
大兔和二兔,二兔和三兔.三兔和四兔(这个上文已经大致说明了,我就不进一步讲了),但大家有没有觉得,10兔子的出现好象在这个逻辑中显得微不足道,即
没有10兔子这个故事也能顺理成章的结束,因此10兔子在这个逻辑中的动机显得苍白.

结论:

据以上的推断,我们都忽视了这个故事的重点,就是10兔子,他为什么出现在这个故事中?难道仅仅为了引出9兔子的一句话么?错了,这是一个有预谋的凶杀
案,而且,10兔子就是这个案件的主谋(不是2兔子),其他所有的兔子都是在他全盘计划中的一枚棋子,案发过程大致如下(补充上文):
(1)10兔子喜欢9兔子,9兔子不喜欢他
(2)5兔子和9兔子互相喜欢
(3)10兔子妒忌
(4)10兔子是大兔子身边最亲信的人,并且对其他兔子之间的关系了如指掌(也就是说,他很清楚大兔子如果病了接下来会发生些什么事),(比如10兔子就像是熬拜,大兔子是康熙)
(5)5兔子也是朝中权贵,10兔子没办法随便处置他.
(6)所以10兔子就让大兔子病了,接下来的一切就像上文说的那样发生了.....
所以,贯穿整个这个故事的主线就是10兔子,他是这个故事的结尾也是这个故事的主因,这样这个逻辑才显得天衣无缝,故事的名字就是:借刀杀人!

================

bl推理:情况是十只兔子都是都是男性

杀也有可能是二兔子爱五兔子,而后五兔子爱九兔子,
然后由同一句话叫做"我得不到的也不可能叫别人得到",所以就因爱生恨杀了五兔子,然后自己痛苦的活着,或者是只是把五兔子内什么弄了下来,然后囚禁在身
边一生一世,有一句话叫做"我得不到你的人就得到你的心" 所以,二兔子也很可怜的。

十兔子
和九兔子是一对,七兔子和八兔子是一对。然后,六兔子喜欢五兔子,大兔子喜欢六兔子,四兔子喜欢大兔子,三兔子喜欢四兔子,五兔子被二兔子弄走,而六兔子
被大兔子救走,大兔子让四兔子救六兔子,但是四兔子给六兔子下了毒,三兔子不想让四兔子被大兔子弄死,就救了六兔子。然后掌握全局的大兔子早就知道这一
切,他把逼疯了四兔子,威胁三兔子去杀九兔子,不然就杀了四兔子。即使四兔子疯了三兔子也要。
上文提到大兔子掌握全局,然后他知道十兔子要九兔子,所以如他所愿,因为大兔子知道有了权力的人就不能有最重要的人,容易被人威胁。
显然大兔子必将会和十兔子争皇位,到那时,死的肯定先是六兔子和九兔子。
他为了保护六兔子必须杀了十兔子,九兔子便是十兔子的弱点,只要用九兔子威胁十兔子,就可以独揽大权。

二兔子那得知九兔子要被杀死的五兔子要去救他,但是二兔子不同意(典型的吃醋),经过一系列五兔子的说服二兔子同意了,但要叫着高手去(不然他去送死啊
不会武功)。但是,五兔子没有及时赶到,三兔子也没有得逞,只是把九兔子掠去,找大兔子复命。五兔子回来求二兔子救九兔子,二兔子招架不住去了。结果,大
兔子和十兔子挑明了谈,十兔子带九兔子浪迹天涯,大兔子给了十兔子足够他和九兔子一辈子的花销,放他们走了。七兔子和八兔子随风倒,不受威胁。而大兔子把
已经疯了的四兔子给了三兔子,也放他们远走天涯。最后,大兔子和六兔子二兔子和五兔子在了一起。

补充1:三兔子是杀手,却动了情,只要稍微控制四兔子就可以让他杀了九兔子。如果可以连十兔子一起斩草除根,以绝后患,避免十兔子到最后拼个鱼死网破。有人会问直接叫他去杀不就行了吗,至于绕怎么一大圈子嘛?答案是至于,因为大兔子不确定三兔子是谁的人。

充2:为什么大兔子听二兔子的话,他们俩一定有不可告人的秘密,不然二兔子早就死了,如此有魄力的君王一定不会任一个谗言小人摆布;又因为如果被大兔子爱
上了就一定不会逃出他的掌控,所以大兔子与二兔子不是情人,那只有可能是最亲密的人。一代君王除了爱人以外最亲密的人莫过于与不会威胁到他的人,这其中最
有可能的的就是兄弟。所以二兔子可能是上代君王的私生子 或许二兔子动用了什么权利,使大兔子放过了十兔子
最后的结果就是权力争斗

/^1?$|^(11+?)\1+$/

|
the above regular expression could be used to check a number is prime or not! is it amazing? like a magic!

but we know there is no magic in CS.. well, this link has a great explanation.

amazing!

Google GO (5) - "Effective Go" Notes

| Monday, November 16, 2009
Effective GO link

"gofmt" could do the code formatting for you.

Underscore (_), is the blank identifier, provides a way to ignore values returned by a multi-valued expression.
x, _ = f() // ignore second value returned by f()


use range to help for loop
for _, value := range m { // key is unused
sum += value
}


In switch, cases can be presented in comma-seperated lists
switch c {
case ' ', '?', '&', '=', '#', '+', '%':
return true
}


Switch can be used to discover the dynamic type of an interface variable.
switch t := interfaceValue.(type) {
default:
fmt.Printf("unexpected type %T", type); // %T prints type
case bool:
fmt.Printf("boolean %t\n", t);
case int:
fmt.Printf("integer %d\n", t);
case *bool:
fmt.Printf("pointer to boolean %t\n", *t);
case *int:
fmt.Printf("pointer to integer %d\n", *t);
}


Functions support multiple returns, such as
func nextInt(b []byte, i int) (int, int)

Named return parameter is initialized by zero, and return by current value if return with no arguments.

Composite literal, could use
return &File{fd, name, nil, 0};
or labels inside
return &File{fd: fd, name: name}


new() returns the pointer with all zeroed memory.

make(T, args) creates slices, maps and channels.

Arrays, when it is passed to a function, it is a copy of the array, not just the pointer.

The size of an array is part of its type, which means [10]int and [20]int are distinct.

len(slice) -> length, cap(slice) -> capacity

In if statement, the expression may be preceded by a simple statement, which executes before the expression is evaluated.
if x := f(); x < y {


Go's memory sharing design:
Do not communicate by sharing memory; instead, share memory by communicating.


Buffered channel & Unbuffered channel
ci := make(chan int); // unbuffered channel of integers
cj := make(chan int, 0); // unbuffered channel of integers
cs := make(chan *os.File, 100); // buffered channel of pointers to Files


Channels could be used as semaphore
var sem = make(chan int, MaxOutstanding)

func handle(r *Request) {
sem <- 1; // Wait for active queue to drain.
process(r); // May take a long time.
<-sem; // Done; enable next request to run.
}

周末好生活 - 不要等到80岁

|
似乎很少描述生活 不过有几件事可以小提一下

一来去看了电影2012 算是近几年来比较想看的电影之一吧 场面还是很帅 看到镜头里的中国人中文英文讲得都挺标准很感动 还提到了痞子堡 另外看到vegas倒掉了感觉超爽哈 我好像有点幸灾乐祸的超希望灾难来得更厉害一点 =)

二来稍微看了一会儿Google GO,这个语言果然很有意思,并且因为毕竟是Google的手笔,光看irc上平均500的常驻人群和日均300条的邮件列表就可见一斑了。在reddit上看到最牛的代码,可以从ruby -> python -> perl -> lua -> ocaml -> haskell -> c -> java -> brainfuck -> whitespace -> unlambda -> ruby 绕了一圈还能转回来实在太牛了!

三来我一直想着80岁的时候,今天突然意识到这可能就成了借口了。一直想能在八十岁的时候,牵起老伴的手,对她说声谢谢。现在看来,八十岁还是太遥远了,理解当时某人的批评。何况,能不能活到八十还是回事呢。把自己的生命定格在三十五,平均来看,还应该是比较明智的。

晃一晃 学期又只剩不到一个月了 说来日子好快 还有几个project要解决一下 然后去hawaii看美女去!

纯手工尸体 和 锁的故事

| Sunday, November 15, 2009
淘宝上有卖蚊子尸体的,链接在这里:来自安徽亳州的正宗蚊子尸体苍蝇尸体,纯手工打死,死状优美,1口价,11元。orz

另外在Rich的Tweet上看到这个,很喷哈,链接在这里
I just had an argument with a girl I know. She was saying how it's unfair that if a guy fucks a different girl every week, he's a legend, but if a girl fucks just two guys in a year, she's a slut. So in response I told her that if a key opens lots of locks, then it's a master key. But if a lock is opened by lots of keys, then it's a shitty lock. That shut her up.

Google GO (4) - Tutorial Notes

|
Tutorial Notes

Three ways of declaration:
var s string = "";
var s = "";
s := "";

For Loop(parentheses no needed, braces mandatory):
for i := 0; i < flag.NArg(); i++ {

To signal an erroneous return, call
os.Exit(1)

Falling off main.main means "success"

Types are different even they are using the same bits. int and int32 are distinct, int and uint are distinct.

Strings are kinda const strings in C++, couldnt be changed.

Arrays
var arrayOfInt [10]int;

Slice variable reference a segment of an array
a[low : high]

function func sum(a []int) int {} could be called in multiple ways
s := sum(&[3]int{1,2,3}); // a slice of the array is passed to sum
s := sum(&[...]int{1,2,3}); // want compiler to count the elements
s := sum([]int{1,2,3});

Maps
m := map[string]int{"one":1 , "two":2}
Allocation
type T struct { a, b int }
var t *T = new(T);

or
t := new(T);

For maps, slices and channels which have reference semantics, using make() instead
m := make(map[string]int);

If a name (of a top-level type, function, method, constant or variable, or of a structure field or method) is capitalized, it is visible to the public, users of the package may see it. Otherwise, the name and hence the thing being named is visible only inside the package in which it is declared.

Open files
func Open(name string, mode int, perm int) (file *File, err os.Error)

Note there is a multi-value return here. err is nil if no error. Similarly, there are other methods for I/O
func (file *File) Close() os.Error
func (file *File) Read(b []byte) (ret int, err os.Error)
func (file *File) Write(b []byte) (ret int, err os.Error)
func (file *File) String() string

os.Error has a method called os.Error.String() could convert to a printing description.

Switch
switch nr, er := f.Read(&buf); true {
case nr < 0:
...
case nr == 0:
...
case nr > 0:
...
}


Interface is declared like
26 type reader interface {
27 Read(b []byte) (ret int, err os.Error);
28 String() string;
29 }

It is implemented by a type if the type implement *all* the methods declared in the interface. This means following empty interface is by default implemented by any type.
type Empty interface {}

Printf(), %v will print in a simple appropirate style by default. Print() and Println() would do the print fromatting automatically.

Type assertion, e.g. v.(Stringer) while Stringer is an interface, to see if v satisfies the Stringer interface.
s, ok := v.(Stringer); // Test whether v implements "String()"

Channel, a communications channel that connect two concurrent computations, using make() to create new channel.
09 // Send the sequence 2, 3, 4, ... to channel 'ch'.
10 func generate(ch chan int) {
11 for i := 2; ; i++ {
12 ch <- i // Send 'i' to channel 'ch'.
13 }
14 }
15
16 // Copy the values from channel 'in' to channel 'out',
17 // removing those divisible by 'prime'.
18 func filter(in, out chan int, prime int) {
19 for {
20 i := <-in; // Receive value of new variable 'i' from 'in'.
21 if i % prime != 0 {
22 out <- i // Send 'i' to channel 'out'.
23 }
24 }
25 }


Go routines, starting the function running in parallel in the same address space
go sum(hugeArray); // calculate sum in the background

Then check the result by passing channel
ch := make(chan int);
go sum(hugeArray, ch);
// ... do something else for a while
result := <-ch; // wait for, and retrieve, result

select statement choose which of the multiple communications listed can proceed
21 func server(op binOp, service chan *request, quit chan bool) {
22 for {
23 select {
24 case req := <-service:
25 go run(op, req); // don't wait for it
26 case <-quit:
27 return;
28 }
29 }
30 }

hahahaha - Win 7 @xkcd

| Thursday, November 12, 2009

Google GO (3)

|
原来还有个Tech Talk (pdf)。果然困了,半点都没看下去 o_O

不过如果GO如传说中编译的那么快的话,yy一下一分钟编译完firefox/OOo(当然要他们改用GO了)的场景,这样我一定没有借口不用Gentoo了。哈哈

letssseeee

Google GO (2)

|
果然是犯困了,刚才更新了env却跑到另一个term里执行...
skh-laptop/home/skh/temp
skh >>> 8g ./helloworld.go                                                                  09-11-12 2:41
skh-laptop/home/skh/temp
skh >>> 8l ./helloworld.8                                                                   09-11-12 2:41
skh-laptop/home/skh/temp
skh >>> ./8.out                                                                             09-11-12 2:41
Hello, 世界
skh-laptop/home/skh/temp
skh >>> ls -l 8.out                                                                         09-11-12 2:41
-rwxr-xr-x 1 skh skh 582423 2009-11-12 02:41 8.out*
这个hello world果然很大

Google GO

|
Google果然什么都开始搞了,昨儿推出了名为GO的新语言。今天睡觉前小看了一下GO的主页,还是很牛的。Design FAQ对GO的特性介绍的很清楚,GO的很多特性归结出来就是simple,code要simple,interpreter要simple,compiler要simple,debugger也要simple。

AUR上发现有人已经创建了go-lang的包了,于是安装了一下,编译过程果然如广告里介绍的一般,少于10s。不过尝试helloworld居然失败了,fmt package没找到。据说暂时还不支持dymanic linking,一个helloworld会超大,暂时没机会验证一下 =(
skh >>> 8g ./helloworld.go                                                                  09-11-12 2:28
./helloworld.go:3: fatal error: can't find import: fmt
困死了,改天再看看吧。

Guys are supposed to love naked women

| Monday, November 09, 2009
ehhh.. 今天在revise monologue的时候才发现自己之前选的片断还是很有攻击性的.. lol

但还是挺有意思,想想自己也要充满感情的念这段东西.. orz

How could I possibly enjoy a film like -- (He pauses, enjoying the title:) “Lesbian Spank Inferno”?

Because it has got naked women in it!

Look, I like naked women! I'm a guy! I'm supposed to like them! We're born like that.

We like naked women as soon as we're pulled out of one. Halfway down the birth canal, we're already enjoying the view.

Look, it's the four pillars of the male heterosexual psyche. We like: naked women, stockings, lesbians, and Sean Connery best as James Bond. Because that is what being a bloke guy is.

And if you don't like it, join the film collective.

Look: I want to spend the rest of my life with the woman at the end of the table here. But that does not stop me wanting to see several thousand more naked bottoms before I die. Because that's what being a guy is.

When Man invented fire, he didn't say "Hey, let's cook!"

He said: "Great! Now we can see naked bottoms in the dark!"

As soon as Gutenberg invented the printing press we were using it to make pictures of

- hey! - naked bottoms.

We've turned the Internet into an enormous international database of...

naked bottoms.

So, you see, the story of male achievement through the ages, feeble though it may have been, has been the story of our struggle to get a better look at your bottoms.

Frankly, girls, I'm not so sure how insulted you really ought to be.

选自Coupling, 下面片断里 from 4:26

BFS, CFS和O(1) Scheduler

| Sunday, November 08, 2009
今天抽空小研究了下传说中的CFS,顺便也看了一下BFS和以前的O(1)调度,再加上一点LKML上的八卦事,在这里扔点notes。

kernel 2.4之前一直用的某种O(N)调度算法,大概就是所有的cpu用1个全局的link list,也用一个超大的lock来做保护,这种坏处就不说了。

后来一个叫Ingo的人进入了kernel的dev,提出了O(1)算法,每个cpu都有一个run queue,O(1)算法就是我们在早年各种kernel书里必介绍的算法了,每个进程都有一个time slice,然后用完了就要被deschedule了。

再后来,CK大人(Con Kolivas)07年的时候提出了Rotating Staircase Deadline算法,基于Packet Switching中常用的fair queueing。这也就是大名鼎鼎的ck补丁(部分),但没能成功被kernel接纳。关于fair queueing可以参看wikipedia

之后Ingo在这个基础上写了CFS, Completely Fairness Scheduler。Ingo也是个牛人,他花了62个小时就写出了100k的CFS patch并且release了出去。当然CK大人就很不高兴了,于是在mailing list上有过一番争吵,然后CK似乎酒销声匿迹了。

CFS主要是用了virtual runtime的概念(对应fair queueing里的virtual time),每个进程都有维护一个vruntime,scheduler总是挑最小的那个switch过去。在每个时间中断时更新当前进程的vruntime值,vruntime+=ticks / weight,weight值根据nice值来确定的,是一个指数关系。一旦当前运行的进程不再是最小的vruntime,就会进行scheduling。数据结构CFS采用的是Red-black Tree,O(logn)复杂度,但又维护了一个变量保存left-most节点也就是queue里最小的vruntime。另外Ingo在写的时候对scheduler做了模块化,有个sched_class的structure,里面就是各种函数指针 orz。慢慢的,CFS就是我们现在的默认scheduler了。

关于CFS有些挺有用的资料:
1. 一个介绍的ppt: http://www.linux-foundation.jp/jp_uploads/seminar20080709/lfjp2008.pdf
2. http://www.ibm.com/developerworks/linux/library/l-cfs/index.html
3. Mailing list的一些讨论: http://kerneltrap.org/node/8208
4. Kernel代码里 Document/scheduler/sched-design-CFS.txt 和 kernel/sched_fair.c

两年之后,CK大人再次出山,带来了BFS,Brain Fuck Scheduler。CK认为现在的Scheduler包括CFS用在个人电脑上浪费了太多的cpu在处理scheduling和cpu load balance(kernel要支持4096个cpu)。BFS用了超简单的算法,来获得在并没有那么多核时的性能突破。BFS就是一个全局的List,一个lock(不算realtime的100个list和另外两个和算法关系不大的list),复杂度O(n)。BFS也是借鉴fair queueing,使用virtual deadline = jiffies + (prio_ratio * rr_interval)作为time slice,一个进程用完之后就不得不被schedule了。rr_interval是可配置的参数,CK在document里还给出了一些指导。

在CK发布没多久,Ingo同学就在Mailing list里发布了他对bfs的一些评测,但他错误的采用了公司非常nb的测试机,跑出来的结果不那么优秀。但用户们普遍反应在双核和四核机器上性能提升显著。

CK在FAQ里的几句话很有意思,用来作为收尾吧。改天有空我得去试试这个补丁 :D
Why "Brain Fuck"?

..
Because it's designed in such a way that mainline would never be interested
in adopting it, which is how I like it.
..
Because it throws out the philosophy that one scheduler fits all and shows
that you can do a -lot- better with a scheduler designed for a particular
purpose. I don't want to use a steamroller to crack nuts.
..
Because I must be fucked in the head to be working on this again.
I'll think of some more becauses later.

Morning, November!

| Monday, November 02, 2009

Random Posts

Powered by Stuff-a-Blog