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

    Default how to balance true and false instances per id ?

    I have a list of instances:

    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
    London, UK
    Blog Entries
    Rep Power


    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 ?

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

    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, 05:59 AM
  2. Prime Number - true , false
    By pinkdreammsss in forum Java Applets
    Replies: 11
    Last Post: 05-04-2010, 02:49 PM
  3. Calculate the remaining balance on a loan
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 9
    Last Post: 03-30-2010, 03:38 AM
  4. Color Balance
    By THEAniKan in forum Java 2D
    Replies: 2
    Last Post: 09-14-2009, 04:34 PM
  5. Binary Tree Deletion & Balance Methods
    By sev51 in forum New To Java
    Replies: 1
    Last Post: 01-27-2009, 04: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