function freebase_populations ($countries
{
$query = array'type'=>'/location/country',
'name'=>null,
'query:name|='=>$countries,
'iso3166_1_alpha2!='=>''
'/location/statistical_region/population'=> arrayarray
'limit'=>1,
'number'=>null,
'year'=>null,
'sort'=>'-year'
)) );
$results = freebase_query$query);
$return = array();
foreach ($results as $result) {
if (isset$result'/location/statistical_region/population'][0]['number'])) {
$return$result'name']] = $result'/location/statistical_region/population'][0]['number'];
}
}
return $return
}
Author: ToneDJCampbell
eXorithm – Execute Algorithm: View / Run Algorithm image_create_alpha
function image_create_alpha ($width, $height
{
// Create a normal image and apply required settings
$img = imagecreatetruecolor$width, $height);
imagealphablending$img, false);
imagesavealpha$img, true);
// Apply the transparent background
$trans = imagecolorallocatealpha$img, 0, 0, 0, 127);
for ($x = 0; $x < $width; $x++)
{
for ($y = 0; $y < $height; $y++)
{
imagesetpixel$img, $x, $y, $trans);
}
}
return $img
}
eXorithm – Execute Algorithm: View / Run Algorithm multicolumn
function multicolumn ($items, $type, $rows, $columns, $table_attributes, $td_attributes, $empty_attributes
{
$return = ''
$count = count$items);
// compute number of columns and rows
if (($rows=='*') && ($columns=='*')) {
$rows = roundsqrt$count));
$columns = ceil$count$rows);
} else {
if ($rows=='*'
$rows = ceil$count$columns);
else if ($columns=='*'
$columns = ceil$count$rows);
}
if ($count>0) {
$return .= "<table $table_attributes>"
$column = 0;
$row = 0;
$total = $rows * $columns
for ($i=0;$i$total$i++) {
if$column == 0)
$return .= '<tr>'
if ($type=='horizontal'
$spot = $i
else
$spot = $row$column$rows
if ($spot$count
$return .= "<td $td_attributes>$items[$spot]</td>"
else
$return .= "<td $empty_attributes></td>"
$column++;
if ($column==$columns) {
$return .= '</tr>'
$column = 0;
$row++;
}
}
$return .= '</table>'
}
return $return
}
eXorithm – Execute Algorithm: Discuss Algorithm pi_digits
pi_digits    version 0.4    Calculate the digits of pi.
There are no comments yet
New Comment
eXorithm – Execute Algorithm: Algorithms Beginning with W
eXorithm – Execute Algorithm: View / Run Algorithm coin_change
function coin_change ($amount, $coins
{
  $change = array();
  rsort$coins);
  for$i=0; $icount$coins); $i++) {
    $change$coins$i]] = floor$amount$coins$i]);
    $amount = $amount % $coins$i];
  }
  return $change
}Â
eXorithm – Execute Algorithm: View / Run Algorithm radtodeg
function radtodeg ($radians
{
  return ($radians * (180.0/pi()));
}Â
eXorithm – Execute Algorithm: View / Run Algorithm bytes2human
function bytes2human ($bytes, $precision
{
switch (true) {
case $bytes < 1024:
return number_format$bytes).($bytes==1 ? " Byte" : " Bytes");
case round$bytes / 1024) < 1024:
return number_format$bytes / 1024, $precision)." KB"
case round$bytes / 1024 / 1024, 2) < 1024:
return number_format$bytes / 1024 / 1024, $precision)." MB"
case round$bytes / 1024 / 1024 / 1024, 2) < 1024:
return number_format$bytes / 1024 / 1024 / 1024, $precision)." GB"
default
return number_format$bytes / 1024 / 1024 / 1024 / 1024, $precision)." TB"
}
}
Sum List
<?php /** * sum_list * * Sum up the numbers in an array. * * @version 0.1 * @author Contributors at eXorithm * @link /algorithm/view/sum_list Listing at eXorithm * @link /algorithm/history/sum_list History at eXorithm * @license /home/show/license * * @param array $numbers * @return number */ function sum_list($numbers=array(0=>'2',1=>'4',2=>'12',3=>'1')) { return array_sum($numbers); } ?>
eXorithm – Execute Algorithm: Discuss Algorithm make_change
make_change    version 0.1    Calculate the number of different ways there are to make change for a given amount.
There are no comments yet
New Comment