Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

w2ksp4.exe, WwwxxXdbf, procmail "FROM_MAILER" patch, Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table, 800c5000, setgid operation not permitted, pciehp: acpi_pciehprm on IBM, WWWXXX.DBF

Links

XODOX
Impressum

#1: Math Question....

Posted on 2010-04-22 16:07:07 by Dan Joseph

--0016363b843e7d9d110484d3d399
Content-Type: text/plain; charset=ISO-8859-1

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...

--
-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

--0016363b843e7d9d110484d3d399--

Report this message

#2: Re: Math Question....

Posted on 2010-04-22 16:12:12 by 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

Report this message

#3: Re: Math Question....

Posted on 2010-04-22 16:13:03 by Ashley Sheridan

--=-9whhZ86anga93zA6dAmo
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

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

> On Thu, Apr 22, 2010 at 10:12 AM, Stephen <stephen-d@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



--=-9whhZ86anga93zA6dAmo--

Report this message

#4: Re: Math Question....

Posted on 2010-04-22 16:17:10 by Dan Joseph

--00c09fa21e376d96b20484d3f77a
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Apr 22, 2010 at 10:12 AM, Stephen <stephen-d@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

--00c09fa21e376d96b20484d3f77a--

Report this message

#5: Re: Math Question....

Posted on 2010-04-22 16:24:35 by joao

for ($g = $maxpergroup; $g > 0; $g++) {
if ($items mod $g <> 0) continue;
$Groups = $items div $g;
}

Maybe it can helps you.

"Dan Joseph" <dmjoseph@gmail.com> escreveu na mensagem
news:q2oa20394491004220707x980cef5ej2b310c97d123056b@mail.gm ail.com...
> 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...
>
> --
> -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
>



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

Report this message

#6: Re: Math Question....

Posted on 2010-04-22 16:26:05 by Richard Quadling

On 22 April 2010 15:13, Ashley Sheridan <ash@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 <stephen-d@rogers.com> wrote:
>>
>> > 1,252,398 DIV 30 =3D 41,746 groups of 30.
>> >
>> > 1,252,398 MOD 30 =3D 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.so=
lver

Solution by Find factors of any number

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

1252398 is divisible by 2: 1252398 =3D 626199 * 2.
626199 is divisible by 3: 626199 =3D 208733 * 3.
208733 is divisible by 7: 208733 =3D 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_f ac=
torization_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.".




--=20
-----
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=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

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

Report this message

#7: Re: Math Question....

Posted on 2010-04-22 16:26:49 by joao

there´s an error in the forget the former:

for ($g = $maxpergroup; $g > 0; $g--) {
if ($items mod $g <> 0) continue;
$Groups = $items div $g;
}


""João Cândido de Souza Neto"" <joao@consultorweb.cnt.br> escreveu na
mensagem news:87.84.21218.63C50DB4@pb1.pair.com...
> for ($g = $maxpergroup; $g > 0; $g++) {
> if ($items mod $g <> 0) continue;
> $Groups = $items div $g;
> }
>
> Maybe it can helps you.
>
> "Dan Joseph" <dmjoseph@gmail.com> escreveu na mensagem
> news:q2oa20394491004220707x980cef5ej2b310c97d123056b@mail.gm ail.com...
>> 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...
>>
>> --
>> -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
>>
>
>



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

Report this message

#8: Re: Math Question....

Posted on 2010-04-22 16:29:03 by Richard Quadling

On 22 April 2010 15:26, Richard Quadling <rquadling@googlemail.com> wrote:
> On 22 April 2010 15:13, Ashley Sheridan <ash@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 <stephen-d@rogers.com> wrote:
>>>
>>> > 1,252,398 DIV 30 =3D 41,746 groups of 30.
>>> >
>>> > 1,252,398 MOD 30 =3D 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 instanc=
e, 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 =3D 2 * 3 * 7 * 29819
> Work Shown
>
> 1252398 is divisible by 2: 1252398 =3D 626199 * 2.
> 626199 is divisible by 3: 626199 =3D 208733 * 3.
> 208733 is divisible by 7: 208733 =3D 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_f =
actorization_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=3DZEND002498&r=3D2134=
74731
> 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 =3D 59,638


Is that the sort of thing you are looking for?

--=20
-----
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=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

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

Report this message

#9: Re: Math Question....

Posted on 2010-04-22 16:29:33 by joao

I think today is not may day to write. hehehe

sorry.
""João Cândido de Souza Neto"" <joao@consultorweb.cnt.br> escreveu na
mensagem news:12.B5.21218.F0D50DB4@pb1.pair.com...
> there´s an error in the forget the former:
>
> for ($g = $maxpergroup; $g > 0; $g--) {
> if ($items mod $g <> 0) continue;
> $Groups = $items div $g;
> }
>
>
> ""João Cândido de Souza Neto"" <joao@consultorweb.cnt.br> escreveu na
> mensagem news:87.84.21218.63C50DB4@pb1.pair.com...
>> for ($g = $maxpergroup; $g > 0; $g++) {
>> if ($items mod $g <> 0) continue;
>> $Groups = $items div $g;
>> }
>>
>> Maybe it can helps you.
>>
>> "Dan Joseph" <dmjoseph@gmail.com> escreveu na mensagem
>> news:q2oa20394491004220707x980cef5ej2b310c97d123056b@mail.gm ail.com...
>>> 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...
>>>
>>> --
>>> -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
>>>
>>
>>
>
>



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

