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.



Your result can be seen below.

Result of php executing





Full code of VFSDraw.php

  1. <?php
  2.  
  3. const MAX_POINTS = 4;
  4.  
  5. $points = array("A" => 1, "B" => 1, "E" => 1, "J" => 1, "L" => 1,
  6.                 "1" => 2, "2" => 2, "3" => 2, "7" => 2, "8" => 2, 
  7.                 "12" => 2, "13" => 2, "14" => 2, "21" => 2, "22" => 2);
  8. $draws = array();
  9.  
  10. function store($draw=[], $withPoints=0, &$inArray=[]) {
  11.     $drawString = implode("-", $draw);
  12.     $inArray[$drawString] = $withPoints;
  13. }
  14.  
  15. // begin point generation
  16. function generateDraw($points, $draws=[]) {
  17.     $draw = [];
  18.     
  19.     foreach ($points as $p1 => $value1) {
  20.         $draw = [];
  21.         $draw[1] = $p1;
  22.         $drawPoints = $value1;
  23.         
  24.         foreach ($points as $p2 => $value2) {
  25.             if ($p2 == $p1) {
  26.                 continue;
  27.             }
  28.             
  29.             $draw[2] = $p2;
  30.             $drawPoints = $value1 + $value2;
  31.             
  32.             if ($drawPoints >=3) {
  33.                 store($draw, $drawPoints, $draws);
  34.                 continue;
  35.             }
  36.             
  37.             foreach ($points as $p3 => $value3) {
  38.                 if (($p3 == $p1) || ($p3 == $p2)) {
  39.                     continue;
  40.                 }
  41.                 
  42.                 $draw[3] = $p3;
  43.                 $drawPoints = $value1 + $value2 + $value3;
  44.                 store($draw, $drawPoints, $draws);
  45.                 unset($draw[3]);
  46.             }
  47.         }
  48.     }
  49.     
  50.     //print_r($draws);
  51.     $keys = array_keys($draws);
  52.     foreach ($keys as $k) {
  53.         print($k);
  54.         print(',');
  55.     }
  56. }
  57.  
  58. generateDraw($points);
File Description
  • VFSDraw
  • PHP Code
  • 06 Apr-2018
  • 1.46 Kb
You can Share it: