Skip to content

Instantly share code, notes, and snippets.

@whyisjake
Last active August 29, 2015 14:10
Show Gist options
  • Save whyisjake/3f2e5f45eb899d3d58d9 to your computer and use it in GitHub Desktop.
Save whyisjake/3f2e5f45eb899d3d58d9 to your computer and use it in GitHub Desktop.
<?php
/**
* Number Tower
*/
$rows = array(
array( 21, 24, 0, 9, 0, 0, 2 ),
array( 45, 30, 0, 11, 9, 0 ),
array( 75, 0, 0, 20, 0 ),
array( 0, 0, 0, 38 ),
array( 0, 117, 0 ),
array( 0, 201 ),
array( 0 ),
);
foreach( $rows as $index => $row ) {
foreach ( $row as $key => $value ) {
if ( $value == 0 && $index == 0 ) {
$rows[ $index ][ $key ] = $rows[ $index + 1 ][ $key - 1 ] - $rows[ $index ][ $key - 1 ];
} elseif ( $value == 0 && $index > 0 ) {
$rows[ $index ][ $key ] = $rows[ $index - 1 ][ $key ] + $rows[ $index - 1 ][ $key + 1 ];
}
}
}
echo '<pre>';
var_dump( $rows );
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment