Created
January 10, 2010 11:03
-
-
Save erikbgithub/273437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$res = mysql_pconnect("localhost","root","root"); | |
mysql_query("DROP Database 'ddpadd'",$res); | |
echo ":\n<br>create:".mysql_query("CREATE DATABASE IF NOT EXISTS ddpadd", $res); | |
echo ":\n<br>select:".mysql_select_db("ddpadd", $res); | |
echo mysql_query("DROP TABLE IF EXISTS decimal"); | |
echo ":\n<br>table:".mysql_query("CREATE TABLE decimal_add ( | |
no1 TINYINT(1), | |
no2 TINYINT(1), | |
output_wo TINYINT(1), | |
output_w TINYINT(1), | |
nextstate_wo CHAR(2), | |
nextstate_w CHAR(2), | |
PRIMARY KEY (no1, no2), | |
UNIQUE (no1, no2, output_wo, output_w), | |
UNIQUE (no1, no2, nextstate_wo, nextstate_w) | |
)",$res); | |
echo ":\n<br>table:".mysql_query("CREATE TABLE binary_add ( | |
no1 TINYINT(1), | |
no2 TINYINT(1), | |
output_wo TINYINT(1), | |
output_w TINYINT(1), | |
nextstate_wo CHAR(2), | |
nextstate_w CHAR(2), | |
PRIMARY KEY (no1, no2), | |
UNIQUE (no1, no2, output_wo, output_w), | |
UNIQUE (no1, no2, nextstate_wo, nextstate_w) | |
)",$res); | |
/*== decimal table filling ==*/ | |
$sql="INSERT INTO decimal_add VALUES \n"; | |
for($x=0; $x < 10; $x++){ | |
for($y=0; $y < 10; $y++){ | |
$sum_wo=($x+$y)%10; | |
$sum_w=($sum_wo+1)%10; | |
$state_wo = "w"; | |
if(($x+$y) < 10) { | |
$state_wo = "wo"; | |
} | |
$state_w = "w"; | |
if(($x+$y+1) < 10) { | |
$state_w = "wo"; | |
} | |
$sql.="($x,$y,$sum_wo,$sum_w, '$state_wo', '$state_w')"; | |
if(!($x==9 && $y==9)){ | |
$sql.=",\n"; | |
} | |
} | |
} | |
echo mysql_query($sql,$res); | |
/*== end of decimal filling ==*/ | |
/*== binary table filling ==*/ | |
$sql = "INSERT INTO binary_add VALUES \n"; | |
$sql.= "(0,0,0,1,'wo','wo'),\n"; | |
$sql.= "(0,1,1,0,'wo','wo'),\n"; | |
$sql.= "(1,0,1,0,'wo','wo'),\n"; | |
$sql.= "(1,1,0,1,'w','wo')\n"; | |
echo mysql_query($sql,$res); | |
/*== end of binary filling =*/ | |
echo ":\n<br>error:".mysql_error().":"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment