+ Reply to Thread
Results 1 to 10 of 10

Code for brute force

  1. #1
    Registered User
    Join Date
    04-28-2011
    Location
    Lahore,Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    25

    Code for brute force

    I have a code that generate some combinations for a specific sum from a given data set. This code has two errors.

    1. code does not look into data. it generates
    2. Code generate those combinations for which sum is greater than target value.
    e.g first combination code generates is 3+7+10+12+12

    This wrong by two means sum is 1) 44 while we need 40 2) 12 is not in data.


    Please Login or Register  to view this content.
    Last edited by rize1159; 03-04-2014 at 02:53 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,982

    Re: Code for brute force

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    04-28-2011
    Location
    Lahore,Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Code for brute force

    Any help on the above code

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,982

    Re: Code for brute force

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  5. #5
    Registered User
    Join Date
    04-28-2011
    Location
    Lahore,Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Code for brute force

    Here is workbook. Book1.xlsm

    sheet 1 is data
    sheet 2 contains desired calculated as example for three possible combinations for 40.
    Now I want to generate all possible combinations for 40 from the given data as described in formula of sum. while code above is not helping.
    Last edited by Leith Ross; 03-12-2014 at 01:53 PM.

  6. #6
    Registered User
    Join Date
    04-28-2011
    Location
    Lahore,Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Code for brute force

    Any Help.............

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Code for brute force

    There's no code in your file.

  8. #8
    Registered User
    Join Date
    04-28-2011
    Location
    Lahore,Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Code for brute force

    code is given in the thread above

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,888

    Re: Code for brute force

    It appears to me that the code is working just fine.

    1. code does not look into data. it generates
    2. Code generate those combinations for which sum is greater than target value.
    e.g first combination code generates is 3+7+10+12+12

    This wrong by two means sum is 1) 44 while we need 40 2) 12 is not in data.
    What you need to realize is that i, j, k, and l are not the actual data values being summed. These values represent the position in the array that lead to the desired solution. Rather than 3+7+10+12+12, these values actually mean data(3)+data(7)+data(10)+data(12)+data(12)=4+7+9+10+10=40. If you want the message box to show the actual data being summed rather than the position in the array, then you will need to modify the messagebox statements accordingly.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  10. #10
    Registered User
    Join Date
    04-28-2011
    Location
    Lahore,Pakistan
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Code for brute force

    Thank you very much MrShorty. I have already solved the issue.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. code to force cell entry
    By 3earth in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-28-2013, 02:15 AM
  2. VB Code To Force Upper Case?
    By Strugggler in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-26-2009, 06:24 PM
  3. Using a PHP form/code to force data into Excel?
    By SouthwestMetal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-02-2007, 06:31 PM
  4. [SOLVED] Force event code to NOT respond
    By Peter Danes in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-07-2006, 10:20 AM
  5. How can I force my code to wait
    By saita in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2005, 10:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1