|
|
|
| <?
/********************************************************
** Permutations, Combinations and Factorials
**
** Author.: leapinglangoor [ leapinglangoor@yahoo.co.in ]
** Date...: 12th feb 2005
** Version: v1.2
**
** Desc...: Permutations and combinations are a major part
** of maths and here it is in PHP
**
********************************************************/
class maths
{
function fact( $num )
{
$res = 1;
for ($i = 2; $i <= $num; $i++)
{
$res *= $i;
}
return $res;
}
function perms( $n, $r )
{
if( $r > $n )
{
return 0;
}
$i = 0;
$res = 1;
while( $i < $r )
{
$res = $res * $n;
$i++;
$n--;
}
return $res;
}
function combos( $n, $r )
{
if( $r > $n )
{
return 0;
}
$res = perms( $n, $r );
$res = $res / fact( $r );
return $res;
}
} // End class math
?> | |
example1.php:
| <?php
include( 'math.php' );
$maths = new maths;
$n = 5;
$r = 3;
$n = 5;
$r = 3;
$maths->fact( $n ); // Factorial of $n
echo $m->fact( $n ); // returns 120
$maths->perms( $n, $r ); // Permutations of $n taking $r things at a time.
echo $m->perms( $n, $r ); // returns 60
$maths->combos( $n, $r ); // Combinations of $n taking $r things at a time.
echo $m->cobos( $n, $r ); // returns 10
?> | | |
|
| 3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations. Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs | | | Greatest Common Denominator - A simple class that finds the greatest common denominator for two integers.
Categories : PHP, PHP Classes, Math. | | | Latitude-Longitude to Miles Categories : PHP, Utilities, Math. | | | very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | Math operations on big numbers Categories : PHP, Math. | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | A Timing Class Categories : PHP, PHP Classes, Date Time | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | These PHP Classes Check if a host is alive using various methods. Categories : PHP, PHP Classes, Sockets, CURL | | | RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | Weighted Random - Random Scripts usually chose one out of each item, and each item have an equal chance to be chosen. But what if you want an item to be chosed more frequently than other? Categories : PHP, Math., Arrays | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email, Network, PHP, PHP Classes | |
| | | | paulz leex wrote : 1321
can not run, with error :
Warning: Unterminated comment starting line 3 in C:\Program Files\Apache Group\Apache2\htdocs\per2.php on line 3
| | | | leapinglangoor wrote : 1322
uhmmmm... Is it just me, or is the example showing only "<?php" - somebody`s gotto really look into this!!!
| | | | Boaz Yahav wrote :1323
fixed :)
| |
|
|
|