function simple_choice ($choice1, $choice2
{
return $choice1" on "$choice2", mmmm..."
}
Category: View
eXorithm – Execute Algorithm: View / Run Algorithm part_of_speech
function part_of_speech ($word
{
  $data = file_get_contents"http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q="urlencode$word)."&sl=en&tl=en&restrict=pr%2Cde&client=te");
 Â
  if ( (substr$data, 0, 25)=="dict_api.callbacks.id100(") &&
       (substr$data, -10)==",200,null)") )
  {
    $data = substr$data, 25, -10);
    $data = str_replace'x22', '"', $data);
    $data = decode_phpstring$data);
   Â
    $parts = array();
   Â
    $obj = json_decode$data);
   Â
    if (isset$obj->primaries)) {
      foreach ($obj->primaries as $prim) {
        $headword = ''
        $part = ''
        foreach ($prim->terms as $term) {
          if ($term->type=="text") {
            $headword = str_replace'·', '', $term->text);
            foreach ($term->labels as $label) {
              if ($label->title=="Part-of-speech") {
               Â
                $st = false;
                $part = strtolower$label->text);
               Â
                foreach ($prim->entries as $entry) {
                  if ($entry->type=="related") {
                    foreach ($entry->terms as $term2) {
                      if ($term2->text==$word) {
                        $st = true;
                        $i = count$parts);
                        $parts$i]['type'] = $part
                        $parts$i]['base'] = $headword
                        $parts$i]['subtype'] = $term2->labels[0]->text;
                      }
                    }
                  }
                }
               Â
                if (!$st) {
                  $i = count$parts);
                  $parts$i]['type'] = $part
                  $parts$i]['base'] = $headword
                  $parts$i]['subtype'] = ''
                }
              }
            }
          }
        }
      }
    }
    return $parts
   Â
  } else {
    throw new Exception"Google dictionary API did not return a result.");
  }
}Â
eXorithm – Execute Algorithm: View / Run Algorithm gcd_euclid
function gcd_euclid ($a, $b
{
  $a = abs$a);
  $b = abs$b);
 Â
  if ($a == 0)
    return $b
  elseif ($b == 0)
    return $a
  elseif ($a > $b
    return gcd_euclid$b, $a % $b);
  else
    return gcd_euclid$a, $b % $a);
}Â
eXorithm – Execute Algorithm: View / Run Algorithm array_fusion
function array_fusion ($array, $type
{
switch$type) {
case 'standard'
case 'positive'
return array_sum$array);
break
case 'negative'
return -array_sum$array);
break
case 'string'
return json_encodearray_sum$array));
break
case 'duplicate'
return powarray_sum$array), array_sum$array));
break
case 'del'
$return = $array
for$i = 0; $i < count$array); $i++)
if$i % 2 == 0 || $i * 3 == count$array))
unset$return$i]);
return array_sum$return);
break
case 'med'
return array_sum$array) / count$array); //count($array);
break
case 'meded'
return array_fusionarrayarray_fusion$array, 'positive')), 'med');
break
}
}
eXorithm – Execute Algorithm: View / Run Algorithm freebase_populations
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
}
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: 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"
}
}