From: Richard Quadling on 23 Apr 2010 11:03 <?php function findBestFactors($Value, $GroupSize = INF) { foreach(range(min($GroupSize, ceil(sqrt($Value))), 1) as $Factor) { if (0 == ($Value % $Factor)) { return array($Factor, $Value / $Factor); } } } list($Groups, $Size) = findBestFactors($argv[1], isset($argv[2]) ? $argv[2] : INF); echo "$Groups groups of $Size"; ?> Supply a value and an optional maximum group size.
First
|
Prev
|
Pages: 1 2 3 4 5 Prev: Updating cli executable on MS-Windows Next: Replace a space with a newline every 2 spaces |