Results 1 to 2 of 2

Thread: algorithm for solving for groups that add up to a number in a 6X5 block

  1. #1

    Thread Starter
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    algorithm for solving for groups that add up to a number in a 6X5 block

    I have a table (looks like this but the numbers might move around)

    Code:
        A        B       C       D       E       F
    1|  6      100     120      140    100    100
    2|  120    100     80       100    120     80
    3|  80      120    140      140    180    100
    4|  60      120    140      100    220    120
    5|  100    120    100       220   120     200
    How would go about making somthing in vb6 (or at all) to solve this.

    To solve, you must find 6 groups, each group add up to exatly 600.
    Each block in the group must tuch (on one side, so from top,buttom,left or right, no diagonals). the number of blocks in a groups may vary.

    so example F1, F2, F3, F4, and F5 are a valid group all tuch on a side, and the sum of all of them is 600
    same goes for B4, C3, C4, D4, and C5, and so on...
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  2. #2
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Re: algorithm for solving for groups that add up to a number in a 6X5 block

    So you seem to have an arbiterilly sized grid for which any given mapped area must be calculated to 600.

    I would create an 2D array to store the grid within and then I might create a user type, object or array of arrays to store pattern shapes (blocks) in. Then each action (timer, user click, whatever) I would loop the collection and sum the values for each array point indicated.

    So if my array of arrays looked like this:

    $array =
    0 = (0 = (x=1, y=2), 1 = (x=1, y=3) ... counter = 0)
    ...

    I would be putting the x and y values into the array and adding the returned value to my counter for that object.

    That would allow you to track the shapes. However if you need to find the shapes that amount to 600 you are going to need something more powerful.

    Look up mapping algorithms becuase you are after them even if you did not know it.

    The simple brute force approach would be to try every possible combination until you got a 600. You could try known shapes as per the first suggestion and offset them on the x and y step by step until you have tried each possibility. You can save time if you have a grasp of rotations and reflections as a mathematical idea.

    I hope I have thrown you some useful ideas.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

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



Click Here to Expand Forum to Full Width