}; $rec([], $arr); return $result; } $people = array_keys($sit); $people[] = 'Self'; $permutations = permute($people); function calcScore($seats) { global $sit; $len = count($seats); $score = 0; for ($i = 0; $i < $len; $i++) { $self = $seats[$i]; $left = $seats[($i - 1 + $len) % $len]; $right = $seats[($i + 1 + $len) % $len]; if ($left !== 'Self') { $score += $sit[$self][$left]; } if ($right !== 'Self') { $score += $sit[$self][$right]; } } return $score; } $scores = []; foreach ($permutations as $perm) { $idx = implode(', ', $perm); $scores[$idx] = calcScore($perm); } var_dump(max($scores));
// echo "deleting responses"; $sql = "DELETE FROM tbl_response" . $_SESSION['qnstable'] . " WHERE tbl_response" . $_SESSION['qnstable'] . ".fld_student_id='" . $_SESSION['studid'] . "'"; mysqli_query($conn, $sql); // echo "deleting scores"; $sql = "DELETE FROM tbl_stud_testscore\n WHERE fld_student_id='" . $_SESSION['studid'] . "'\n AND fld_test_id='" . $_SESSION['testid'] . "'"; mysqli_query($conn, $sql); $sql = "INSERT INTO tbl_response" . $_SESSION['qnstable'] . " (fld_student_id,fld_question_id,fld_response) VALUES"; for ($x = 1; $x <= $_SESSION['numq']; $x++) { $sql .= "('" . $_SESSION['studid'] . "',{$x},'" . mysqli_real_escape_string($conn, $response[$x]) . "'),"; } $sql = rtrim($sql, ","); mysqli_query($conn, $sql) or die("damn!" . mysqli_error($conn) . "<br><br>" . $sql); //SELECT wrongly answered questions $query = callWrong($conn); //CALCULATE score $percent_score = calcScore($query); //INSERT scores table $sql = "insert into tbl_stud_testscore(fld_student_id, fld_test_id, fld_score) VALUES('" . $_SESSION['studid'] . "', '" . $_SESSION['testid'] . "',{$percent_score})"; mysqli_query($conn, $sql) or die("woah!" . mysqli_error($conn)); } $percent_score = round($percent_score); if ($_SESSION['retain'] == -1) { if ($percent_score != 100) { $bob = $_SESSION['testid'] . "/" . $_SESSION['testblurb']; print "<div id='again'>\n{$percent_score}%\n <form action='" . $_SESSION['global_url'] . "/test.php' method='get'>\n\n <input type='submit' id='btnAgain' value='' />\n\n </form>\n</div>"; } else { print "<div id='again'>만점</div>"; } } else { print "<div id='again'>\n{$percent_score}%</div>"; }