More servicesWindows Live
HomeHotmailSpacesOneCare
 
MSN
Sign in
 
 
Spaces home  ArrixPhotosProfileFriendsMore Tools Explore the Spaces community

Arrix

View spaceSend a message
Occupation:
Age:
Interests:
I cannot choose the best.
The best chooses me.
Life is an event.
Don't just be a handler!
Updated 12/1/2007
Updated 7/16/2008
Updated 7/8/2005
Updated 6/5/2005
Updated 4/30/2006
Updated 2/18/2005

Arrix

We are all machines with a will that we wish to be free
View space
吉泽拓也
View space
VIVIAN
View space
晓慧
View space
LittleDemon
View space
籽鱼
View space
晓瑜
View space
View space
Chanceux.sa
View space
小迷
View space
Sunny'
View space
︷SмΙιē
View space
小虎
View space
YANG
View space
叶子
View space
Giggle
View space
北京枣园居宾馆
View space
haiming
View space
晓玲
View space
HuangXiang
View space
View space
楠楠
View space
水双巨哈哈
View space
Jessy
View space
刘巨
View space
View space
akina
View space
Emma
View space
Maggie
View space
华哥
View space
逻各斯
View space
Srain
View space
wendy
View space
Vera
View space
生命要继续。
View space
xumingjin_up
View space
请叫我、Meng

7/17/2008

C# 3.0 一行求方差

某python程序员说用C#求方差需要五十行。于是我试了试

python
def variance (*l):
      return sum([(i - sum(l) * 1.0 / len(l)) ** 2 for i in l]) / len(l)

C#

Func<List<double>, double> variance = numbers => 
                (from n in numbers select Math.Pow((n - numbers.Sum() / numbers.Count), 2)).Sum() / numbers.Count;

Console.Write(variance(new List<double> { 1, 2, 5, 6 }));
我很久没干过这么无聊的事情了……
7/16/2008

三角形拼图 这怎么可能?

missingsquare

我看了半天没看出破绽,于是用Canvas + jQuery UI做了个网页拼图,拼了半天终于发现了其中的奥妙。

我讨厌剧透,所以贴出代码占位,以免想独立思考的同学意外看到答案。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Missing Square?</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="ui.core.js"></script>
        <script type="text/javascript" src="ui.draggable.js"></script>
        <script type="text/javascript" src="missingsquare.js"></script>
    </head>
    <body>
        <div style="float:left"><img src="missingsquare.jpg"/></div>
        <div style="float:left; margin: 10px"><canvas id="canvas-grid" width="150px" height="150px"></canvas></div>
    </body>
</html>
missingsquare.js
 
$(init);
 
var cellWidth = 18.5, cellHeight = 15;
 
function init() {
    drawGrid();
    drawTriangle1();
    drawTriangle2();
    drawPoly1();
    drawPoly2();
    
    $('#canvas-triangle1,#canvas-triangle2,#canvas-poly1,#canvas-poly2').draggable();
}
 
function drawGrid() {
    var cellCountX = 15, cellCountY = 15;
    var c = document.getElementById('canvas-grid');
    c.width = cellWidth * cellCountX + 1;
    c.height = cellHeight * cellCountY + 1;
    var ctx = c.getContext('2d');
    
    ctx.fillStyle = 'white';
    ctx.fillRect(0, 0, c.width, c.height);
    ctx.strokeStyle = 'rgb(127, 127, 127)';
    for (var i = 0; i <= cellCountX; i++) {
        ctx.moveTo(i * cellWidth, 0);
        ctx.lineTo(i * cellWidth, c.height);
        ctx.stroke();
    }
    
    for (var i = 0; i <= cellCountX; i++) {
        ctx.moveTo(0, i * cellHeight);
        ctx.lineTo(c.width, i * cellHeight);
        ctx.stroke();
    }
}
 
function drawTriangle1() {
    var canv = document.createElement('canvas');
    document.body.appendChild(canv);
    canv.id = 'canvas-triangle1';
    canv.width = cellWidth * 5;
    canv.height = cellHeight * 2;
    
    var ctx = canv.getContext('2d');
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'rgba(4, 145, 110, .5)';
    ctx.beginPath();
    ctx.moveTo(0, canv.height);
    ctx.lineTo(canv.width, canv.height);
    ctx.lineTo(canv.width, 0);
    ctx.fill();
    ctx.closePath();
    ctx.stroke();
}
 
function drawTriangle2() {
    var canv = document.createElement('canvas');
    document.body.appendChild(canv);
    canv.id = 'canvas-triangle2';
    canv.width = cellWidth * 8;
    canv.height = cellHeight * 3;
    
    var ctx = canv.getContext('2d');
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'rgba(194, 5, 3, .5)';