Esempio n. 1
0
 function WordLadderCompute($StringX, $StringY)
 {
     //if string sizes do not match then you can not
     //compute the word ladder
     if (strlen($StringX) == strlen($StringY)) {
         print "Incorrect/Mismach word sizes";
         return;
     } else {
         $TrieTable[strlen($StringX)] . findPath($StringX, $StringY);
     }
 }
Esempio n. 2
0
/**
    @param $start_marker<Marker> the starting station
    @param $end_marker<Marker> the ending station
*/
function findS2SPath($start_marker, $end_marker)
{
    $debug = false;
    if ($debug) {
        echo "findS2SPath<br/>";
    }
    if ($start_marker == $end_marker) {
        return "walk";
    }
    global $markers;
    // determine original bounding box
    $original_box = new Box($start_marker->point, $end_marker->point);
    // create array of paths
    $open = array();
    foreach ($start_marker->getLines() as $line) {
        foreach ($line->getConnections() as $connection) {
            // get associated marker
            $marker = $markers[$connection->id];
            if ($debug) {
                echo "retrieved marker from connection (" . $connection->id . "): ";
                $marker->printInfo();
            }
            $lines = $start_marker->getOverlapLines($marker);
            $segment = new Segment($start_marker, $marker, $lines, $connection->duration, $connection->type);
            $visited = array();
            $visited[] = $start_marker;
            $visited[] = $marker;
            $new_box = new Box($marker->point, $end_marker->point);
            $path = new Path2($segment, $new_box, $visited);
            if ($marker == $end_marker) {
                return $path;
            }
            $area = $new_box->getArea();
            $array = $open["{$area}"];
            if ($array == null) {
                $array = array();
            }
            $array[] = $path;
            $open["{$area}"] = $array;
        }
    }
    $end_stations = array();
    $end_stations[] = new Station($end_marker, 0);
    return findPath($open, $end_stations, $end_marker);
}
Esempio n. 3
0
/**
    @param $start_station<Marker>
    @param $end_station<Marker>
*/
function findS2SPath($start_marker, $end_marker)
{
    global $markers;
    // determine original bounding box
    $original_box = new Box($start_marker->point, $end_marker->point);
    // create array of paths
    $open = array();
    foreach ($start_marker->getLines() as $line) {
        foreach ($line->getConnections() as $connection) {
            // get associated marker
            $marker = $markers[$connection->id];
            $segment = new Segment($start_marker, $marker, $marker->lines, $connection->duration, $connection->type);
            $visited = array();
            $visited[] = $start_marker;
            $visited[] = $marker;
            $new_box = new Box($marker->point, $end_marker->point);
            $path = new Path2($segment, $new_box, $visited);
            $area = $new_box->getArea();
            $array = $open["{$area}"];
            if ($array == null) {
                $array = array();
            }
            $array[] = $path;
            #echo "adding $array<br/>";
            $open["{$area}"] = $array;
        }
    }
    $end_stations = array();
    $end_stations[] = new Station2($end_marker, 0);
    findPath($open, $end_stations, null);
}
Esempio n. 4
0
    $line = $result->fetch_assoc();
    if ($line["user"] == $user && (strpos($line["rights"], 'all') !== false || strpos($line["rights"], 'notes') !== false)) {
        $max_size = 26843545600;
    } else {
        $max_size = 0;
    }
} elseif (isset($_SESSION["notes-user"])) {
    //check if teachers user exists an has permissions
    $user = $_SESSION["notes-user"];
    $request = "SELECT * FROM teachers_users WHERE user = '******'";
    $result = $connection->query($request);
    $line = $result->fetch_assoc();
    if ($line["user"] == $user) {
        $max_size = $line["max_user_space"];
    } else {
        $max_size = 0;
    }
} else {
    $max_size = 0;
}
if (getFolderSize("../../../" . $config->plugin_notes_engine_fpath) + $_FILES['files']['size'] > $max_size * 1073741824) {
    echo '{"files":[{"error":"max user folder size exceeded or invalid user"}]}';
    exit;
}
$options = ['upload_dir' => str_replace("core/modules/php/notes-engine-upload.php", "", $_SERVER['SCRIPT_FILENAME']) . $config->plugin_notes_engine_fpath . "/" . findPath($_POST["target"]) . "/", 'upload_url' => str_replace("core/modules/php", "", get_full_url()) . $config->plugin_notes_engine_fpath . "/" . findPath($_POST["target"]) . "/", 'inline_file_types' => '/\\.(?!(php|js|pl|cgi|html|css|xml|json|swf|jar|class|py|rb|sh|bat|fcgi|inc)).+$/i', 'accept_file_types' => '/\\.(?!(php|pl|cgi|sh|fcgi|inc)).+$/i'];
$upload_handler = new UploadHandler($options);
function get_full_url()
{
    $https = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'on') === 0 || !empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0;
    return ($https ? 'https://' : 'http://') . (!empty($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] . '@' : '') . (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'] . ($https && $_SERVER['SERVER_PORT'] === 443 || $_SERVER['SERVER_PORT'] === 80 ? '' : ':' . $_SERVER['SERVER_PORT'])) . substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
}
Esempio n. 5
0
function findPath($c, $path)
{
    $query = "SELECT t1.category_name, t1.parent_category_id, t2.category_name\n\tFROM categories as t1, cat_name_translations as t2 WHERE t1.category_id=t2.category_id AND t1.category_id='{$c}' AND t2.lang = '" . $_SESSION['MDS_LANG'] . "' ";
    //echo $query;
    $result = mysql_query($query) or die("<b>{$query}</b>" . mysql_error());
    if (mysql_num_rows($result) > 0) {
        $row = mysql_fetch_row($result);
        if ($path == "") {
            $path = "  {$row['2']}  ";
            // leaf
        } else {
            $path = " <A href=\"" . htmlentities($_SERVER['PHP_SELF']) . "?cat={$c}\">{$row['2']}</a> -&gt;  ";
            // stem
        }
        $path = findPath($row[1], $path) . $path;
        return $path;
    }
}
Esempio n. 6
0
// return last standing distance :)
// Possible optimations: fail fast after reaching previous best, remove duplicates, ...
function findPath($evalCallback)
{
    global $routes;
    $distances = [];
    foreach (array_keys($routes) as $i => $from) {
        $distances[$from] = getDistance($evalCallback, $from);
    }
    \var_dump($distances);
    return \call_user_func($evalCallback, $distances);
}
function getDistance($evalCallback, $from, $previousDistance = 0, $previousLocations = [])
{
    global $routes;
    $previousLocations[] = $from;
    $distances = [];
    foreach ($routes[$from] as $to => $length) {
        if (\in_array($to, $previousLocations)) {
            continue;
        }
        // Here (at least on shortest path) we could stop if previous + length > previous-best
        $distances[$to] = \getDistance($evalCallback, $to, $previousDistance + $length, $previousLocations);
    }
    return empty($distances) ? $previousDistance : \call_user_func($evalCallback, $distances);
}
// Task 1
$shortestPath = \findPath("\\min");
// Task 2
$longestPath = \findPath("\\max");
echo "The shortest path is {$shortestPath} and the longest is {$longestPath}.";
Esempio n. 7
0
function newFolder($name, $parent)
{
    global $connection, $config;
    $id = uniqid();
    $name = $connection->escape_string($name);
    $request = "SELECT * FROM notes_vfs WHERE id = '{$parent}'";
    $result = $connection->query($request);
    $line = $result->fetch_assoc();
    $path = findPath($parent);
    if (isset($line["container"])) {
        $container = $line["container"];
    } else {
        $container = $parent;
        $parent = "/";
    }
    //Permission check (frontend based on js: VERY WEAK)
    $permissions = validatePermissions(validateUser());
    if ($permissions == $container || ($permissions = "all")) {
        if (mkdir($config->plugin_notes_engine_fpath . "/" . $path . "/" . $id)) {
            $request = "INSERT INTO notes_vfs (id,name,parent,container) VALUES ('{$id}','{$name}','{$parent}','{$container}')";
            $connection->query($request);
            echo $connection->error;
            echo "success";
        } else {
            echo "500: Internal Server Error";
        }
    } else {
        echo "403: Not authorized";
    }
}
Esempio n. 8
0
    $path = array();
    helper($root, $target, $path, $result);
    return $result;
}
function helper($root, $target, &$path, &$result)
{
    if ($root == null) {
        return;
    }
    if ($root->left == null && $root->right == null) {
        if ($root->val == $target) {
            $path[] = $root->val;
            $result[] = $path;
            array_pop($path);
        }
        return;
    }
    $path[] = $root->val;
    helper($root->left, $target, $path, $result);
    helper($root->right, $target, $path, $result);
    array_pop($path);
}
// test case for findPath
$result = findPath($root, 4);
echo "findPath() result:\n";
foreach ($result as $path) {
    foreach ($path as $node) {
        echo $node;
    }
    echo "\n";
}
Esempio n. 9
0
<?php

$MAP = [];
fscanf(STDIN, "%d %d %d %d", $sX, $sY, $eX, $eY);
fscanf(STDIN, "%d", $nbObstacles);
// number of walls
$MAP[$sX][$sY] = 'S';
$MAP[$eX][$eY] = 'X';
for ($i = 0; $i < $nbObstacles; $i++) {
    fscanf(STDIN, "%d %d", $pX, $pY);
    $MAP[$pX][$pY] = '#';
}
findPath($MAP, $eX, $eY, 0);
showMAP($MAP, 16, 10);
$MAX = array(isset($MAP[$sX][$sY - 1]) ? $MAP[$sX][$sY - 1] : 0, isset($MAP[$sX][$sY + 1]) ? $MAP[$sX][$sY + 1] : 0, isset($MAP[$sX - 1][$sY]) ? $MAP[$sX - 1][$sY] : 0, isset($MAP[$sX + 1][$sY]) ? $MAP[$sX + 1][$sY] : 0);
$MAP[$sX][$sY] = max($MAX) + 10;
$MAP[$eX][$eY] = '0';
showMAP($MAP, 16, 10);
//die;
goToExit($MAP, $sX, $sY);
echo "\n";
//error_log(var_export($MAP, true));
// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));
//echo("RIGHT RIGHT RIGHT DOWN\n"); // Use this function to dump all your movements (example: "RIGHT RIGHT UP UP UP")
function findPath(&$MAP, $X, $Y, $i)
{
    $WAVE = oneWave($MAP, $X, $Y, ++$i);
    while (count($WAVE)) {
        $i++;
        $newWave = [];
Esempio n. 10
0
<?php

if (!isset($page)) {
    die("403: Not authorized to call this page directly");
}
$module["action"] = "library";
include "core/modules/notes-engine.php";
//process request by calling the correct functions
if (isset($_POST["action"])) {
    switch ($_POST["action"]) {
        case "load-path":
            $path = findPath($connection->escape_string($_POST["folder"]));
            displayFiles($path);
            break;
        case "update-breadcrumb":
            $path = findPath($connection->escape_string($_POST["folder"]));
            displayBreadcrumbs($path);
            break;
        case "delete-file":
            deleteFile($connection->escape_string($_POST["path"]), $connection->escape_string($_POST["container"]));
            break;
        case "delete-folder":
            deleteFolder($connection->escape_string($_POST["id"]));
            break;
        case "new-folder":
            newFolder($connection->escape_string($_POST["name"]), $connection->escape_string($_POST["path"]));
            break;
        case "edit-folder":
            editFolder($connection->escape_string($_POST["name"]), $connection->escape_string($_POST["id"]));
            break;
        case "get-usage":