Re: [PHP] Math Question....

2010-04-23 Thread Richard Quadling
On 22 April 2010 17:47, Developer Team d...@thebat.net wrote:
 Awesome source.
 Thanks

 On 4/22/10, Richard Quadling rquadl...@googlemail.com wrote:
 On 22 April 2010 14:48, Dan Joseph dmjos...@gmail.com wrote:
 On Thu, Apr 22, 2010 at 10:29 AM, Richard Quadling
 rquadl...@googlemail.com
 wrote:

  
  It sounds like you are looking for factors.
 
 
 http://www.algebra.com/algebra/homework/divisibility/factor-any-number-1.solver
 
  Solution by Find factors of any number
 
  1252398 is NOT a prime number: 1252398 = 2 * 3 * 7 * 29819
  Work Shown
 
  1252398 is divisible by 2: 1252398 = 626199 * 2.
  626199 is divisible by 3: 626199 = 208733 * 3.
  208733 is divisible by 7: 208733 = 29819 * 7.
  29819 is not divisible by anything.
 
  So 29819 by 42 (7*3*2)
 
  would be a route.

 Aha. Missed the 30 bit.

 So, having found the factors, you would need to process them to find
 the largest combination under 30.

 2*3
 2*3*7
 2*7
 3*7

 are the possibilities (ignoring any number over 30).

 Of which 3*7 is the largest.

 So, 1,252,398 divided by 21 = 59,638


 Is that the sort of thing you are looking for?



 Yes, that looks exactly what like what I'm looking for.  I'm going to try
 and wake up the algebra side of my brain that hasn't been used in years
 and
 see if I can digest all this.

 For the 2, 3, and 7, that is based solely on the last number being
 divisible
 by a prime number?

 Joao, Jason, thanks for the code.

 --
 -Dan Joseph

 www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
 Code NEWTHINGS for 10% off initial order

 http://www.facebook.com/canishosting
 http://www.facebook.com/originalpoetry


 This seems to be working ...

 ?php
 function findBestFactors($Value, $GroupSize, array $Factors = null)
       {
       $Factors = array();
       foreach(range(1, ceil(sqrt($Value))) as $Factor)
               {
               if (0 == ($Value % $Factor))
                       {
                       if ($Factor = $GroupSize)
                               {
                               $Factors[] = $Factor;
                               }
                       if ($Factor != ($OtherFactor = ($Value / $Factor))  
 $OtherFactor
 = $GroupSize)
                               {
                               $Factors[] = $OtherFactor;
                               }
                       }

               if ($Factor = $GroupSize)
                       {
                       break;
                       }
               }

       rsort($Factors);

       return reset($Factors);
       }

 echo findBestFactors($argv[1], $argv[2], $Factors), PHP_EOL;
 ?


 factors 1252398988 5000

 outputs  ...

 4882

 and 21 for your value 1252398

 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




Thank you. It was a quick knock up, so could probably be optimized a
little more.

It will also not work beyond PHP_MAX_INT, unless the code is converted
to use the BCMath or GMP extension.

-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-23 Thread Dotan Cohen
On 22 April 2010 17:07, Dan Joseph dmjos...@gmail.com wrote:
 Howdy,

 This is a math question, but I'm doing the code in PHP, and have expunged
 all resources... hoping someone can guide me here.  For some reason, I can't
 figure this out.

 I want to take a group of items, and divide them into equal groups based on
 a max per group.  Example.

 1,252,398 -- divide into equal groups with only 30 items per group max.

 Can anyone guide me towards an algorithm or formula name to solve this?  PHP
 code or Math stuff is fine.  Either way...

 Thanks...


What is wrong with 626,299 groups of 2 items each (done in my head, so
I might be off a little)?

-- 
Dotan Cohen

http://bido.com
http://what-is-what.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-23 Thread Richard Quadling
On 23 April 2010 13:33, Dotan Cohen dotanco...@gmail.com wrote:
 What is wrong with 626,299 groups of 2 items each (done in my head, so
 I might be off a little)?

2, 3, 6, 7, 14 and 21 are all valid.


-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-23 Thread tedd

At 10:17 AM -0400 4/22/10, Dan Joseph wrote:

On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com wrote:


 1,252,398 DIV 30 = 41,746 groups of 30.

 1,252,398 MOD 30 = 18 items in last group


Well, the only problem with going that route, is the one group is not
equally sized to the others.  18 is ok for a group in this instance, but if
it was a remainder of only 1 or 2, there would be an issue.  Which is where
I come to looking for a the right method to break it equally.

--
-Dan Joseph



_Dan:

As I see it -- you are asking is What would be the 'optimum' group 
size for 1,252,398?


Optimum here meaning:

1. A group size of 30 or under;
2. All groups being of equal size.

Is that correct?

There may not be an exact solution, but a first order attempt would 
be to divide the total number by 30 and check the remainder (i.e., 
MOD), the do the same for 29, 28, 27... and so on.


The group size solution would be a number with a zero remainder OR 
with a remainder closest to your group size.


That would be my first blush solution.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-23 Thread Richard Quadling
?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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-22 Thread Stephen

Dan Joseph wrote:

I want to take a group of items, and divide them into equal groups based on
a max per group.  Example.

1,252,398 -- divide into equal groups with only 30 items per group max.


  

1,252,398 DIV 30 = 41,746 groups of 30.

1,252,398 MOD 30 = 18 items in last group

Stephen


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-22 Thread Dan Joseph
On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com wrote:

 1,252,398 DIV 30 = 41,746 groups of 30.

 1,252,398 MOD 30 = 18 items in last group

Well, the only problem with going that route, is the one group is not
equally sized to the others.  18 is ok for a group in this instance, but if
it was a remainder of only 1 or 2, there would be an issue.  Which is where
I come to looking for a the right method to break it equally.

-- 
-Dan Joseph

www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
Code NEWTHINGS for 10% off initial order

http://www.facebook.com/canishosting
http://www.facebook.com/originalpoetry


Re: [PHP] Math Question....

2010-04-22 Thread Ashley Sheridan
On Thu, 2010-04-22 at 10:17 -0400, Dan Joseph wrote:

 On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com wrote:
 
  1,252,398 DIV 30 = 41,746 groups of 30.
 
  1,252,398 MOD 30 = 18 items in last group
 
 Well, the only problem with going that route, is the one group is not
 equally sized to the others.  18 is ok for a group in this instance, but if
 it was a remainder of only 1 or 2, there would be an issue.  Which is where
 I come to looking for a the right method to break it equally.
 


How do you mean break it equally? If the number doesn't fit, then you've
got a remainder, and no math is going to change that. How do you want
that remainder distributed?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Math Question....

2010-04-22 Thread Richard Quadling
On 22 April 2010 15:13, Ashley Sheridan a...@ashleysheridan.co.uk wrote:
 On Thu, 2010-04-22 at 10:17 -0400, Dan Joseph wrote:

 On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com wrote:

  1,252,398 DIV 30 = 41,746 groups of 30.
 
  1,252,398 MOD 30 = 18 items in last group
 
 Well, the only problem with going that route, is the one group is not
 equally sized to the others.  18 is ok for a group in this instance, but if
 it was a remainder of only 1 or 2, there would be an issue.  Which is where
 I come to looking for a the right method to break it equally.



 How do you mean break it equally? If the number doesn't fit, then you've
 got a remainder, and no math is going to change that. How do you want
 that remainder distributed?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




It sounds like you are looking for factors.

http://www.algebra.com/algebra/homework/divisibility/factor-any-number-1.solver

Solution by Find factors of any number

1252398 is NOT a prime number: 1252398 = 2 * 3 * 7 * 29819
Work Shown

1252398 is divisible by 2: 1252398 = 626199 * 2.
626199 is divisible by 3: 626199 = 208733 * 3.
208733 is divisible by 7: 208733 = 29819 * 7.
29819 is not divisible by anything.

So 29819 by 42 (7*3*2)

would be a route.


Take note of 
http://www.algebra.com/algebra/homework/divisibility/Prime_factorization_algorithm.wikipedia,
which has the comment ...

Many cryptographic protocols are based on the difficultly of
factoring large composite integers or a related problem, the RSA
problem. An algorithm which efficiently factors an arbitrary integer
would render RSA-based public-key cryptography insecure..




-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-22 Thread Richard Quadling
On 22 April 2010 15:26, Richard Quadling rquadl...@googlemail.com wrote:
 On 22 April 2010 15:13, Ashley Sheridan a...@ashleysheridan.co.uk wrote:
 On Thu, 2010-04-22 at 10:17 -0400, Dan Joseph wrote:

 On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com wrote:

  1,252,398 DIV 30 = 41,746 groups of 30.
 
  1,252,398 MOD 30 = 18 items in last group
 
 Well, the only problem with going that route, is the one group is not
 equally sized to the others.  18 is ok for a group in this instance, but if
 it was a remainder of only 1 or 2, there would be an issue.  Which is where
 I come to looking for a the right method to break it equally.



 How do you mean break it equally? If the number doesn't fit, then you've
 got a remainder, and no math is going to change that. How do you want
 that remainder distributed?

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




 It sounds like you are looking for factors.

 http://www.algebra.com/algebra/homework/divisibility/factor-any-number-1.solver

 Solution by Find factors of any number

 1252398 is NOT a prime number: 1252398 = 2 * 3 * 7 * 29819
 Work Shown

 1252398 is divisible by 2: 1252398 = 626199 * 2.
 626199 is divisible by 3: 626199 = 208733 * 3.
 208733 is divisible by 7: 208733 = 29819 * 7.
 29819 is not divisible by anything.

 So 29819 by 42 (7*3*2)

 would be a route.


 Take note of 
 http://www.algebra.com/algebra/homework/divisibility/Prime_factorization_algorithm.wikipedia,
 which has the comment ...

 Many cryptographic protocols are based on the difficultly of
 factoring large composite integers or a related problem, the RSA
 problem. An algorithm which efficiently factors an arbitrary integer
 would render RSA-based public-key cryptography insecure..




 --
 -
 Richard Quadling
 Standing on the shoulders of some very clever giants!
 EE : http://www.experts-exchange.com/M_248814.html
 EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
 Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
 ZOPA : http://uk.zopa.com/member/RQuadling


Aha. Missed the 30 bit.

So, having found the factors, you would need to process them to find
the largest combination under 30.

2*3
2*3*7
2*7
3*7

are the possibilities (ignoring any number over 30).

Of which 3*7 is the largest.

So, 1,252,398 divided by 21 = 59,638


Is that the sort of thing you are looking for?

-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Math Question....

2010-04-22 Thread Jason
-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: 22 April 2010 15:13
To: Dan Joseph
Cc: PHP eMail List
Subject: Re: [PHP] Math Question

On Thu, 2010-04-22 at 10:17 -0400, Dan Joseph wrote:

 On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com wrote:
 
  1,252,398 DIV 30 = 41,746 groups of 30.
 
  1,252,398 MOD 30 = 18 items in last group
 
 Well, the only problem with going that route, is the one group is not
 equally sized to the others.  18 is ok for a group in this instance, but
if
 it was a remainder of only 1 or 2, there would be an issue.  Which is
where
 I come to looking for a the right method to break it equally.
 


How do you mean break it equally? If the number doesn't fit, then you've
got a remainder, and no math is going to change that. How do you want
that remainder distributed?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Perhaps a round-robin approach is called for?

?
$items=1252398;
$groupsize=30;

for ($i=0;$i$items;$i++)
$grouparray[$i % $groupsize][]=$i;


print_r($grouparray);
?

HTH
J


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-22 Thread Dan Joseph
On Thu, Apr 22, 2010 at 10:29 AM, Richard Quadling rquadl...@googlemail.com
 wrote:

  
  It sounds like you are looking for factors.
 
 
 http://www.algebra.com/algebra/homework/divisibility/factor-any-number-1.solver
 
  Solution by Find factors of any number
 
  1252398 is NOT a prime number: 1252398 = 2 * 3 * 7 * 29819
  Work Shown
 
  1252398 is divisible by 2: 1252398 = 626199 * 2.
  626199 is divisible by 3: 626199 = 208733 * 3.
  208733 is divisible by 7: 208733 = 29819 * 7.
  29819 is not divisible by anything.
 
  So 29819 by 42 (7*3*2)
 
  would be a route.

 Aha. Missed the 30 bit.

 So, having found the factors, you would need to process them to find
 the largest combination under 30.

 2*3
 2*3*7
 2*7
 3*7

 are the possibilities (ignoring any number over 30).

 Of which 3*7 is the largest.

 So, 1,252,398 divided by 21 = 59,638


 Is that the sort of thing you are looking for?



Yes, that looks exactly what like what I'm looking for.  I'm going to try
and wake up the algebra side of my brain that hasn't been used in years and
see if I can digest all this.

For the 2, 3, and 7, that is based solely on the last number being divisible
by a prime number?

Joao, Jason, thanks for the code.

-- 
-Dan Joseph

www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
Code NEWTHINGS for 10% off initial order

http://www.facebook.com/canishosting
http://www.facebook.com/originalpoetry


Re: [PHP] Math Question....

2010-04-22 Thread Peter van der Does
On Thu, 22 Apr 2010 10:17:10 -0400
Dan Joseph dmjos...@gmail.com wrote:

 On Thu, Apr 22, 2010 at 10:12 AM, Stephen stephe...@rogers.com
 wrote:
 
  1,252,398 DIV 30 = 41,746 groups of 30.
 
  1,252,398 MOD 30 = 18 items in last group
 
 Well, the only problem with going that route, is the one group is not
 equally sized to the others.  18 is ok for a group in this instance,
 but if it was a remainder of only 1 or 2, there would be an issue.
 Which is where I come to looking for a the right method to break it
 equally.
 

My take on it:

$Items=1252398;
$MaxInGroup=30;
for ($x=$MaxInGroup; $x1;$x--) {
$remainder=$Items % $x;
// Change 17 to the max amount allowed in the last group
if ($remainder == 0 || $remainder = 17) { // 
$groups = (int) ($Items /$x)+1;
echo $groups.\n;
echo $remainder;
break;
}
}

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-22 Thread Peter van der Does
On Thu, 22 Apr 2010 10:49:11 -0400
Peter van der Does pvanderd...@gmail.com wrote:


 
 My take on it:
 
 $Items=1252398;
 $MaxInGroup=30;
 for ($x=$MaxInGroup; $x1;$x--) {
   $remainder=$Items % $x;
   // Change 17 to the max amount allowed in the last group
   if ($remainder == 0 || $remainder = 17) { // 
   $groups = (int) ($Items /$x)+1;
   echo $groups.\n;
   echo $remainder;
   break;
   }
 }
 
Bugfixed LOL:
$Items=1252398;
$MaxInGroup=30;
for ($x=$MaxInGroup; $x1;$x--) {
$remainder=$Items % $x;
// Change 17 to the max amount allowed in a group
if ($remainder == 0 || $remainder = 17) {
$groups = (int) ($Items /$x);
if ($remainder  0 ) {
$groups++;
}
echo $groups.\n;
echo $remainder;
break;
}
}

-- 
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: @petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: @avhsoftware

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-22 Thread Richard Quadling
On 22 April 2010 14:48, Dan Joseph dmjos...@gmail.com wrote:
 On Thu, Apr 22, 2010 at 10:29 AM, Richard Quadling rquadl...@googlemail.com
 wrote:

  
  It sounds like you are looking for factors.
 
 
 http://www.algebra.com/algebra/homework/divisibility/factor-any-number-1.solver
 
  Solution by Find factors of any number
 
  1252398 is NOT a prime number: 1252398 = 2 * 3 * 7 * 29819
  Work Shown
 
  1252398 is divisible by 2: 1252398 = 626199 * 2.
  626199 is divisible by 3: 626199 = 208733 * 3.
  208733 is divisible by 7: 208733 = 29819 * 7.
  29819 is not divisible by anything.
 
  So 29819 by 42 (7*3*2)
 
  would be a route.

 Aha. Missed the 30 bit.

 So, having found the factors, you would need to process them to find
 the largest combination under 30.

 2*3
 2*3*7
 2*7
 3*7

 are the possibilities (ignoring any number over 30).

 Of which 3*7 is the largest.

 So, 1,252,398 divided by 21 = 59,638


 Is that the sort of thing you are looking for?



 Yes, that looks exactly what like what I'm looking for.  I'm going to try
 and wake up the algebra side of my brain that hasn't been used in years and
 see if I can digest all this.

 For the 2, 3, and 7, that is based solely on the last number being divisible
 by a prime number?

 Joao, Jason, thanks for the code.

 --
 -Dan Joseph

 www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
 Code NEWTHINGS for 10% off initial order

 http://www.facebook.com/canishosting
 http://www.facebook.com/originalpoetry


