eXorithm – Execute Algorithm: View / Run Algorithm simple_calculator

function simple_calculator ($number1$operator$number2
{
  // calculator
  
  switch ($operator) {
    case "plus"
      $res = $number1$number2
      break
    case "minus"
      $res = $number1$number2
      break
    case "times"
      $res = $number1$number2
      break
    case "divided by"
      $res = $number1$number2
      break
    default
      $res = 0;
  }
  
  return $res

eXorithm – Execute Algorithm: Embed Algorithm make_change


Embed This Algorithm

This page will help you embed the algorithm make_change on a page on your own website. Just configure the inputs, then click the generate button to get a snippet of code you can paste onto your site. You have two options.

  1. You can embed the entire form. Users will be able to enter their own arguments, and will need to press the run button to execute the algorithm.
  2. You can add only the output of the algorithm to your website. There will be no argument inputs or run button.

amount Argument info
coins
Argument info
Embed the form Embed only the output

eXorithm – Execute Algorithm: Embed Algorithm draw_triangle


Embed This Algorithm

This page will help you embed the algorithm draw_triangle on a page on your own website. Just configure the inputs, then click the generate button to get a snippet of code you can paste onto your site. You have two options.

  1. You can embed the entire form. Users will be able to enter their own arguments, and will need to press the run button to execute the algorithm.
  2. You can add only the output of the algorithm to your website. There will be no argument inputs or run button.

points
Argument info
color Argument info
Embed the form Embed only the output

eXorithm – Execute Algorithm: Embed Algorithm photobucket


Embed This Algorithm

This page will help you embed the algorithm photobucket on a page on your own website. Just configure the inputs, then click the generate button to get a snippet of code you can paste onto your site. You have two options.

  1. You can embed the entire form. Users will be able to enter their own arguments, and will need to press the run button to execute the algorithm.
  2. You can add only the output of the algorithm to your website. There will be no argument inputs or run button.
url Argument info
Embed the form Embed only the output

Validate Domain

<?php

/**
 * validate_domain
 *
 * validate domain
 *
 * @version 0.5
 * @author Contributors at eXorithm
 * @link /algorithm/view/validate_domain Listing at eXorithm
 * @link /algorithm/history/validate_domain History at eXorithm
 * @license /home/show/license
 *
 * @param mixed $domain 
 * @return bool
 */
function validate_domain($domain='www.google.com')
{
	return preg_match ("/^[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu)$/i", $domain);
}

?>

eXorithm – Execute Algorithm: View / Run Algorithm raise_polygon

function raise_polygon ($points$height$direction$color
{
  // check points
  if ((count$points)==0) || ((count$points)%2)!=0)) {
    throw new Exception'The points must be an array with an even number of integers.');
  }
  
  // determine the extent of the polygon
  $maxx = $points[0];
  $maxy = $points[1];
  $minx = $points[0];
  $miny = $points[1];
  for ($i=2; $icount$points); $i$i+2) {
    $x = $points$i];
    $y = $points$i+1];
    if ($x$maxx$maxx = $x
    if ($y$maxy$maxy = $y
    if ($x$minx$minx = $x
    if ($y$miny$miny = $y
  }
  
  // determine the extent of the projection
  $proj_length = roundsqrt$height$height/2));
  switch ($direction) {
    case 'nw'
      $projx = $proj_length*-1;
      $projy = $proj_length*-1;
      break
    case 'ne'
      $projx = $proj_length
      $projy = $proj_length*-1;
      break
    case 'sw'
      $projx = $proj_length*-1;
      $projy = $proj_length
      break
    default
      $projx = $proj_length
      $projy = $proj_length
  }
  
  // determine where the polygon should be positioned
  for ($i=0; $icount$points); $i$i+2) {
    $points$i] = $points$i]-$minx+1;
    $points$i+1] = $points$i+1]-$miny+1;
    if ($projx<0) $points$i] = $points$i] - $projx
    if ($projy<0) $points$i+1] = $points$i+1] - $projy
  }
  
  // blank image
  $image = image_create_alpha$maxx$minx$proj_length+2, $maxy$miny$proj_length+2);
  
  // create the colors
  $r  = hexdecsubstr$color, 0, 2));
  $g  = hexdecsubstr$color, 2, 2));
  $b  = hexdecsubstr$color, 4, 2));
  $color = imagecolorallocate$image$r$g$b);
  
  // draw the first polygon
  imagepolygon$image$pointscount$points)/2, $color);
  
  // draw the lines + modify the points
  for ($i=0; $icount$points); $i$i+2) {
    imageline$image$points$i], $points$i+1], $points$i]+$projx$points$i+1]+$projy$color);
    $points$i] = $points$i]+$projx
    $points$i+1] = $points$i+1]+$projy
  }
  
  // draw the second polygon
  imagepolygon$image$pointscount$points)/2, $color);
  
  return $image

eXorithm – Execute Algorithm: View / Run Algorithm show_address

function show_address ($address
{
  $data = file_get_contents"http://maps.googleapis.com/maps/api/geocode/json?address="urlencode$address)."&sensor=false");
  $obj = json_decode$data);
  if ($obj) {
    if (isset$obj->results[0]->geometry->location)) {
      $loc = $obj->results[0]->geometry->location;
      return array'latitude'=>$loc->lat, 'longitude'=>$loc->lng);
    } else {
      throw new Exception'Lookup failed and/or address does not exist!');
    }
  } else {
    throw new Exception'Lookup failed and/or address does not exist!');
  }