<?php function compare($f, $g) { echo '<table border="1" style="border-collapse:collapse" cellpadding="4">'; echo '<tr><th>A</th><th>B</th><th>C</th><th>Y1</th><th>Y2</th></tr>'; for ($i = 0; $i < 8; $i++) { $a = (($i & 0x01) != 0); $b = (($i & 0x02) != 0); $c = (($i & 0x04) != 0); $y1 = $f($a, $b, $c); $y2 = $g($a, $b, $c); printf('<tr><td>%d</td><td>%d</td><td>%d</td><td>%d</td><td>%d</td></tr>', $a, $b, $c, $y1, $y2); } echo '</table>'; } function y12_1($a, $b, $c) { return !(($a && $b && !$c) || ($a && !$b && $c) || (!$a && $b && $c)); } function y12_2($a, $b, $c) { return !(!(!$a && !$b) && !(!$a && !$c) && !(!$b && !$c) && !(!$b && !$c) && !($a && $b && $c)); } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Week 2</title> </head> <body> <?php compare('y12_1', 'y12_2'); ?> </body> </html>
|