Last active
August 29, 2015 14:10
-
-
Save whyisjake/3f2e5f45eb899d3d58d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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