Forked from ad3n/gist:21c5208cd3de2aea703892cd418d365d
Created
April 11, 2016 11:51
-
-
Save 3Shoka/2c05ff49d45cd842844b0082411e6cf3 to your computer and use it in GitHub Desktop.
[PHPID QUIZ] Bujur Sangkar
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 | |
class BujurSangkar | |
{ | |
private $sisi = 7; | |
private $reserved = array(); | |
public function __construct() | |
{ | |
for ($i = 1; $i <= $this->sisi * $this->sisi; $i++) { | |
$this->reserved[] = $i; | |
} | |
shuffle($this->reserved); | |
} | |
public function draw() | |
{ | |
$index = 1; | |
for ($i = 1; $i <= $this->sisi; $i++) { | |
for ($j = 1; $j < $this->sisi; $j++) { | |
$number = $this->reserved[$index]; | |
echo $number; | |
if (10 > $number) { | |
echo ' '; | |
} | |
echo ' '; | |
$index++; | |
} | |
echo PHP_EOL; | |
} | |
} | |
} | |
$bujurSangkar = new BujurSangkar(); | |
$bujurSangkar->draw(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment