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"
}
Blog
eXorithm – Execute Algorithm: Discuss Algorithm draw_triangle
draw_triangle    version 0.4    Draw a filled triangle.
There are no comments yet
New Comment
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: Algorithms Beginning with O
eXorithm – Execute Algorithm: View / Run Algorithm volume_sphere
function volume_sphere ($radius
{
return (4/3) * pi() * pow$radius,3);
}
eXorithm – Execute Algorithm: Discuss Algorithm gaussian_curve
gaussian_curve    version 0.1    Plot the Gaussian function (a bell curve)
There are no comments yet
New Comment
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
}