Anonymous Anonymous - 4 months ago
431 0

No description

PHP

Get Thue-Morse Results - MacDonald

<?php
	$count = intval($_GET['count']);
	
	$initial_array_size = $count;
	$initial_array = array();
	$selected_array = array();
	
	$i_init = 0;
	$i = $i_init;

	//build initial array
	while ($i < $initial_array_size) {
	array_push($initial_array, $i);
	$i++;
	}
	
	$odd_array = array();
	$even_array = array();
	
	foreach ($initial_array as $vals) {
		if(array_sum(str_split(decbin($vals))) % 2 != 0) {
			array_push($odd_array,$vals);
		} else {
			array_push($even_array,$vals);
		}
	}
?>
<strong>Consider all whole numbers between <u><?php echo $i_init; ?></u> and <u><?php echo ($i_init + $initial_array_size - 1); ?></u>.<br><br><br>
<table style="border-collapse:collapse;">
<col width="22%">
<col width="11%">
<col width="11%">
<col width="11%">
<col width="11%">
<col width="11%">
<col width="11%">
<col width="11%">
	<tr>
		<td style="padding:5px;font-weight:bold;vertical-align:bottom;">Whole number groups</td>
		<td style="border:1px solid black;padding:5px;vertical-align:bottom;">&Sigma;(1st Powers)</td>
		<td style="border:1px solid black;padding:5px;vertical-align:bottom;">&Sigma;(2nd Powers)</td>
		<td style="border:1px solid black;padding:5px;vertical-align:bottom;">&Sigma;(3rd Powers)</td>
		<td style="border:1px solid black;padding:5px;vertical-align:bottom;">&Sigma;(4th Powers)</td>
		<td style="border:1px solid black;padding:5px;vertical-align:bottom;">&Sigma;(5th Powers)</td>
		<td style="border:1px solid black;padding:5px;vertical-align:bottom;">&Sigma;(6th Powers)</td>
		<td style="border:1px solid black;padding:5px;vertical-align:bottom;">&Sigma;(7th Powers)</td>
	</tr>
	<tr>
		<td style="font-size:75%; border:1px solid black;padding:5px;">
			<?php
				$co = 1;
				foreach ($odd_array as $odd) {
					echo $odd;
					if ($co > $count / 2 - 1) { break; } else {
						echo " + ";
						$co++;
					}
				}
			?>
		</td>
		<?php 
			$o = 1;
			while ($o <= (log($count)/log(2) - 1)) {
				echo "
					<td style='border:1px solid black;vertical-align:top;text-align:left;padding:5px;'>";
						$odd_a = $odd . $o;
						$odd_a = array();
						foreach ($odd_array as $odd) {
							$odd = pow($odd,$o);
							array_push($odd_a, $odd);
						}
						echo number_format(array_sum($odd_a)) . "</td>
					";
				$o++;
			}
		?>
	</tr>
	<tr>
		<td style="font-size:75%; border:1px solid black;padding:5px;">
			<?php
				$ce = 1;
				foreach ($even_array as $even) {
					echo $even;
					if ($ce > $count / 2 - 1) { break; } else {
						echo " + ";
						$ce++;
					}
				}
			?>
		</td>
			<?php 
				$e = 1;
				while ($e <= (log($count)/log(2) - 1)) {
					echo "
						<td style='border:1px solid black;vertical-align:top;text-align:left;padding:5px;'>";
							$even_a = $even . $e;
							$even_a	= array();
							foreach ($even_array as $even) {
								$even = pow($even,$e);
								array_push($even_a, $even);
							}
							echo number_format(array_sum($even_a)) . "</td>
						";
					$e++;
				}
			?>
	</tr>
</table>
</center>