Brock MacDonald Brock MacDonald - 4 months ago
863 0

No description

PHP

MacDonald | Get Sequence | Thue-Morse Sequencer

<?php
	//define array paramters
	$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>.</strong><br><br><br>
<table>
<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 class="c1r1">Whole number groups</td>
		<td class="t_head">&Sigma;(1st Powers)</td>
		<td class="t_head">&Sigma;(2nd Powers)</td>
		<td class="t_head">&Sigma;(3rd Powers)</td>
		<td class="t_head">&Sigma;(4th Powers)</td>
		<td class="t_head">&Sigma;(5th Powers)</td>
		<td class="t_head">&Sigma;(6th Powers)</td>
		<td class="t_head">&Sigma;(7th Powers)</td>
	</tr>
	<tr>
		<td class="t_row_head">
			<?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 class='t_row_data'>";
						$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 class="t_row_head">
			<?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 class='t_row_data'>";
							$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>