function indefinite_article ($word, $explicit_a, $explicit_an
{
// adapted from http://search.cpan.org/~dconway/Lingua-EN-Inflect/
# HANDLE SPECIAL CASES
if (preg_match'/^'implode'|'$explicit_a).'/i', $word)) return "a $word"
if (preg_match'/^'implode'|'$explicit_an).'/i', $word)) return "an $word"
# HANDLE ABBREVIATIONS
if (preg_match'/^((?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z])/', $word)) return "an $word"
if (preg_match'/^[aefhilmnorsx]$/i', $word)) return "an $word"
if (preg_match'/^[aefhilmnorsx][.-]/i', $word)) return "an $word"
if (preg_match'/^[bcdgjkpqtuvwyz]$/i', $word)) return "a $word"
if (preg_match'/^[bcdgjkpqtuvwyz][.-]/i', $word)) return "a $word"
# HANDLE ORDINAL FORMS
if (preg_match'/^[bcdgjkpqtuvwyz]-?th$/i', $word)) return "a $word"
if (preg_match'/^[aefhilmnorsx]-?th$/i', $word)) return "an $word"
# HANDLE CONSONANTS
if (preg_match'/^[^aeiouy]/i', $word)) return "a $word"
# HANDLE SPECIAL VOWEL-FORMS
if (preg_match'/^e[uw]/i', $word)) return "a $word"
if (preg_match'/^onc?eb/i', $word)) return "a $word"
if (preg_match'/^uni([^nmd]|mo)/i', $word)) return "a $word"
if (preg_match'/^ut[th]/i', $word)) return "an $word"
if (preg_match'/^u[bcfhjkqrst][aeiou]/i', $word)) return "a $word"
# HANDLE SPECIAL CAPITALS
if (preg_match'/^U[NK][AIEO]?/', $word)) return "a $word"
# HANDLE VOWELS
if (preg_match'/^[aeiou]/i', $word)) return "an $word"
# HANDLE y... (BEFORE CERTAIN CONSONANTS IMPLIES (UNNATURALIZED) "i.." SOUND)
if (preg_match'/^(y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt))/i', $word)) return "an $word"
# OTHERWISE, GUESS "a"
return "a $word"
}
Category: View
eXorithm – Execute Algorithm: View / Run Algorithm list_prime
function list_prime ($min, $max, $return_string
{
$count = $min
$numbert = 2;
$return = array();
while ($count < $max ) {
$div_count=0;
for ( $i=1;$i<=$number$i++)
if (($number$i)==0)
$div_count++;
if ($div_count<3) {
$return[] = $number
$count += 1;
}
$number += 1;
}
unset$return[0]);
if$return_string
$return = implode", ", $return);
return $return
}
eXorithm – Execute Algorithm: View / Run Algorithm volume_sphere
function volume_sphere ($radius
{
return (4/3) * pi() * pow$radius,3);
}
eXorithm – Execute Algorithm: View / Run Algorithm gaussian_curve
function gaussian_curve ($expected, $variance
{
$a = 1/(sqrt$variancepi()*2));
$b = $expected
$c = sqrt$variance);
// gaussian function:
// f(x) = ae^(-((x-b)^2)/(2*c^2))
// http://en.wikipedia.org/wiki/Gaussian_function
$f = array'*', $a,
array'^', exp(1),
array'neg',
array'/'
array'^', array'-', 'x', $b), 2),
array'*', 2, array'^', $c, 2))))));
// evaluate
$max = evaluate_for_x$f, $b);
$width = 600;
$height = ceil$max$width/10);
if ($height<200) $height = 200;
return plot_function$f, 'x', $b-5, $b+5, $width, $height, 1);
}
eXorithm – Execute Algorithm: View / Run Algorithm overlay_image
function overlay_image ($base, $image
{
$h = imagesy$image);
$w = imagesx$image);
imagealphablending$base, true);
imagesavealpha$base, true);
imagecopy$base, $image, 0, 0, 0, 0, $w, $h);
return $base
}
eXorithm – Execute Algorithm: View / Run Algorithm scientific_notation
function scientific_notation ($value, $condensed
{
$e = 0;
while$value>=10 || $value<1)
{
if$value<=1)
{
$value *= 10;
$e--;
}
else
{
if$value>=10)
{
$value /= 10;
$e++;
}
}
}
if$condensed
return $value . "E" . $e
return $value . " x 10<sup>" . $e . "</sup>"
}
eXorithm – Execute Algorithm: View / Run Algorithm photobucket
function photobucket ($url
{
$str = file_get_contents$url);
preg_match_all'/<img[^>]+>/i'$str, $result);
$strPics = ""
foreach( $result as $img_tag) {
foreach( $img_tag as $img) {
if( !strpos$img, 'class="under off"') ) continue
preg_match'/< *img[^>]*src *= *["']?([^"']*)/i', $img, $imgURLs);
$imgURL = str_replace"/th_", "/", $imgURLs[1]);
$strPics .= $imgURL . "n"
}
}
return $strPics
}
eXorithm – Execute Algorithm: View / Run Algorithm countries_from_freebase
function countries_from_freebase ()
{
// build query and issue it
$query = array'limit'=>1000, 'type'=>'/location/country', 'name'=>array(), 'iso3166_1_alpha2'=>array());
$results = freebase_query$query);
// extract country names and codes from the results
$return = array();
foreach ($results as $result) {
if (isset$result'iso3166_1_alpha2'][0])) {
$return$result'iso3166_1_alpha2'][0]] = $result'name'][0];
}
}
// sort
asort$return);
return $return
}
eXorithm – Execute Algorithm: View / Run Algorithm evaluate_for_x
function evaluate_for_x ($equation, $x
{
return evaluate_equation$equation, array'x'=>$x));
}
eXorithm – Execute Algorithm: View / Run Algorithm plot_3d_function
function plot_3d_function ($function, $variable1, $variable2, $center_x, $center_y, $range, $z_scale, $width, $detail, $line_color, $surface_color
{
  $x1 = $center_x$range/2;
  $y1 = $center_y$range/2;
 Â
  $xfinal = $center_x$range/2;
  $yfinal = $center_y$range/2;
 Â
  // step size
  $step = $range$detail
 Â
  // all the polygons that make up the graph
  $polygons = array();
 Â
  // generate the polygons for the graph
  for ($ii=0;$ii<=$detail$ii++) {
    $x$x1+($ii$step);
    for ($jj=0;$jj<=$detail$jj++) {
      $y$y1+($jj$step);
     Â
      $z = evaluate_equation$function, array$variable1=>$x, $variable2=>$y))*$z_scale
     Â
      if (!is_nan$z) && !is_infinite$z)) {
       Â
        if ($ii$detail) {
          if ($jj$detail) {
            $poly = $ii$detail$jj+1;
            $polygons$poly][6] = $x
            $polygons$poly][7] = $y
            $polygons$poly][8] = $z
          }
         Â
          if ($jj>0) {
            $poly = $ii$detail$jj
            $polygons$poly][9] = $x
            $polygons$poly][10] = $y
            $polygons$poly][11] = $z
          }
        }
       Â
        if ($ii>0) {
          if ($jj$detail) {
            $poly = ($ii-1)*$detail$jj+1;
            $polygons$poly][3] = $x
            $polygons$poly][4] = $y
            $polygons$poly][5] = $z
          }
         Â
          if ($jj>0) {
            $poly = ($ii-1)*$detail$jj
            $polygons$poly][0] = $x
            $polygons$poly][1] = $y
            $polygons$poly][2] = $z
          }
        }
      }
    }
  }
 Â
  $polygons = array_values$polygons);
 Â
  // project each of the polygons into 2-d
  for ($i=0; $icount$polygons); $i++) {
    $points[] = project_polygon$polygons$i], -60, 180, 135, $center_x, $center_y, 0, $range, $range*2, true);
  }
 Â
  // scale the image somewhat
  $scale = $width*2/$range
 Â
  return render_polygons$points, $line_color, $surface_color, false, false, $width, $scale);
}Â