VFSDraw - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of VFSDraw.php
- <?php
- const MAX_POINTS = 4;
- $points = array("A" => 1, "B" => 1, "E" => 1, "J" => 1, "L" => 1,
- "1" => 2, "2" => 2, "3" => 2, "7" => 2, "8" => 2,
- "12" => 2, "13" => 2, "14" => 2, "21" => 2, "22" => 2);
- $draws = array();
- function store($draw=[], $withPoints=0, &$inArray=[]) {
- $drawString = implode("-", $draw);
- $inArray[$drawString] = $withPoints;
- }
- // begin point generation
- function generateDraw($points, $draws=[]) {
- $draw = [];
- foreach ($points as $p1 => $value1) {
- $draw = [];
- $draw[1] = $p1;
- $drawPoints = $value1;
- foreach ($points as $p2 => $value2) {
- if ($p2 == $p1) {
- continue;
- }
- $draw[2] = $p2;
- $drawPoints = $value1 + $value2;
- if ($drawPoints >=3) {
- store($draw, $drawPoints, $draws);
- continue;
- }
- foreach ($points as $p3 => $value3) {
- if (($p3 == $p1) || ($p3 == $p2)) {
- continue;
- }
- $draw[3] = $p3;
- $drawPoints = $value1 + $value2 + $value3;
- store($draw, $drawPoints, $draws);
- unset($draw[3]);
- }
- }
- }
- //print_r($draws);
- $keys = array_keys($draws);
- foreach ($keys as $k) {
- print($k);
- print(',');
- }
- }
- generateDraw($points);