Results 1 to 2 of 2
  1. #1
    aneuryzma is offline Member
    Join Date
    Aug 2008
    Posts
    46
    Rep Power
    0

    Default how to balance true and false instances per id ?

    I have a list of instances:

    1,true
    2, true
    2, true
    3, false
    2, false
    2, false
    2, true
    1, true
    1, false

    And I need balance the true and false instances for each ID. Therefore, the example above would become:

    1, true
    1, false
    2, true
    2, true
    2, false
    2, false

    How can I code this ? Should I go through the list collecting all instance with id 1 count the true, count the false and if true>false delete (true-false) true instances and viceversa ?

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    CLARIFY
    so what you want to do is, count the instance of true and false, and whichever is greater becomes the result? but what about if they are 50:50 ?

    ELABORATE
    and you have 2 java.util.List objects? one for the ID and one for the boolean?

    DESIGN
    what would be the purpose of storing the boolean values when they are of no further use to you? (since you mentioned you would like to delete them after the counting). why not increment a counter or decrement a counter in the first place?
    i.e. keep one instance of each ID 1,2,3, whenever there is a TRUE, don't copy a boolean, increment a counter ++, when there is a false, decrement.

Similar Threads

  1. Changing balance variable so its never negative
    By coding in forum New To Java
    Replies: 2
    Last Post: 02-13-2011, 06:59 AM
  2. Prime Number - true , false
    By pinkdreammsss in forum Java Applets
    Replies: 11
    Last Post: 05-04-2010, 03:49 PM
  3. Calculate the remaining balance on a loan
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 9
    Last Post: 03-30-2010, 04:38 AM
  4. Color Balance
    By THEAniKan in forum Java 2D
    Replies: 2
    Last Post: 09-14-2009, 05:34 PM
  5. Binary Tree Deletion & Balance Methods
    By sev51 in forum New To Java
    Replies: 1
    Last Post: 01-27-2009, 05:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •