Brute Force Algorithm

Get help using Construct 2

Post » Tue Feb 11, 2014 1:13 pm

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?Kurz2014-02-11 13:14:33
B
57
S
19
G
10
Posts: 191
Reputation: 9,626

Post » Tue Feb 11, 2014 1:30 pm

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.   >_>
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue Feb 11, 2014 1:47 pm

anyway the function object support recursion, its stated in the manual

maybe something like

sum = sum + variable (range within 10)vtrix2014-02-11 13:50:13
ImageImage
B
70
S
21
G
7
Posts: 827
Reputation: 10,052

Post » Tue Feb 11, 2014 1:54 pm

@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
B
57
S
19
G
10
Posts: 191
Reputation: 9,626

Post » Tue Feb 11, 2014 2:17 pm

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];
}Kurz2014-02-11 14:18:59
B
57
S
19
G
10
Posts: 191
Reputation: 9,626

Post » Tue Feb 11, 2014 8:13 pm

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.
B
92
S
32
G
110
Posts: 5,295
Reputation: 71,501

Post » Tue Feb 11, 2014 9:16 pm

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..
Need help? Upload .capx file with your question.
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

Post » Wed Feb 12, 2014 6:58 am

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

Thank you, guys! Again going to learn manual
B
57
S
19
G
10
Posts: 191
Reputation: 9,626


Return to How do I....?

Who is online

Users browsing this forum: Armench, brunopalermo, Kin, worm1, Yahoo [Bot] and 27 guests