This seems to be working ...

?php
function findBestFactors($Value, $GroupSize, array $Factors = null)
{
$Factors = array();
foreach(range(1, ceil(sqrt($Value))) as $Factor)
{
if (0 == ($Value % $Factor))
{
if ($Factor = $GroupSize)
{
$Factors[] = $Factor;
}
if ($Factor != ($OtherFactor = ($Value / $Factor))  
$OtherFactor
= $GroupSize)
{
$Factors[] = $OtherFactor;
}
}

if ($Factor = $GroupSize)
{
break;
}
}

rsort($Factors);

return reset($Factors);
}

echo findBestFactors($argv[1], $argv[2], $Factors), PHP_EOL;
?


factors 1252398988 5000

outputs  ...

4882

and 21 for your value 1252398

-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question....

2010-04-22 Thread Dan Joseph
On Thu, Apr 22, 2010 at 12:16 PM, Richard Quadling rquadl...@googlemail.com
 wrote:

  On 22 April 2010 14:48, Dan Joseph dmjos...@gmail.com wrote:
 This seems to be working ...

 ?php
 function findBestFactors($Value, $GroupSize, array $Factors = null)
{
$Factors = array();
foreach(range(1, ceil(sqrt($Value))) as $Factor)
{
if (0 == ($Value % $Factor))
{
if ($Factor = $GroupSize)
{
$Factors[] = $Factor;
}
if ($Factor != ($OtherFactor = ($Value / $Factor))
  $OtherFactor
 = $GroupSize)
{
$Factors[] = $OtherFactor;
}
}

if ($Factor = $GroupSize)
{
break;
}
}

rsort($Factors);

return reset($Factors);
}

 echo findBestFactors($argv[1], $argv[2], $Factors), PHP_EOL;
 ?


 factors 1252398988 5000

 outputs  ...

 4882

 and 21 for your value 1252398



Wow!  thanks...  I just plopped it into phped and fired off some tests, and
I agree, seems to work fine.  I appreciate your help today.  I am still
looking over the algebra stuff, and am now comparing it to your code.  This
will get me moving forward better in my project.  Thank you!

-- 
-Dan Joseph

www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month.  Promo
Code NEWTHINGS for 10% off initial order

http://www.facebook.com/canishosting
http://www.facebook.com/originalpoetry


Re: [PHP] Math Question

2004-02-11 Thread Richard Davey
Hello Jeremy,

Wednesday, February 11, 2004, 2:00:32 PM, you wrote:

JS Is there a function that when you divide 2 numbers you drop the
JS remainder and are left with the whole number.

round($number1 / $number2)

See the manual for the precision value if you need it.

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Math Question

2004-02-11 Thread Vincent Jansen
Seems to me you need 

floor($number1 / $number2)


Vincent

-Original Message-
From: Richard Davey [mailto:[EMAIL PROTECTED] 
Sent: woensdag 11 februari 2004 15:07
To: Jeremy Schroeder
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Math Question


Hello Jeremy,

Wednesday, February 11, 2004, 2:00:32 PM, you wrote:

JS Is there a function that when you divide 2 numbers you drop the 
JS remainder and are left with the whole number.

round($number1 / $number2)

See the manual for the precision value if you need it.

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Math Question

2004-02-11 Thread Jeremy Schroeder
Thanks for all the help, floor() was the correct choice for this problem .

-Blake

Vincent Jansen wrote:

Hi Richard

I agree
But you always want to round down ;)
Blake Is there a function that when you divide 2 numbers you drop the 
Blake remainder and are left with the whole number.

Still seems floor() to me

Vincent



-Original Message-
From: Richard Davey [mailto:[EMAIL PROTECTED] 
Sent: woensdag 11 februari 2004 15:23
To: Vincent Jansen
Cc: [EMAIL PROTECTED]
Subject: Re[2]: [PHP] Math Question

Hello Vincent,

Wednesday, February 11, 2004, 2:15:15 PM, you wrote:

VJ Seems to me you need
VJ floor($number1 / $number2)
Only if you always want to round *down* the equation. For example
flooring a result of 4.99 will give you an integer of 4 whereas
round() (or ceil()) will give you 5. It depends on the situation as to
which is most useful.
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Math Question

2004-02-11 Thread John Nichel
Jeremy Schroeder wrote:

Hey group

Is there a function that when you divide 2 numbers you drop the 
remainder and are left with the whole number.

A whole section of the manual dedicated to mathematical functions!

http://us4.php.net/manual/en/ref.math.php

floor()
ceil()
round()
--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP Math Question

2003-12-11 Thread Eric Bolikowski

Mike D [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
 I'm am completely stumped on a seemingly simple math formula

 I need to find a way to map a set of numbers up to 4 (e.g. 1,2,3,4 or 1,2)
 to any number in a range of up to 10,000 (ideally, unlimited). Such that,

 (e.g. 1,2,3,4)

 1 is to 1
 2 is to 2
 3 is to 3
 4 is to 4

 5 is to 1
 6 is to 2
 7 is to 3
 8 is to 4

 9 is to 1
 10 is to 2
 11 is to 3
 12 is to 4

 13 is to 1
 14 is to 2
 15 is to 3
 16 is to 4

 And so on...

 Is anyone good at math, that can throw me a bone?

 Thanks y'all,
 Mike D


 
 Mike Dunlop
 AWN, Inc.
 // www.awn.com
 [ e ] [EMAIL PROTECTED]
 [ p ] 323.606.4237

Here is some simple code to solve that problem(if i have understood right):

?php

for($i = 1, $j = 1; $i = 1; $i++, $j++){

 if($j == 5){
  $j = 1;
  print \nbr;
 }

 print $i is to $jbr\n;

}

?

Eric

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Re: PHP Math Question

2003-12-11 Thread Bronislav Kluka
I do not know if I understand well, but what about 

$group=$number % 4;
if ($group==0) $group=4;

Brona

 -Original Message-
 From: Eric Bolikowski [mailto:[EMAIL PROTECTED]
 Sent: Thursday, December 11, 2003 10:53 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Re: PHP Math Question
 
 
 
 Mike D [EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
  I'm am completely stumped on a seemingly simple math formula
 
  I need to find a way to map a set of numbers up to 4 (e.g. 
 1,2,3,4 or 1,2)
  to any number in a range of up to 10,000 (ideally, unlimited). 
 Such that,
 
  (e.g. 1,2,3,4)
 
  1 is to 1
  2 is to 2
  3 is to 3
  4 is to 4
 
  5 is to 1
  6 is to 2
  7 is to 3
  8 is to 4
 
  9 is to 1
  10 is to 2
  11 is to 3
  12 is to 4
 
  13 is to 1
  14 is to 2
  15 is to 3
  16 is to 4
 
  And so on...
 
  Is anyone good at math, that can throw me a bone?
 
  Thanks y'all,
  Mike D
 
 
  
  Mike Dunlop
  AWN, Inc.
  // www.awn.com
  [ e ] [EMAIL PROTECTED]
  [ p ] 323.606.4237
 
 Here is some simple code to solve that problem(if i have 
 understood right):
 
 ?php
 
 for($i = 1, $j = 1; $i = 1; $i++, $j++){
 
  if($j == 5){
   $j = 1;
   print \nbr;
  }
 
  print $i is to $jbr\n;
 
 }
 
 ?
 
 Eric
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP Math Question

2003-12-11 Thread Website Managers.net
I like Eric's idea of showing the values and added a form to it so you can 
select the number of items to show before running the script.

?php
if(!$_POST[Submit]) {
echo form method=post action=.$_SERVER[PHP_SELF].
Maximum Number to Show: input type=text name=i size=5 value=1
input type=submit name=Submit value=Show
/form;
}

else {
for($i = 1, $j = 1; $i = $_POST[i]; $i++, $j++){

 if($j == 5){
  $j = 1;
  print \nbr;
 }

 print $i. is to .$j.br\n;

} // end for

?

Jim

- Original Message - 
From: Bronislav Kluka [EMAIL PROTECTED]
To: Eric Bolikowski [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, December 11, 2003 5:22 PM
Subject: RE: [PHP] Re: PHP Math Question


| I do not know if I understand well, but what about 
| 
| $group=$number % 4;
| if ($group==0) $group=4;
| 
| Brona
| 
|  -Original Message-
|  From: Eric Bolikowski [mailto:[EMAIL PROTECTED]
|  Sent: Thursday, December 11, 2003 10:53 PM
|  To: [EMAIL PROTECTED]
|  Subject: [PHP] Re: PHP Math Question
|  
|  
|  
|  Mike D [EMAIL PROTECTED] wrote in message 
|  news:[EMAIL PROTECTED]
|   I'm am completely stumped on a seemingly simple math formula
|  
|   I need to find a way to map a set of numbers up to 4 (e.g. 
|  1,2,3,4 or 1,2)
|   to any number in a range of up to 10,000 (ideally, unlimited). 
|  Such that,
|  
|   (e.g. 1,2,3,4)
|  
|   1 is to 1
|   2 is to 2
|   3 is to 3
|   4 is to 4
|  
|   5 is to 1
|   6 is to 2
|   7 is to 3
|   8 is to 4
|  
|   9 is to 1
|   10 is to 2
|   11 is to 3
|   12 is to 4
|  
|   13 is to 1
|   14 is to 2
|   15 is to 3
|   16 is to 4
|  
|   And so on...
|  
|   Is anyone good at math, that can throw me a bone?
|  
|   Thanks y'all,
|   Mike D
|  
|  
|   
|   Mike Dunlop
|   AWN, Inc.
|   // www.awn.com
|   [ e ] [EMAIL PROTECTED]
|   [ p ] 323.606.4237
|  
|  Here is some simple code to solve that problem(if i have 
|  understood right):
|  
|  ?php
|  
|  for($i = 1, $j = 1; $i = 1; $i++, $j++){
|  
|   if($j == 5){
|$j = 1;
|print \nbr;
|   }
|  
|   print $i is to $jbr\n;
|  
|  }
|  
|  ?
|  
|  Eric
|  
|  -- 
|  PHP General Mailing List (http://www.php.net/)
|  To unsubscribe, visit: http://www.php.net/unsub.php
|  
| 
| -- 
| PHP General Mailing List (http://www.php.net/)
| To unsubscribe, visit: http://www.php.net/unsub.php
| 
|

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP Math Question

2003-12-11 Thread Rob Bryant
 Mike D [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

I'm am completely stumped on a seemingly simple math formula

I need to find a way to map a set of numbers up to 4 (e.g. 1,2,3,4 or 1,2)
to any number in a range of up to 10,000 (ideally, unlimited). Such that,
(e.g. 1,2,3,4)

1 is to 1
2 is to 2
3 is to 3
4 is to 4
5 is to 1
6 is to 2
7 is to 3
8 is to 4
9 is to 1
10 is to 2
11 is to 3
12 is to 4
13 is to 1
14 is to 2
15 is to 3
16 is to 4
etc.

Here is an (untested) function that may work:

function map_four( $num )
{
$map_val = $num % 4;
if ($map_val) {
return $map_val;
} else {
return 4;
}
}
Basically, it looks like a modulus with 4, except that you want 
multiples of four to return four instead of zero.

Unless, of course, I completely misunderstood the question. Which is not 
uncommon as of late.

--
Rob
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: PHP Math Question

2003-12-11 Thread Eric Bolikowski

Website Managers.Net [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
I like Eric's idea of showing the values and added a form to it so you can
select the number of items to show before running the script.

?php
if(!$_POST[Submit]) {
echo form method=post action=.$_SERVER[PHP_SELF].
Maximum Number to Show: input type=text name=i size=5 value=1
input type=submit name=Submit value=Show
/form;
}

else {
for($i = 1, $j = 1; $i = $_POST[i]; $i++, $j++){

 if($j == 5){
  $j = 1;
  print \nbr;
 }

 print $i. is to .$j.br\n;

} // end for

?

Jim

- Original Message - 
From: Bronislav Kluèka [EMAIL PROTECTED]
To: Eric Bolikowski [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Thursday, December 11, 2003 5:22 PM
Subject: RE: [PHP] Re: PHP Math Question


| I do not know if I understand well, but what about
|
| $group=$number % 4;
| if ($group==0) $group=4;
|
| Brona
|
|  -Original Message-
|  From: Eric Bolikowski [mailto:[EMAIL PROTECTED]
|  Sent: Thursday, December 11, 2003 10:53 PM
|  To: [EMAIL PROTECTED]
|  Subject: [PHP] Re: PHP Math Question
| 
| 
| 
|  Mike D [EMAIL PROTECTED] wrote in message
|  news:[EMAIL PROTECTED]
|   I'm am completely stumped on a seemingly simple math formula
|  
|   I need to find a way to map a set of numbers up to 4 (e.g.
|  1,2,3,4 or 1,2)
|   to any number in a range of up to 10,000 (ideally, unlimited).
|  Such that,
|  
|   (e.g. 1,2,3,4)
|  
|   1 is to 1
|   2 is to 2
|   3 is to 3
|   4 is to 4
|  
|   5 is to 1
|   6 is to 2
|   7 is to 3
|   8 is to 4
|  
|   9 is to 1
|   10 is to 2
|   11 is to 3
|   12 is to 4
|  
|   13 is to 1
|   14 is to 2
|   15 is to 3
|   16 is to 4
|  
|   And so on...
|  
|   Is anyone good at math, that can throw me a bone?
|  
|   Thanks y'all,
|   Mike D
|  
|  
|   
|   Mike Dunlop
|   AWN, Inc.
|   // www.awn.com
|   [ e ] [EMAIL PROTECTED]
|   [ p ] 323.606.4237
| 
|  Here is some simple code to solve that problem(if i have
|  understood right):
| 
|  ?php
| 
|  for($i = 1, $j = 1; $i = 1; $i++, $j++){
| 
|   if($j == 5){
|$j = 1;
|print \nbr;
|   }
| 
|   print $i is to $jbr\n;
| 
|  }
| 
|  ?
| 
|  Eric
| 
|  -- 
|  PHP General Mailing List (http://www.php.net/)
|  To unsubscribe, visit: http://www.php.net/unsub.php
| 
|
| -- 
| PHP General Mailing List (http://www.php.net/)
| To unsubscribe, visit: http://www.php.net/unsub.php
|
|

Mike sent me an email, and it seemed that he was satisfied with the script
that I made:

?php

for($i = 1, $j = 1; $i = 1; $i++, $j++){

 if($j == 5){
  $j = 1;
  print \nbr;
 }

 print $i is to $jbr\n;

}

?


Good idea to rather make an interface for this, Jim!

Eric

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] math question

2001-06-23 Thread Hugh Bothwell


Julia A. Case [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 $theta = 15*pi/360;
 gives a value of 0 for $theta...  it should be something like 0.131...

 Julia

I get
echo 15 * M_PI / 360;
returns
0.13089969389957




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] math question

2001-06-23 Thread Anon Y Mous

pi is a function. Try this:

$theta = 15*pi()/360;

It should return 0.13089969389957


-Evan Nemerson


 $theta = 15*pi/360;
 gives a value of 0 for $theta...  it should be something like 0.131...

 Julia


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] math question

2001-06-23 Thread Zak Greant

Have you defined the 'pi' constant?

If you are trying to use PHP's built-in PI constant, it is named 'M_PI'

Perhaps consider increasing your error reporting level so that PHP reports
problems like undefined constants - see error_reporting() for more details.

--zak

- Original Message -
From: Julia A. Case [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, June 23, 2001 12:07 AM
Subject: [PHP] math question


 $theta = 15*pi/360;
 gives a value of 0 for $theta...  it should be something like 0.131...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] math question

2001-06-23 Thread George Alexander

If u don't want to use the pi() function.
Try M_PI. This is a pi constant its value is 3.14159265358979323846

$theta=15*M_PI/360;

- Original Message - 
From: Anon Y Mous [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, June 23, 2001 2:21 PM
Subject: Re: [PHP] math question


 pi is a function. Try this:
 
 $theta = 15*pi()/360;
 
 It should return 0.13089969389957
 
 
 -Evan Nemerson
 
 
  $theta = 15*pi/360;
  gives a value of 0 for $theta...  it should be something like 0.131...
 
  Julia
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]