[Solved] How can i calculate all possible sums of an int array?

Hi,
i can't figure out the algorithm for that:
e.g. array=1,2,3,..n => P1=1+2,P2=1+3,P3=2+3,P4=1+2+3,...
For a program language i use Java.
thanks.
Last edited by br4 (2008-12-10 15:23:40)

Idea:
Let V be the array and N the number of elements in V. Computing "sum_number_P":
-> Assume the binary representation of P is: bN b(N-1) ... b3 b2 b1 (where bJ = "bit number J", bN = MSB, b1 = LSB).
=> sum_number_P = bN * V[N - 1] + b(N-1) * V[N - 2] + ... + b1 * V[0]
Now compute sum_number_1, sum_number_2, .... sum_number_(2^N - 1)
An example: Let V = { 1, 2, 3 } ; N = 3.
sum_number_1:
-> 1 = 001 (in base 2)
=> sum_number_1 = 0 * V[2] + 0 * V[1] + 1 * V[0] = 0 * 3 + 0 * 2 + 1 * 1 = 1
sum_number_2:
-> 2 = 010 (in base 2)
=> sum_number_2 = 0 * V[2] + 1 * V[1] + 0 * V[0] = 0 * 3 + 1 * 2 + 0 * 1 = 2
sum_number_3:
-> 3 = 011 (in base 2)
=> sum_number_3 = 0 * V[2] + 1 * V[1] + 1 * V[0] = 0 * 3 + 1 * 2 + 1 * 1 = 3
sum_number_(2^3 - 1) = sum_number_7:
-> 7 = 111
=> sum_number_7 = 1 * V[2] + 1 * V[1] + 1 * V[0] = 1 * 3 + 1 * 2 + 1 * 1 = 6
Last edited by string (2008-12-08 16:46:47)

Similar Messages

  • How can I calculate all members of a dimension except one?

    I have an accounts dense dimension with one member that is a percentage, and as a result, should not be aggregated through other dimensions (product, client, country).I use CALC DIM command, and could clear afterwards the upper-blocks for that member, but I don't like this solution very much.Any ideas? Thank you very much in advance.

    My suggestion would be to make the percentage field that you do not want to aggregate up to be a dynamic and not stored member with two pass. In this way, you do not need to worry about it during your calc script.

  • How can I get all the values of a String array profile property using javascript?

    I am trying to build functionality into our site that records all products added to the basket against a user's profile.
    I have so far been able to store the product codes against the profile as a property using Ajax:
           var dataString = ":formid=addProduct&:formstart=/apps/thread/templates/page_product/jcr:content/par/produc t/formstart&:redirect=/content/thread/en/user/cart.html&productId=151515:profile="+profile ;
                         $.ajax({ 
                type: "POST", 
                url: "/content/women/evening/dresses/l-k-bennett-davinadress.html", 
                data: dataString, 
                success: function(data) { 
    In this example I have hardcoded a product ID of 151515.
    In order to save the property as a multi string field you simply replace &productId=151515 with &productId=151515&productId=131313&productId=141414 or as many extra values as you want to build into that string. This stores a productId property against a user profile.
    The issue comes from calling that data back. Using var value = CQ_Analytics.ProfileDataMgr.getProperty("productId") I can get the first value of this array (or the single value if only one is stored).
    However there does not seem to be a way to get any of the other stored values in the array using getProperty. Does anyone know how I can achieve this?

    Hi,
    Don't think that's possible. Even if it were, you wouldn't be able to use/display BOOLEAN type in SQL.
    If you just aim to see what they are, you could do something like this
    select text
      from all_source
    where owner = 'SYS'
       and name = 'DBMS_DB_VERSION'
       and type = 'PACKAGE';Or even
    select dbms_metadata.get_ddl('PACKAGE', 'DBMS_DB_VERSION', 'SYS') from dual;My version is:
    SQL> select * from v$version where rownum = 1;
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selectedIn 11g you also have [PL/SCOPE|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_plscope.htm#ADFNS02203] which might help you even more.
    Regards
    Peter

  • How can I multiply all values of a 4-element array with all of its inverse values resulting to an array having all 16 products?

    I'm quite new to LabVIEW (v.8.0) and I'm trying to figure out the easiest way to have a 4-element array multiplied by its inverse values resulting in a 16-element array
    Array 1 values = 1, 2, 3, 4
    Array 1 inverse values = 1, 0.5, 0.33, 0.25
    Resulting array = (1, 0.5, 0.33, 0.25, 2, 1, 0.66, 0.5, 3, 1.5, 1, 0.75, 4, 2, 1.32, 1)
    Any advice would be appreciated. Thanks!
    Solved!
    Go to Solution.

    Attachments:
    mo.doc ‏27 KB

  • I just bought a new ITOUCH 4th Generation how can i transfer all my apps from my old ITOUCH 2nd Generation? Is it possible?

    I just bought a new ITOUCH 4th Generation how can i transfer all my apps from my old ITOUCH 2nd Generation? Is it possible?I just bought a new ITOUCH 4th Generation how can i transfer all my apps from my old ITOUCH 2nd Generation? Is it possible?
    Thanks

    If you want to transfer app dat you need to restore the new iPod from the backup of the old iPod.  Restoring from backup will result in your new iPod being just like your old iPOd except you will have to reenter keychain items like passwords since those only get restore to the same device upon a restore.

  • Dear I am using iphone 4s now its connected with pc to create contact group.  I have 750 contacts in phone but pc showing only 36. How can i solve this? How can I see all contacts in pc?

    Dear I am using iphone 4s now its connected with pc to create contact group.  I have 750 contacts in phone but pc showing only 36. How can i solve this? How can I see all contacts in pc?

    HI,
    It may pay to bookmark this page.
    http://www.apple.com/support/systemstatus/
    8:40 PM      Wednesday; April 10, 2013
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.3)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • How can i calculate tempsize and logdir size ?

    Hello:
    I have one database on a primary server and its replica on a replica server.
    Since one week to now, Mexican Exchange have had a considerable growth on transactions.
    My database works in line, every night all data is cleaned waiting for new data on next day.
    From last Thursday (29 april 2010) my replicas have had problems on drop all data using delete from.
    I use delete from because those tables are Oracle cache groups defined.
    Looking for error on tterrors logs (yesterday I got this error) I could see that replica was ran out of temporal memory.
    On line database and replica database I have defined same temporal memory size, on this case 512Mb. But primary database did not send any error about this parameter, so if I checked “monitor” columns on database, my temp_in_use size is too less than temp_allocate_size.
    My problem is, how can I calculate temp_allocate_size ?
    So I have had close to 3,000,000 record on a simple table, I mean, I could have 2 or 3 tables with same number of rows.
    If I have this parameter (may be 9,000,000) rows to be deleted, is there any way to calculate temp_allocate_size ?
    But now, I suppose that I need enogh space on “LogDir”, my high_water_mark for permanent memory is 10GB, I have defined 16 gb for LogDir, but if I stopped replication since the operation starts, I had 100% space used at middle of my operation, so 5Gb on real database used, it is using close to 16 gb on LogDir.
    My second doubt … is there any way to calculate LogDir size having the maximum database size ??
    Thanks a lot for your help.
    Regards.

    I think that approaching this from the perspective of increasing temporary space and log space is not the best way.
    Firstly, there are better ways to delete all rows from a table instead of using delete...
    1. For regular tables (ones that are not part of a cache group) you can use TRUNCATE TABLE ... This operation is replicated but the voilume of replicated data is vastly smaller than if you delete all rows individually. Also, it should take a lot less Temp space on both the source and target system.
    2. For cache tables, you could use UNLOAD CACHE GROUP ... This is similar to TRUNCATE but for cache tables. Again, this operation is replicated. Note that if you are using AWT or SWT cache groups and you DELETE in TimesTen then the data is also deleted from Oracle... is that wjhat is desired?
    If you have to use DELETE then it is very important that you delete the rows in small batches rather than as one huge transaction. Trying to replicate a delete of 3M rows will cause huge problems for replication. A much better solution is to delete in smaller batches using some application logic as follows:
    loop:
    commit;
    DELETE FIRST 1000 FROM sometable;
    If rowcount > 0 then goto loop;
    commit;
    This approach has 5 benefits:
    1. Much less Temp space will be needed.
    2. Replication will be able to process the delets as they occur rather than waiting until all 3M rows have been deleted and then trying to tepliate a single transaction of 3M deletes. This will greatly improve replication performance and also prevent excessive log file buildup.
    3. Checkpointing will be able to purge log files as the delete progresses rather than having to wait until all rowsw have been deleted. This will prevent excessive log file buildup.
    4. The overall time required will be much reduced compared to deleting all rows in a single delete.
    You should not stop replication while the delete s are being done as this just causes log file accumulation.
    To answer your original question. it is not possible ot 'calculate' the required temp space pof log space; rather one must use observed data from when the system is running to determine the necessary size. For Temp size, you can look at the Temp high water mark to see the maximum space used and then set TempSize to somewhat more than that value. For log space, you need enough to sustain the maximum amount of log data generated with some contingency. Running our of log space is a very bad idea...
    If you adopt my suggestions above then you can avoid these issues and also complete the cleanup of data in a shorter time.
    Chris

  • How can I calculate the value of the cell, which depends on other rows?

    Hi, all!
    I have an application with table. In this table i have calculate some fields, that doesn't exists in data class and depends on other row values, e.g. current row number, or sum of previous rows. How can i calculate this values in TableView?
    The problem is that I have no information about the current row number in the cell value factory.
    Example:
    public class Transaction {
         public String getName();
         public BigInteger getAmount();
    } // There is no getter for "Balance"
    Result table should be something like this:
    Name
    Amount
    Balance
    transaction1
    300
    300
    transaction2
    200
    500
    transaction3
    500
    1000
    Also, after sorting by "Amount", "Balance" should be recalculated:
    Name
    Amount
    Balance
    transaction3
    500
    500
    transaction1
    300
    800
    transaction2
    200
    1000

    Strings can be converted to numbers by various parse methods. For instance Strings can be converted to double via Double.parseDouble(myString).
    That being said, it appears that your textfield will contain numbers and operators, and so these operators will need to be parsed too. I would advise you to search on the terms Java infix postfix.

  • How can i calculate the average in java

    how can i calculate the avergae mark out of two marks for instance in like exam mark out
    of two other ones
    thanks for considering this message

    Average or Mean:
    sum_of_N/N
    Here N is the number of marks.
    sum_of_N is the total sum of n(all marks added together)
    public int average(int[] marks) {
    int sum;
    sum = 0;
    for(int i=0;i < marks.length;i++) {
    sum=marks[i]+sum; // keep adding to the total
    return average = sum/marks.length;
    // warning- using an int here can be a pitfall(we could have a decimal outcome).
    }

  • How can i calculate the percentile rank?

    How can I calculate where in percentile terms a single value falls within a array of many values?
    In excel it is:
    5
    10
    12
    11
    26
    18
    14
    11
    16
    19
    =PERCENTRANK(A1:A10,10) = 0.111
    Thanks!

    Average or Mean:
    sum_of_N/N
    Here N is the number of marks.
    sum_of_N is the total sum of n(all marks added together)
    public int average(int[] marks) {
    int sum;
    sum = 0;
    for(int i=0;i < marks.length;i++) {
    sum=marks[i]+sum; // keep adding to the total
    return average = sum/marks.length;
    // warning- using an int here can be a pitfall(we could have a decimal outcome).
    }

  • How can i remove all contact at once from ovi?

    after synchronise with ovi & my mobile how can i remove all contact from my ovi's contact.
    I can remove one by one but i want to remove all at once. how possible??
    Solved!
    Go to Solution.

    @tkwcare:
    Beware of that method. Restoring your contacts after sync'ing will restore the phone to a state with a timestamp prior to when the sync occurred. Sync'ing again will attempt to bring the phone up to date with the online resource and, in doing so, will delete all the contacts off the phone!
    Was this post helpful? If so, please click on the white "Kudos!" star below. Thank you!

  • Text on path: How can I calculate the text length?

    Hi
    I have a text on path (spline item). Now I need the length of this text and the length of the spline item.
    I try to calculate the text length using IWaxLine::GetWidth(), but this is always 0.
    - How can I calculate the length of this text?
    - How can I calculate the length of the spline item?
    Thanks
    Hans

    It would be interesting if you could describe the purpose of your "length", but I don't have an answer anyway. Would the bounding box be sufficient?
    Considering that TOP may be combined with arbitrary spline paths, this could become an exercise in higher math. I haven't yet encountered a function that returns the mathematical length of such a spline.
    Otherwise it could be solved if you iterate and sum up the relevant points of the bounding box (ascender, descender, baseline?) of individual glyphs.
    Be warned that the whole TOP looks alien, as if it were a transplant from a different program. Experience also shows that documented and actually used interfaces / commands are completely different animals ...
    Dirk

  • How can i display all the query items to a table?

    how can i display all the query items to a table in a jsp file?
    i always have an out of memory error..

    any body??any idea?
    is it possible thru configuration or i have to write a program by the abaper??
    Biswa

  • How can I display all the columns on the screen without scrolling from side to side?

    My clinic software has many columns. How can I display all the columns without having to scroll from left to right all the time?

    If the software you are using doesn't offer the ability to increase or decrease document size, as many do, then the only way is to increase your screen resolution. If that's not possible, maybe you can decrease your font size?  If you can't do any of these, I think you're out of luck!

  • In Contacts version 8, how can I print ALL information in each individual card? When I select the print command the only thing printed is the name and address. I need phone number(s) and all other information in the cards.

    In Contacts version 8, how can I print ALL information in each individual card? When I select the print command the only thing printed is the name and address. I need phone number(s) and all other information in the cards. We enter various pieces of data, other than the standard name address & phone numbers and we print all information on each card so it fits in a 5x7 inch loose binder. We have used InTouch software for many years and it has served us extremely welll, however, the publisher (The Prairie Group) has not, and apparently has no plans to update their software to be compatible with any Mac OSX OS beyond 10.6. Any help will be appreciated!

    You can select what you want included in a list format. In the Print command from Contacts, click the Show Details button. Then in the Style pulldown menu select "Lists" and there you'll be able to select what you want included. You can also select what you wish included if you select the Pocket Address Book style.
    If neither of those options will work for you, then you will need to look to third-party software. Here's one possibility that seems to get good reviews:
    https://www.macupdate.com/app/mac/15485/labels-&-addresses
    I haven't done more than try it to make sure that it works with OS X 10.9's Contacts, which it does, but you can download their demo and try it yourself.
    Regards.

Maybe you are looking for

  • Print from DMS directly

    hi all,     i have a requirement that document should be printed directly from DMS. i came to kno from someone that there is s program named MCDOKPRT which can solve my problem. But i tried that program, it is giving me some text and not displaying o

  • Should I persevere?

    I'm a professional photographer shooting RAW who currently uses Adobe Bridge, ACR and Photoshop CS2. I've spent about ten hours with the Lightroom trial, and so far I'm sorry to say that it doesn't look like it would save me any time over my current

  • Is Photoshop Elements 10 compatible with Windows 8.1?

    I am about to download/install Photoshop Elements 10 onto my Windows 8.1 system and I don't know if it will work.

  • I receive an error and iTunes shuts down every time I try to sync my iPhone

    Every time I try to sync my iPhone, I receive an error and iTunes shuts down. I have uninstalled and reinstalled iTunes at least 3 different times and still no luck. Any suggestions please.

  • How to import logo to the clip and display it during the whole clip

    Hello All, I am using Adobe Premiere Pro CS4. I am doing a project now from various DVDs I've already made from a while ago. Now I will use these them in a commercial things so I want to add a logo to the clips to keep my rights ...etc. Here is the s