Skip to content

Instantly share code, notes, and snippets.

@ad3n
Created April 11, 2016 11:48
Show Gist options
  • Save ad3n/21c5208cd3de2aea703892cd418d365d to your computer and use it in GitHub Desktop.
Save ad3n/21c5208cd3de2aea703892cd418d365d to your computer and use it in GitHub Desktop.
[PHPID QUIZ] Bujur Sangkar
<?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