Brute Force Algorithm

0 favourites
  • 8 posts
From the Asset Store
Finding the shortest path through the cells based on the A-star algorithm
  • Good Day!

    I'm trying to solve the brute force algorithm through events and this look like C2 don't support recursion in function object.

    My problem - I have to calculate the sum of all numbers in the range 10 ( like: 1+1+1+3+6 or 5+5 or 6+2+2... ALL numbers)

    Is there someone tried to implement it?

  • 1+1+1+3+6   << how would that one work ? wouldnt that be 12 ? (whats the reasoning behind it)

    You statement: I have to calculate the sum of all numbers in the range 10.

    Leaves a lot to the imagination.

    Or it could be 55.   >_>

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • anyway the function object support recursion, its stated in the manual

    maybe something like

    sum = sum + variable (range within 10)

  • lennaert , My mistake. I have to calculate all numbers in range 10 that it should equal 10.

    vtrix , I'm so blind... going to read manual

  • Okey, here the example code. I have a problem with return string in count_change func

    _types = [1, 5, 10, 25, 50]; // coin types

    // this programm count number of ways to exchange money(to example)

    // amount ? sum for exchange

    // n ? number of coins (5 to example )

    function count_change(amount, n) {

        if (amount == 0) {

            return 1;

        } else if (amount < 0 or n == 0) {

            return 0;

        } else {

            return count_change(amount, n - 1) + count_change(amount - type(n), n);          /////////////// How to write THIS string in C2 ??

        }

    }

    // nominal value returns n-type coins

    function type(n) {

        return _types[n - 1];

    }

  • Here's that function implemented in events:

    https://dl.dropboxusercontent.com/u/5426011/fixed/kurz_brute_algo.capx

    Although I don't quite get the significance of the results.

  • About the only reason I'll see for calculations like that could be on generating some kind of list of all possible actions at the turn on a Game. That is there are numerous cards with different costs (or units with different movements) and the algorithm is trying to maximize the effect gained with certain point value.

    Anyhow.. those can become quite big/slow quite easily..

  • R0J0hound I'm impressive! Didn't know about this syntax.

    Thank you, guys! Again going to learn manual

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)