Report this message

#10: RE: Math Question....

Posted on 2010-04-22 16:37:03 by Network Admin

-----Original Message-----
From: Ashley Sheridan [mailto:ash@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 <stephen-d@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

Report this message

#11: Re: Math Question....

Posted on 2010-04-22 16:40:42 by joao

I´ll try this again:

for ($g = $maxpergroup; $g > 0; $g--) {
if ($items mod $g <> 0) continue;
$Groups = $items div $g;
break;
}

Hope it helps.

""João Cândido de Souza Neto"" <joao@consultorweb.cnt.br> escreveu na
mensagem news:05.36.21218.06D50DB4@pb1.pair.com...
>I think today is not may day to write. hehehe
>
> sorry.
> ""João Cândido de Souza Neto"" <joao@consultorweb.cnt.br> escreveu na
> mensagem news:12.B5.21218.F0D50DB4@pb1.pair.com...
>> there´s an error in the forget the former:
>>
>> for ($g = $maxpergroup; $g > 0; $g--) {
>> if ($items mod $g <> 0) continue;
>> $Groups = $items div $g;
>> }
>>
>>
>> ""João Cândido de Souza Neto"" <joao@consultorweb.cnt.br> escreveu na
>> mensagem news:87.84.21218.63C50DB4@pb1.pair.com...
>>> for ($g = $maxpergroup; $g > 0; $g++) {
>>> if ($items mod $g <> 0) continue;
>>> $Groups = $items div $g;
>>> }
>>>
>>> Maybe it can helps you.
>>>
>>> "Dan Joseph" <dmjoseph@gmail.com> escreveu na mensagem
>>> news:q2oa20394491004220707x980cef5ej2b310c97d123056b@mail.gm ail.com...
>>>> 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...
>>>>
>>>> --
>>>> -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
>>>>
>>>
>>>
>>
>>
>
>



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

Report this message

#12: Re: Math Question....

Posted on 2010-04-22 16:48:50 by Dan Joseph

--0016363b8510ab819c0484d468c2
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Apr 22, 2010 at 10:29 AM, Richard Quadling <rquadling@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

--0016363b8510ab819c0484d468c2--

Report this message

#13: Re: Math Question....

Posted on 2010-04-22 16:49:11 by Peter van der Does

On Thu, 22 Apr 2010 10:17:10 -0400
Dan Joseph <dmjoseph@gmail.com> wrote:

> On Thu, Apr 22, 2010 at 10:12 AM, Stephen <stephen-d@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; $x>1;$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

Report this message

#14: Re: Math Question....

Posted on 2010-04-22 16:59:34 by Peter van der Does

On Thu, 22 Apr 2010 10:49:11 -0400
Peter van der Does <pvanderdoes@gmail.com> wrote:


>
> My take on it:
>
> $Items=1252398;
> $MaxInGroup=30;
> for ($x=$MaxInGroup; $x>1;$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; $x>1;$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

Report this message

#15: Re: Math Question....

Posted on 2010-04-22 18:16:57 by Richard Quadling

On 22 April 2010 14:48, Dan Joseph <dmjoseph@gmail.com> wrote:
> On Thu, Apr 22, 2010 at 10:29 AM, Richard Quadling <rquadling@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 =3D 2 * 3 * 7 * 29819
>> > Work Shown
>> >
>> > 1252398 is divisible by 2: 1252398 =3D 626199 * 2.
>> > 626199 is divisible by 3: 626199 =3D 208733 * 3.
>> > 208733 is divisible by 7: 208733 =3D 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 =3D 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 t=
o try
> and wake up the algebra side of my brain that hasn't been used in years a=
nd
> see if I can digest all this.
>
> For the 2, 3, and 7, that is based solely on the last number being divisi=
ble
> by a prime number?
>
> Joao, Jason, thanks for the code.
>
> --
> -Dan Joseph
>
> www.canishosting.com - Unlimited Hosting Plans start @ $3.95/month. =C2=
=A0Promo
> 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 =3D null)
{
$Factors =3D array();
foreach(range(1, ceil(sqrt($Value))) as $Factor)
{
if (0 == ($Value % $Factor))
{
if ($Factor <=3D $GroupSize)
{
$Factors[] =3D $Factor;
}
if ($Factor !=3D ($OtherFactor =3D ($Value / $Factor)) && $OtherFactor
<=3D $GroupSize)
{
$Factors[] =3D $OtherFactor;
}
}

if ($Factor >=3D $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

--=20
-----
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=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

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

Report this message

#16: Re: Math Question....

Posted on 2010-04-22 18:42:13 by Dan Joseph

--00c09f88cfaf27f7950484d5fe23
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Apr 22, 2010 at 12:16 PM, Richard Quadling <rquadling@googlemail.com
> wrote:

> On 22 April 2010 14:48, Dan Joseph <dmjoseph@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

--00c09f88cfaf27f7950484d5fe23--

Report this message