Exemplo n.º 1
0
<?php

$input = array(6, 5, 3, 1, 8, 7, 2, 4);
function shell_sort($arr)
{
    $gaps = array(1, 2, 3, 4, 6);
    $gap = array_pop($gaps);
    $len = count($arr);
    while ($gap > 0) {
        for ($i = $gap; $i < $len; $i++) {
            $temp = $arr[$i];
            $j = $i;
            while ($j >= $gap && $arr[$j - $gap] > $temp) {
                $arr[$j] = $arr[$j - $gap];
                $j -= $gap;
            }
            $arr[$j] = $temp;
        }
        $gap = array_pop($gaps);
    }
    return $arr;
}
// 1, 2, 3, 4, 5, 6, 7, 8
shell_sort($input);
Exemplo n.º 2
0
function nox_interpol($message, $dico)
{
    print "Decryptage de " . $message . "\n";
    $handle = fopen($message, "r");
    $message_content = fread($handle, filesize($message));
    $handle = fopen($dico, "r");
    $dico_content = fread($handle, filesize($dico));
    preg_match_all("/\\w+/", $dico_content, $dico_arr);
    preg_match_all("/\\w+/", $message_content, $message_arr);
    shell_sort($dico_arr[0]);
    $i = 0;
    $time_start = microtime(true);
    while (isset($message_arr[0][$i])) {
        interpol_search($dico_arr[0], count($dico_arr[0]), $message_arr[0][$i]);
        $i++;
    }
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    print "Recherche terminée en " . round($time, 5) . " sec.\n";
}