Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27250 > unrolled thread
| Started by | Rahul Reddy <rahulreddy160@gmail.com> |
|---|---|
| First post | 2015-04-08 10:46 -0700 |
| Last post | 2015-04-11 22:14 -0400 |
| Articles | 9 — 8 participants |
Back to article view | Back to comp.lang.javascript
Javascript classes, Please take a look at my question below Rahul Reddy <rahulreddy160@gmail.com> - 2015-04-08 10:46 -0700
Re: Javascript classes, Please take a look at my question below Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-04-09 11:14 +0200
Re: Javascript classes, Please take a look at my question below JJ <jj4public@vfemail.net> - 2015-04-09 19:50 +0700
Re: Javascript classes, Please take a look at my question below Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-09 16:17 +0200
Re: Javascript classes, Please take a look at my question below JJ <jj4public@vfemail.net> - 2015-04-10 10:57 +0700
Re: Javascript classes, Please take a look at my question below "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-09 16:37 +0200
Re: Javascript classes, Please take a look at my question below Stefan Weiss <krewecherl@gmail.com> - 2015-04-09 21:44 +0200
Re: Javascript classes, Please take a look at my question below Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-10 14:22 +0000
Re: Javascript classes, Please take a look at my question below Richard Damon <Richard@Damon-Family.org> - 2015-04-11 22:14 -0400
| From | Rahul Reddy <rahulreddy160@gmail.com> |
|---|---|
| Date | 2015-04-08 10:46 -0700 |
| Subject | Javascript classes, Please take a look at my question below |
| Message-ID | <886ff158-ecdf-4913-8cc2-7ac2ba88b971@googlegroups.com> |
The seats allocated to a party are calculated by this method in two steps: In the first step the corresponding number of votes that are attributable to a party is multiplied by the total number of available seats and divided by the total number of valid votes. In the second step the result is split into the integer portion and the rest. The integer parts are attributed to the respective party as seats. The remaining seats are allocated to parties in the order of the size of the fractional portions. Exemplary data (assuming all votes are valid): Total seats: 15 Votes: A => 15000, B => 5400, C => 5500, D => 5550 Result should be Seats: A => 7, B => 2, C = 3, D = > 3 Write a class that calculates for a variable number of parties and seats and include the needed two lines how to call your class.
[toc] | [next] | [standalone]
| From | Erwin Moller <erwinmollerusenet@xs4all.nl> |
|---|---|
| Date | 2015-04-09 11:14 +0200 |
| Message-ID | <552642cd$0$2827$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #27250 |
On 4/8/2015 7:46 PM, Rahul Reddy wrote: > The seats allocated to a party are calculated by this method in two steps: > > In the first step the corresponding number of votes that are attributable to a party is multiplied by the total number of available seats and divided by the total number of valid votes. > > In the second step the result is split into the integer portion and the rest. The integer parts are attributed to the respective party as seats. The remaining seats are allocated to parties in the order of the size of the fractional portions. > Exemplary data (assuming all votes are valid): > > Total seats: 15 > Votes: A => 15000, B => 5400, C => 5500, D => 5550 > > Result should be > Seats: A => 7, B => 2, C = 3, D = > 3 > > Write a class that calculates for a variable number of parties and seats and include the needed two lines how to call your class. > Dear Rahul, You asked this question before. All that responded to you told you to do your own work. Except Dennis, he actually wrote some 'code' for you. ;-) If you have a piece of code *you* wrote all by yourself, please post it. I am sure some kind soul in here will help you from there. But nobody is willing to write it from scratch for you. (Unless you pay our regular hourly wages). Regards, Erwin Moller -- "That which can be asserted without evidence, can be dismissed without evidence." -- Christopher Hitchens
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2015-04-09 19:50 +0700 |
| Message-ID | <jfgvr1ihhbmq$.1y1oa9f37j6dc$.dlg@40tude.net> |
| In reply to | #27250 |
On Wed, 8 Apr 2015 10:46:28 -0700 (PDT), Rahul Reddy wrote: > The seats allocated to a party are calculated by this method in two steps: > > In the first step the corresponding number of votes that are attributable to a party is multiplied by the total number of available seats and divided by the total number of valid votes. > > In the second step the result is split into the integer portion and the rest. The integer parts are attributed to the respective party as seats. The remaining seats are allocated to parties in the order of the size of the fractional portions. > Exemplary data (assuming all votes are valid): > > Total seats: 15 > Votes: A => 15000, B => 5400, C => 5500, D => 5550 > > Result should be > Seats: A => 7, B => 2, C = 3, D = > 3 > > Write a class that calculates for a variable number of parties and seats and include the needed two lines how to call your class. This is more like math problem rather than JavaScript. Here's an example for A. Total_Votes = A + B + C + D A_Share% = A / Total_Votes x 100 A = A_Share x Total_Seats / 100
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-04-09 16:17 +0200 |
| Message-ID | <8842311.7ocnDDfIAB@PointedEars.de> |
| In reply to | #27261 |
JJ wrote: > On Wed, 8 Apr 2015 10:46:28 -0700 (PDT), Rahul Reddy wrote: >> [Programming homework question] > > This is more like math problem rather than JavaScript. > > Here's an example for A. > > Total_Votes = A + B + C + D > A_Share% = A / Total_Votes x 100 > A = A_Share x Total_Seats / 100 <facepalm/> -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2015-04-10 10:57 +0700 |
| Message-ID | <u458av40dewe$.wegjmapq5keg.dlg@40tude.net> |
| In reply to | #27268 |
On Thu, 09 Apr 2015 16:17:03 +0200, Thomas 'PointedEars' Lahn wrote: > > <facepalm/> <wiggle/>
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2015-04-09 16:37 +0200 |
| Message-ID | <XnsA477A92A260BBeejj99@194.109.133.246> |
| In reply to | #27261 |
JJ <jj4public@vfemail.net> wrote on 09 apr 2015 in comp.lang.javascript: > On Wed, 8 Apr 2015 10:46:28 -0700 (PDT), Rahul Reddy wrote: [..] >> Write a class that calculates for a variable number of parties and >> seats and include the needed two lines how to call your class. > > This is more like math problem rather than JavaScript. I would suggest the possibility that the OP indeed talks about "Javascript classes", where his homework assignment originates. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Date | 2015-04-09 21:44 +0200 |
| Message-ID | <mg6krd$fq0$1@news.albasani.net> |
| In reply to | #27250 |
On 2015-04-08 19:46, Rahul Reddy wrote:
> In the second step the result is split into the integer portion and
> the rest. The integer parts are attributed to the respective party as
> seats. The remaining seats are allocated to parties in the order of the
> size of the fractional portions.
I would reject this algorithm as incomplete.
Example input: 10 seats, votes: 50 A, 35 B, 15 C
Does C get one or two seats?
What should the program do if it can't find an unambiguous distribution?
(Amusingly, Denis's solution would solve this specific example by simply
adding a seat.)
- stefan
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-04-10 14:22 +0000 |
| Message-ID | <mg8mas$dpa$3@dont-email.me> |
| In reply to | #27281 |
On Thu, 09 Apr 2015 21:44:45 +0200, Stefan Weiss wrote: > (Amusingly, Denis's solution would solve this specific example by simply > adding a seat.) Denis didn't claim his solution was complete either. ;) Although it might provide a starting point for someone trying to develop their own code. Or not. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2015-04-11 22:14 -0400 |
| Message-ID | <%xkWw.252000$2f6.172530@fx12.iad> |
| In reply to | #27281 |
On 4/9/15 3:44 PM, Stefan Weiss wrote: > On 2015-04-08 19:46, Rahul Reddy wrote: >> In the second step the result is split into the integer portion and >> the rest. The integer parts are attributed to the respective party as >> seats. The remaining seats are allocated to parties in the order of the >> size of the fractional portions. > > I would reject this algorithm as incomplete. > > Example input: 10 seats, votes: 50 A, 35 B, 15 C > > Does C get one or two seats? > What should the program do if it can't find an unambiguous distribution? > > (Amusingly, Denis's solution would solve this specific example by simply > adding a seat.) > > - stefan > There is a fundamental problem with ANY vote system of how to handle ties. The simplest case would be 1 seat, two parties, equal votes. The next level would be 2 seats, 3 parties, or 3 seat, 2 parties with equal votes. Fundamentally, such a case (due to the symmetry) can't (from what I see) have a solution other than going to chance or a new vote, or maybe have some other body "vote" to break the tie. With typical number of votes in a real election, the odds of having a true tie gets small, and if the number of seat is large having a lottery choose might not be unreasonable (perhaps add a extra tie breaking rule biasing cases like the above one way or the other, but these couldn't handle the 50/25/25 case due to symmetry, that would need to go to another stage (lottery or re-vote, etc). Sometimes adding a seat is a viable solution, but properly if you add (or remove) a seat, you should redo the whole calculation and I suspect it may be possible that there are cases when you do this the extra seat goes elsewhere. You also run into the issue that normally the number of seats is set by a more fundamental law (and may be constrained by the actually number of physical seats).
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web