note 70969 added to ref.math
| From: | tembenite at gmail dot com | Date: | Mon, 06 Nov 2006 21:36:18 +0000 |
| Subject: | note 70969 added to ref.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119443@lists.php.net to get a copy of this message | ||
To add to what Cornelius had, I have written a function that will take an array of numbers and
return the least common multiple of them:
function lcm_arr($items){
//Input: An Array of numbers
//Output: The LCM of the numbers
while(2 <= count($items)){
array_push($items, lcm(array_shift($items), array_shift($items)));
}
return reset($items);
}
//His Code below with $'s added for vars
function gcd($n, $m) {
$n=abs($n); $m=abs($m);
if ($n==0 and $m==0)
return 1; //avoid infinite recursion
if ($n==$m and $n>=1)
return $n;
return $m<$n?gcd($n-$m,$n):gcd($n,$m-$n);
}
function lcm($n, $m) {
return $m * ($n/gcd($n,$m));
}
----
Server IP: 86.55.8.30
Probable Submitter: 208.49.241.145
----
Manual Page -- http://www.php.net/manual/en/ref.math.php
Edit -- https://master.php.net/note/edit/70969
Del: integrated -- https://master.php.net/note/delete/70969/integrated
Del: useless -- https://master.php.net/note/delete/70969/useless
Del: bad code -- https://master.php.net/note/delete/70969/bad+code
Del: spam -- https://master.php.net/note/delete/70969/spam
Del: non-english -- https://master.php.net/note/delete/70969/non-english
Del: in docs -- https://master.php.net/note/delete/70969/in+docs
Del: other reasons-- https://master.php.net/note/delete/70969
Reject -- https://master.php.net/note/reject/70969
Search -- https://master.php.net/manage/user-notes.php