X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A52F79FABE7 for ; Tue, 25 Jul 2006 22:44:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 28309-04 for ; Tue, 25 Jul 2006 22:44:00 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web53202.mail.yahoo.com (web53202.mail.yahoo.com [206.190.49.72]) by postgresql.org (Postfix) with SMTP id 556ED9FA68D for ; Tue, 25 Jul 2006 22:43:30 -0300 (ADT) Received: (qmail 38922 invoked by uid 60001); 26 Jul 2006 01:43:28 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=PzAM/ke6jcV3XnqPhiz7wuqV0JEQeealrTQSSHOjyuu3MtMq1UXohnRqxpV4nwnqlUHxBp8lNwCiHlZ10Ql2diUOotjk1yw0ay71b6HuZz/64gx0DqoqcBSi9uEYG/S0dFlOVWiEArxm/pxlHXyxPWg+OX3lRVEkxCwEw/3EvTE= ; Message-ID: <20060726014328.38920.qmail@web53202.mail.yahoo.com> Received: from [222.124.225.25] by web53202.mail.yahoo.com via HTTP; Tue, 25 Jul 2006 18:43:28 PDT Date: Tue, 25 Jul 2006 18:43:28 -0700 (PDT) From: Otniel Michael Subject: Re: About Div To: Aaron Bono Cc: pgsql-sql@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-343180568-1153878208=:30982" Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.846 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, DNS_FROM_RFC_WHOIS, HTML_50_60, HTML_MESSAGE X-Spam-Level: * X-Archive-Number: 200607/312 X-Sequence-Number: 25886 --0-343180568-1153878208=:30982 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Mr. Aaron. I am sorry, your solution didn't match in my case. Example for your solution : A = 1 B = 1 C = 1 D = 1 E = 1 F = 1 G = 4 G have 4 candy. Its too much for G. In my case, the solution is : A = 1 B = 1 C = 1 D = 1 E = 2 F = 2 G = 2 The extra candy is given to three child. Do you have the other solution? I need function in postgresql for my case. Because my loop is too slow. Btw thanks for your solution. Aaron Bono wrote: On 7/25/06, Otniel Michael wrote: Dear All, I have a problem with this case : I have 10 candy for 7 child (A, B, C, D, E, F, G). Table X : code value ------- -------- A 0 B 0 C 0 D 0 E 0 F 0 G 0 And I want divide it with this algorithm : A = 10 / 7 = 1 B = (10-1) / (7-1) = 9 / 6 = 1 C = (10-2) / (7-2) = 8 / 5 = 1 D = (10-3) / (7-3) = 7 / 4 = 1 E = (10-4) / (7-4) = 6 / 3 = 2 F = (10-6) / (7-5) = 4 / 2 = 2 G = (10-8) / (7-6) = 2 / 1 = 2 In my first solution i use loop - for each record in my function. But it is too slow in a lot of data. Did postgresql have a function for my case? No loop necessary. This is a simple math problem: dividedamount := candy / childcount; extra = candy % childcount; So the first (childcount - extra) get (dividedamount) pieces of candy and the last (extra) get (dividedamount + 1) pieces of candy. ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com ================================================================== -- "He who is quick to become angry will commit folly, and a crafty man is hated" __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --0-343180568-1153878208=:30982 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Mr. Aaron. I am sorry, your solution didn't match in my case.
Example for your solution :
A = 1
B = 1
C = 1
D = 1
E = 1
F = 1
G = 4

G have 4 candy. Its too much for G.

In my case, the solution is :
A = 1
B = 1
C = 1
D = 1
E = 2
F = 2
G = 2

The extra candy is given to three child.

Do you have the other solution? I need function in postgresql for my case.
Because my loop is too slow.

Btw thanks for your solution.

Aaron Bono <postgresql@aranya.com> wrote:
On 7/25/06, Otniel Michael <otmic_ie@yahoo.com> wrote:
Dear All,

I have a problem with this case :

I have 10 candy for 7 child (A, B, C, D, E, F, G).

Table X :
code   value
 -------  --------
 A        0       
 B        0       
 C        0       
 D        0       
 E        0       
 F        0       
 G       0       

And I want divide it with this algorithm :
    A = 10 / 7 = 1
    B = (10-1) / (7-1) = 9 / 6 = 1
    C = (10-2) / (7-2) = 8 / 5 = 1
    D = (10-3) / (7-3) = 7 / 4 = 1
    E = (10-4) / (7-4) = 6 / 3 = 2
    F = (10-6) / (7-5) = 4 / 2 = 2
    G = (10-8) / (7-6) = 2 / 1 = 2

In my first solution i use loop - for each record in my function.
But it is too slow in a lot of data.
Did postgresql have a function for my case?

 
No loop necessary.  This is a simple math problem:

dividedamount := candy / childcount;
extra = candy % childcount;

So the first (childcount - extra) get (dividedamount) pieces of candy and the last (extra) get (dividedamount + 1) pieces of candy.

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
==================================================================



--
"He who is quick to become angry will commit folly, and a crafty man is hated"

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com --0-343180568-1153878208=:30982--