示例#1
0
 /**
  * Splits url into array of it's pieces as follows:
  * [scheme]://[user]:[pass]@[host]/[path]?[query]#[fragment]
  * In addition it adds 'query_params' key which contains array of
  * url-decoded key-value pairs
  *
  * @param String $sUrl Url
  * @return Array Parsed url pieces
  */
 public static function explode($sUrl)
 {
     $aUrl = parse_url($sUrl);
     $aUrl['query_params'] = array();
     $aPairs = explode('&', $aUrl['query']);
     DU::show($aPairs);
     foreach ($aPairs as $sPair) {
         if (trim($sPair) == '') {
             continue;
         }
         list($sKey, $sValue) = explode('=', $sPair);
         $aUrl['query_params'][$sKey] = urldecode($sValue);
     }
     return $aUrl;
 }
示例#2
0
    $num = (string) $num;
    $digits = str_split($num);
    rsort($digits);
    $key = implode('', $digits);
    if (isset($cache[$key])) {
        $sum = $cache[$key];
    } else {
        $sum = 0;
        foreach ($digits as $digit) {
            $sum += factorial($digit);
            if ($sum > $num) {
                return false;
            }
        }
    }
    $cache[$key] = $sum;
    if ($sum == $num) {
        return true;
    }
    return false;
}
$limit = factorial(9) * 8;
$result = 0;
for ($i = 3; $i < $limit; $i++) {
    if (isCurious($i)) {
        DU::show($i);
        $result += $i;
    }
}
DU::show('Result: ' . $result);
示例#3
0
<?php

require_once '../functions.php';
$start = 2;
$stop = 100;
$results = array();
for ($i = $start; $i <= $stop; $i++) {
    for ($j = $start; $j <= $stop; $j++) {
        $result = bcpow($i, $j);
        $results[$result] = 1;
    }
}
DU::show(count($results));
示例#4
0
<?php

require_once '../functions.php';
for ($i = 1; $i < 1000; $i++) {
    $division = 1 / $i;
    DU::show($division);
}
示例#5
0
function permute($list)
{
    $result = array();
    $inner = function ($items, $perms = array()) use(&$result, &$inner) {
        if (!$items) {
            $result[] = $perms;
        } else {
            foreach ($items as $i => $item) {
                $newItems = $items;
                $newPerms = $perms;
                array_splice($newItems, $i, 1);
                array_unshift($newPerms, $item);
                $inner($newItems, $newPerms);
            }
        }
    };
    $inner($list);
    return $result;
}
for ($i = 7; $i > 3; $i--) {
    $numbers = range(1, $i);
    $permutations = permute($numbers);
    rsort($permutations);
    foreach ($permutations as $numberArr) {
        $number = implode('', $numberArr);
        if (isPrime($number)) {
            DU::show($number);
            exit;
        }
    }
}
示例#6
0
<?php

require_once '../functions.php';
calculateExecutionTime();
$abundantNumbers = array();
$start = 28123 - 12 + 1;
for ($i = $start; $i >= 12; $i--) {
    $properDivisors = 0;
    $x = floor($i / 2);
    for ($j = $x; $j > 0; $j--) {
        if ($i % $j === 0) {
            $properDivisors += $j;
            if ($properDivisors > $i) {
                $abundantNumbers[] = $i;
                continue 2;
            }
        }
    }
}
$allNumbers = array_combine(range(1, 28123), range(1, 28123));
foreach ($abundantNumbers as $abundantNumber) {
    foreach ($abundantNumbers as $abundantNumber2) {
        $sum = $abundantNumber + $abundantNumber2;
        unset($allNumbers[$sum]);
    }
}
DU::show(array_sum($allNumbers));
示例#7
0
    yuru($x, $y);
}
function yuru($x, $y)
{
    global $currentX, $currentY, $coordinates, $start, $stop;
    $wentSomewhere = false;
    if ($x < $stop) {
        yuruX($x, $y);
        $wentSomewhere = true;
    }
    if ($y < $stop) {
        yuruY($x, $y);
        $wentSomewhere = true;
    }
    if (!$wentSomewhere) {
        //$coordinates += 1;
        $coordinates = bcadd($coordinates, 1);
        //$coordinates[] = $coordStr;
    }
}
/*
for($i=1; $i<=10; $i++) {
	$coordinates = 0;
	$stop = $i;
	yuru(0,0);
	DU::show($stop.' => '.$coordinates);
}
*/
yuru(0, 0, '');
DU::show($coordinates);