* Category for Code *

24
May
2008

    Salut ! Tout le monde, je vous représente d’ici un jeu de programmation intéressant que nous avons réalisé en utilisant VB pendant ce semestre à l’université. Pour qu’on peut partager les expériences et se progresser.

Sujet : Le jeu de l’ultimatum se présente de la façon suivante :

2 individus (A et B) se partagent une somme S = 100 ;
A (le proposant) offre à B (le répondant) une part X de cette somme, c’est à dire,
A reçoit une somme (S-X) ; B reçoit une somme X ;
Si répondant B accepte la proposition, les 2 gagent la somme indiquée au-dessus;
Si répondant B n’accepte pas, les 2 n’obtiennent rien du tout;

    (Au sens de la théorie des jeux, s’ils sont rationnels, la proposition (X=1 ; S-X=99) est un équilibre parfait).     On suppose que l’on a 49 individus qui répètent ce jeu un certain nombre de fois :

A chaque fois, chaque individu joue le rôle de proposant avec un répondant choisi au hasard.

    La stratégie de chaque individu est la suivante :

Choisir 2 nombres entiers au hasard mais entre 0 et 100, prop et accept ; Quand il est proposant il offre toujours prop à l’autre; Quand il est répondant il accepte si et seulement si la répartition offerte est supérieure ou égale à accept.

Read the rest of this entry »

05
Apr
2008

比较和逻辑运算符

             符    号

        含    义

             类    型

      示    例

= =

等于

比较

$x == $y

!=

不等于

比较

$x != $y

小于

比较

$x < $y

大于

比较

$x > $y

<=

小于或等于

比较

$x <= $y

>=

大于或等于

比较

$x >= $y

!

逻辑

!$x

&&

逻辑

$x && $y

||

逻辑

$x || $y

XOR

异或

逻辑

$x XOR $y

Read the rest of this entry »

01
Apr
2008

Finally, I’ve fixed the problem of language recognition.

Before, my site can not filter the posts very well in a language which is determined by the browser’s language setting to show on the homepage.
When I use the code :
<?php if ($_SERVER["HTTP_ACCEPT_LANGUAGE"] != “zh-CN”) {query_posts(’cat=57,16′);} ?>
in homepage, the posts can be filtered correctly in IE7: If your browser’s language setting is zh-CN, the homepage will show all the posts, else, the homepage will show all the posts in category ID 57/16.
But in IE6 or FireFox, it doesn’t work. Because the browser’s language setting is “zh-cn”, it’s not “zh-CN”.

So I added a condition :
<?php
            $lan=&$_SERVER["HTTP_ACCEPT_LANGUAGE"];
            if (($lan != “zh-CN”)&&($lan != “zh-cn”)) {query_posts(’cat=57,16′);}
?>

Maybe it is not very “beautiful”, but it works very well for me! So hope it can help you! Maybe one day, I can make it smarter!

Ps: The codition part is a general format in PHP code, but the execute part is only for Wordpress!

29
Feb
2008

div+css实现圆角边框,代码如下:

<html>
<head>
<style>
#a{
border-left:1px #333 solid;
border-right:1px #333 solid;
width:300px;
height:500px;
}
.b{
height:1px;
overflow:hidden;
border-left:1px #333 solid;
border-right:1px #333 solid;
}
</style>
</head>
<body>
<div>
<div class=”b” style=”margin-left:3px;width:294px;background:#333″></div>
<div class=”b” style=”margin-left:2px;width:296px;”></div>
<div class=”b” style=”margin-left:1px;width:298px”></div>
<div id=”a”>

我能做到的,纯DIV+CSS实现的效果,只能这样了。这里是放置内容的地方,观察一下代码的规律,很容易明白。

代码很简单,a层为放置内容的层,其width值为300,然后向外以2像素的宽度递减。最外一层要加上background为个属性,目的是要将上、下两线条呈现出来。

这里实现了3像素的圆角边框,b层的数量决定了要实现多少个像素边框。建议不要多于3层,最好是2层,即2像素圆角边框,或者1层,因为层数越多,圆角的表现就越不圆滑。在firefox  IE6 都通过测试。

</div>
<div class=”b” style=”margin-left:1px;width:298px”></div>
<div class=”b” style=”margin-left:2px;width:296px;”></div>
<div class=”b” style=”margin-left:3px;width:294px;background:#333″></div>
</div>
</body>
</html>

27
Feb
2008

See this post in : English Version or Chinese Version

Private Sub Command1_Click()
 r = InputBox(”Entrez un chiffre pour vérifier, SVP”)
 For i = 2 To r
   If Val(r) Mod i = 0 And i <> Val(r) Then ‘Ici donne une condition pour les non premiers nombres
    MsgBox (”Ce n’est pas un premier nombre”)
    Exit Sub
   End If
 Next i
 MsgBox (”C’est un premier nombre”)
End Sub

Read the rest of this entry »