Advertisement
imedvedev

Untitled

Mar 2nd, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <?
  2. function trueTable($x1, $x2, $x3, $x4) {
  3.     return implication(disjunction($x4, invers($x3, $x2)), xor2($x2, disjunction($x3, implication($x1, $x2)))) ? 1 : 0;
  4. }
  5.  
  6. function disjunction($x1, $x2) {
  7.     return $x1 || $x2;
  8. }
  9.  
  10. function conjunction($x1, $x2) {
  11.     return $x1 && $x2;
  12. }
  13.  
  14. function xor2($x1, $x2) {
  15.     return $a xor $b;
  16. }
  17.  
  18. function invers($x1, $x2) {
  19.     return !$x2;
  20. }
  21.  
  22. function implication($x1, $x2) {
  23.     return $x1 && !$x2 ? false : true;
  24. }
  25.  
  26.  
  27. ?>
  28.  
  29. <!doctype html>
  30. <html lang="en">
  31. <head>
  32.     <meta charset="UTF-8">
  33.     <title>№3</title>
  34.     <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootswatch/3.1.1/flatly/bootstrap.min.css">
  35. </head>
  36. <body>
  37.  
  38. <div class="container">
  39.     <table class="table table-striped">
  40.         <thead>
  41.             <th>X1</th>
  42.             <th>X2</th>
  43.             <th>X3</th>
  44.             <th>X4</th>
  45.             <th>F</th>
  46.         </thead>
  47.         <tbody>
  48.         <?
  49.         for($x1 = 0; $x1 <= 1; $x1++) {
  50.             for($x2 = 0; $x2 <= 1; $x2++) {
  51.                 for($x3 = 0; $x3 <= 1; $x3++) {
  52.                     for($x4 = 0; $x4 <= 1; $x4++) {
  53.                         ?>
  54.                         <tr>
  55.                             <td><?=$x1?></td>
  56.                             <td><?=$x2?></td>
  57.                             <td><?=$x3?></td>
  58.                             <td><?=$x4?></td>
  59.                             <td><?=trueTable($x1, $x2, $x3, $x4)?></td>
  60.                         </tr>              
  61.                         <?
  62.                     }
  63.                 }
  64.             }  
  65.         }
  66.         ?>
  67.         </tbody>
  68.     </table>
  69.  
  70. </div>
  71.  
  72. </body>
  73. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement