Category: Algorithm
Unity
<?php /** * unity * * Returns digit summation of any numerical value given for passkey (up to 14 digits in length) * * @version 1.2 * @author Contributors at eXorithm * @link /algorithm/view/unity Listing at eXorithm * @link /algorithm/history/unity History at eXorithm * @license /home/show/license * * @param number $passkey enter any numerical "whole" digits (non-negative) * @return mixed */ function unity($passkey=75025) { $ubn = array(); while ($passkey > 9) { if (strlen($passkey) > 1) $passkey = array_sum(str_split($passkey)); else $passkey = $passkey; } $ubn[] = $passkey; return end($ubn); } ?>
eXorithm – Execute Algorithm: Algorithms Beginning with J
eXorithm – Execute Algorithm: View / Run Algorithm round_up
function round_up ($num, $precision
{
$pow = pow(10, $precision);
return ceil$num * $pow)/$pow
}
eXorithm – Execute Algorithm: Please Login or Register
Log In or Create Account
You need to log in to access this part of the website. Use the form on the left side of the screen.
If you are not yet registered, you can create an account. Registering is free, and allows you to edit algorithms, participate on the forums, and more!
eXorithm – Execute Algorithm: Embed Algorithm overlay_image
Embed This Algorithm
This page will help you embed the algorithm overlay_image 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.
- 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.
- You can add only the output of the algorithm to your website. There will be no argument inputs or run button.
eXorithm – Execute Algorithm: Embed Algorithm validate_domain
Embed This Algorithm
This page will help you embed the algorithm validate_domain 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.
- 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.
- You can add only the output of the algorithm to your website. There will be no argument inputs or run button.
eXorithm – Execute Algorithm: View / Run Algorithm books_by
function books_by ($author
{
// construct the query
$query = array'limit'=>100,
'name'=>null,
'type'=>'/book/written_work',
'author'=>array'name'=>$author));
// issue the query
$results = freebase_query$query);
$books = array();
foreach ($results as $result) {
if (isset$result'name'])) {
$books[] = $result'name'];
}
}
return $books
}
eXorithm – Execute Algorithm: View / Run Algorithm diceRoll
function diceRoll ($numSides, $numDice
{
$rolls = array();
/*Rolls each die and stores it's value while also keeping a running
total of the rolls.*/
for ($i = 0; $i < $numDice; $i++)
{
$dieValue = rand(1, $numSides);
$rollTotal += $dieValue
Array_push$rolls, $dieValue);
}
//Adds the roll total to the final index.
Array_push$rolls, $rollTotal);
return $rolls
}
eXorithm – Execute Algorithm: View / Run Algorithm freebase_query
function freebase_query ($query
{
$queryarray = array'q'=>array'query'=>array$query)));
$jsonquerystr = json_encode$queryarray);
$jsonquerystr = urlencode$jsonquerystr);
$apiendpoint = "http://api.freebase.com/api/service/mqlread?queries"
$ch = curl_init();
curl_setopt$ch, CURLOPT_URL, "$apiendpoint=$jsonquerystr");
curl_setopt$ch, CURLOPT_HEADER, 0);
curl_setopt$ch, CURLOPT_RETURNTRANSFER, 1);
$jsonresultstr = curl_exec$ch);
curl_close$ch);
$resultarray = json_decode$jsonresultstr, true);
if (isset$resultarray'q']['result'])) {
return $resultarray'q']['result'];
} else {
if (isset$resultarray'q']['messages'][0]['message'])) {
throw new Exception"Error: "$resultarray'q']['messages'][0]['message']);
} else {
throw new Exception"Error");
}
}
}